Пример #1
0
 public function actionSubscriptions()
 {
     $subscriptions = PaypalSubscriptionExpress::find()->where(['and', ['!=', 'status', PaypalSubscriptionExpress::SUBSCRIPTION_STATUS_CANCELLED]])->all();
     foreach ($subscriptions as $subscription) {
         $subscription->isSubscriptionActive();
     }
 }
Пример #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]);
 }
Пример #3
0
 public function actionSubscriptionExpressCreate($price, $modelId = null, $period = 30, $description = null)
 {
     if (!Yii::$app->getModule('payment')->enableSubscriptionExpress) {
         throw new \yii\web\NotFoundHttpException('Page Not Found');
     }
     if ($modelId == 'null') {
         $modelId = null;
     }
     if (!is_null($modelId)) {
         $model = PaypalSubscriptionExpress::findOne($modelId);
         $subscription = Yii::$app->getModule('payment')->getPaypalSubscriptionExpress();
         $subscription->setAttributes($model->getAttributes());
         $subscription->id = $model->id;
         $subscription->isNewRecord = false;
     } else {
         $subscription = Yii::$app->getModule('payment')->getPaypalSubscriptionExpress();
         $subscription->period = $period;
         $subscription->price = $price;
     }
     if (empty($subscription)) {
         throw new \yii\web\NotFoundHttpException('Page Not Found');
     }
     try {
         if ($subscription->prepareSubscriptionUrl()) {
             $url = $subscription->paymentUrl;
             Yii::info('User #' . Yii::$app->user->getId() . ' redirected to paypal with token is "' . $subscription->getToken() . '"', 'payment');
             return $this->redirect($url);
         }
     } catch (Exception $ex) {
         throw new \yii\web\NotFoundHttpException('Page Not Found');
     }
     throw new BadRequestHttpException('Something went wrong');
 }