Ejemplo n.º 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);
 }