我有一些问题试图让它工作,我已经成功地实现了 checkout express (或似乎是),但我的系统还需要订阅选项,这example之后.
现在,我的问题是,在Laravel中,您不能简单地放置一些随机文件,所以我试图以正确的方式这样做,遗憾的是,没有包括在库中的类和方法的文档.
I've created some functions within controllers (I don't know if this the right way) the problem I'm facing now is trying to createRecurringPayment() to apply the desired amount of the recurring payment, is the final step I guess.
谢谢你的帮助.
-
APP/Controls/PaypalController.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()); }
-
app/routes.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'));