实施Payum/Laravel定期付款
我在尝试使其工作时遇到一些问题,我已经成功实现了结帐快车(或似乎),但我的系统也需要订阅选项,遵循此示例。
现在,我的问题是,在Laravel中,你不能简单地放置一些随机文件,所以我试图以正确的方式做到这一点,可悲的是,没有关于库上的类和方法的文档。
我已经在控制器中创建了一些函数(我不知道这是否是正确的方式),我现在面临的问题是试图创建RecurringPayment()来应用所需的定期付款金额,这是我猜的最后一步。
谢谢你的帮助。
-
应用程序/控制器/贝宝控制器.php
public function prepareExpressCheckout(){ $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject'); $details = $storage->createModel(); $details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'; $details['PAYMENTREQUEST_0_AMT'] = 1.23; $storage->updateModel($details); $captureToken = $this->getTokenFactory()->createCaptureToken('paypal_es', $details, 'payment_done'); $details['RETURNURL'] = $captureToken->getTargetUrl(); $details['CANCELURL'] = $captureToken->getTargetUrl(); $storage->updateModel($details); return \Redirect::to($captureToken->getTargetUrl()); } public function prepareSubscribe(){ $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject'); $details = $storage->createModel(); $details['PAYMENTREQUEST_0_AMT'] = 0; $details['L_BILLINGTYPE0'] = Api::BILLINGTYPE_RECURRING_PAYMENTS; $details['L_BILLINGAGREEMENTDESCRIPTION0'] = "Suscripción por X meses"; $details['NOSHIPPING'] = 1; $storage->updateModel($details); $captureToken = $this->getTokenFactory()->createCaptureToken('paypal_es', $details, 'payment_done'); $storage->updateModel($details); return \Redirect::to($captureToken->getTargetUrl()); } public function createRecurringPayment(){ $payum_token = Input::get('payum_token'); $request = \App::make('request'); $request->attributes->set('payum_token', $payum_token); $token = ($request); //$this->invalidate($token); $agreementStatus = new GetHumanStatus($token); $payment->execute($agreementStatus); if (!$agreementStatus->isSuccess()) { header('HTTP/1.1 400 Bad Request', true, 400); exit; } $agreementDetails = $agreementStatus->getModel(); $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject'); $recurringPaymentDetails = $storage->createModel(); $recurringPaymentDetails['TOKEN'] = $agreementDetails['TOKEN']; $recurringPaymentDetails['DESC'] = 'Subscribe to weather forecast for a week. It is 0.05$ per day.'; $recurringPaymentDetails['EMAIL'] = $agreementDetails['EMAIL']; $recurringPaymentDetails['AMT'] = 0.05; $recurringPaymentDetails['CURRENCYCODE'] = 'USD'; $recurringPaymentDetails['BILLINGFREQUENCY'] = 7; $recurringPaymentDetails['PROFILESTARTDATE'] = date(DATE_ATOM); $recurringPaymentDetails['BILLINGPERIOD'] = Api::BILLINGPERIOD_DAY; $payment->execute(new CreateRecurringPaymentProfile($recurringPaymentDetails)); $payment->execute(new Sync($recurringPaymentDetails)); $doneToken = $this->createToken('paypal_es', $recurringPaymentDetails, 'payment_done'); return \Redirect::to($doneToken->getTargetUrl()); }
-
应用/路线.php
Route::get('/payment', array('as' => 'payment', 'uses' => 'PaymentController@payment')); Route::get('/payment/done', array('as' => 'payment_done', 'uses' => 'PaymentController@done')); Route::get('/payment/paypal/express-checkout/prepare', array('as' => 'paypal_es_prepare', 'uses' => 'PaypalController@prepareExpressCheckout')); Route::get('/payment/paypal/subscribe/prepare', array('as' => 'paypal_re_prepare', 'uses' => 'PaypalController@prepareSubscribe')); Route::get('/payment/paypal/subscribe/create', array('as' => 'payment_create', 'uses' => 'PaypalController@createRecurringPayment'));