I have some issues trying to get this working, I've implemented the checkout express (or seems to be) successfully, but also my system needs subscription option, following this example.
Now, my problem is that in Laravel you cannot simply put some random files, so I'm trying to do it in the correct way, sadly, there is no documentation of the classes and methods including on the library.
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.
Thanks for yout help.
app/controllers/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'));