예제 #1
0
 /**
  * @param int $price
  * @param int $modelId
  * @return string
  */
 public function actionPay($price, $modelId = null)
 {
     if (!Yii::$app->getModule('payment')->enableExpressPayment) {
         throw new \yii\web\NotFoundHttpException('Page Not Found');
     }
     if ($modelId == 'null') {
         $modelId = null;
     }
     if (!is_null($modelId)) {
         $model = PaypalExpressPayment::findOne($modelId);
         $paypal = Yii::$app->getModule('payment')->paypalExpressPayment;
         $paypal->setAttributes($model->getAttributes());
         $paypal->id = $model->id;
         $paypal->isNewRecord = false;
     } else {
         $paypal = Yii::$app->getModule('payment')->paypalExpressPayment;
         $paypal->payment_price = $price;
     }
     if (empty($paypal)) {
         throw new \yii\web\NotFoundHttpException('Page Not Found');
     }
     try {
         $paypal->createExpressPayment($paypal->payment_price, 1);
     } catch (Exception $ex) {
         throw new \yii\web\NotFoundHttpException('Page Not Found');
     }
     $url = $paypal->paymentUrl;
     Yii::info('User #' . Yii::$app->user->getId() . ' redirected to paypal with payment #' . $paypal->id . ' token is "' . $paypal->getToken() . '"', 'payment');
     return $this->redirect($url);
 }
예제 #2
0
 public function actionConfigure()
 {
     $settings = PaypalSettings::find()->one();
     if ($settings->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($settings);
         }
         if ($settings->save()) {
             PaypalSubscriptionExpress::deleteAll();
             PaypalExpressPayment::deleteAll();
             Yii::$app->getSession()->setFlash('success', 'Paypal settings updated succesfully');
             return $this->refresh();
         }
     }
     return $this->render('configure', ['settings' => $settings]);
 }