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]); }
/** * @return boolean */ public function cancelSubscription() { $settings = PaypalSettings::find()->one(); $config = ['mode' => $settings->mode ? 'live' : 'sandbox', 'acct1.UserName' => $settings->api_username, 'acct1.Password' => $settings->api_password, 'acct1.Signature' => $settings->api_signature]; if (empty($this->paypal_profile_id)) { return $this->save(); } $details = new ManageRecurringPaymentsProfileStatusRequestDetailsType($this->paypal_profile_id, 'Cancel'); $reqType = new ManageRecurringPaymentsProfileStatusRequestType(); $reqType->ManageRecurringPaymentsProfileStatusRequestDetails = $details; $req = new ManageRecurringPaymentsProfileStatusReq(); $req->ManageRecurringPaymentsProfileStatusRequest = $reqType; $service = new PayPalAPIInterfaceServiceService($config); $response = $service->ManageRecurringPaymentsProfileStatus($req); if (strtolower($response->Ack) == 'success') { return $this->save(); } else { $this->addError('subscription_status', $response->Errors[0]->ShortMessage); } return false; }
/** * returns url for a current payment * @param string $token * @return string url * @throws Exception */ public function getPaymentUrl($token = null) { if (is_null($token)) { $token = $this->token; } if (empty($token)) { return null; } $settings = PaypalSettings::find()->one(); if ($settings->mode == PaypalSettings::MODE_SANDBOX) { return self::EXPRESS_CHECKOUT_SANDBOX . $token; } if ($settings->mode == PaypalSettings::MODE_LIVE) { return self::EXPRESS_CHECKOUT_LIVE . $token; } throw new Exception('Looks like settings paypal have no mode'); }