Implement Payum/Laravel recurring payment

后端 未结 3 690
抹茶落季
抹茶落季 2021-01-17 09:35

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

3条回答
  •  死守一世寂寞
    2021-01-17 10:20

    I have found the problem. It is with the parameters we pass to the create recurring payment function. Here are functions for agreement and payment creation. It should work fine.

    getPayum()->getStorage('Payum\Core\Model\ArrayObject');
    
            $details = $storage->create();
            $details['PAYMENTREQUEST_0_AMT'] = 0;
            $details['L_BILLINGTYPE0'] = Api::BILLINGTYPE_RECURRING_PAYMENTS;
            $details['L_BILLINGAGREEMENTDESCRIPTION0'] = "Weather subscription";
            //$details['NOSHIPPING'] = 1;
            $storage->update($details);
    
            $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('paypal_ec', $details, 'paypal_subscribe');
    
            return \Redirect::to($captureToken->getTargetUrl());
        }
    
        public function createSubscribePayment(Request $request) {
            $request->attributes->set('payum_token', $request->input('payum_token'));
    
            $token = $this->getPayum()->getHttpRequestVerifier()->verify($request);
            $gateway = $this->getPayum()->getGateway($token->getGatewayName());
    
            $agreementStatus = new GetHumanStatus($token);
            $gateway->execute($agreementStatus);
    
            if (!$agreementStatus->isCaptured()) {
                header('HTTP/1.1 400 Bad Request', true, 400);
                exit;
            }
    
            $agreement = $agreementStatus->getModel();
    
            $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');
    
            $recurringPayment = $storage->create();
            $recurringPayment['TOKEN'] = $agreement['TOKEN'];
            $recurringPayment['PAYERID'] = $agreement['PAYERID'];
            $recurringPayment['PROFILESTARTDATE'] = date(DATE_ATOM);
            $recurringPayment['DESC'] = $agreement['L_BILLINGAGREEMENTDESCRIPTION0'];
            $recurringPayment['BILLINGPERIOD'] = Api::BILLINGPERIOD_DAY;
            $recurringPayment['BILLINGFREQUENCY'] = 7;
            $recurringPayment['AMT'] = 0.05;
            $recurringPayment['CURRENCYCODE'] = 'USD';
            $recurringPayment['COUNTRYCODE'] = 'US';
            $recurringPayment['MAXFAILEDPAYMENTS'] = 3;
    
            $gateway->execute(new CreateRecurringPaymentProfile($recurringPayment));
            $gateway->execute(new Sync($recurringPayment));
    
            $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('paypal_ec', $recurringPayment, 'payment_done');
    
            return \Redirect::to($captureToken->getTargetUrl());
        }
    
        public function done(Request $request) {
            /** @var Request $request */
            //$request = \App::make('request');
            $request->attributes->set('payum_token', $request->input('payum_token'));
    
            $token = $this->getPayum()->getHttpRequestVerifier()->verify($request);
            $gateway = $this->getPayum()->getGateway($token->getGatewayName());
    
            $gateway->execute($status = new GetHumanStatus($token));
    
            return \Response::json(array(
                        'status' => $status->getValue(),
                        'details' => iterator_to_array($status->getFirstModel())
            ));
        }
    
    }
    

    The routes:

    Route::get('paypal/agreement', 'PayPalController@prepareSubscribeAgreement');
        Route::get('paypal/subscribe', [
            'as' => 'paypal_subscribe',
            'uses' => 'PayPalController@createSubscribePayment'
        ]);
        Route::get('paydone', [
            'as' => 'payment_done',
            'uses' => 'PayPalController@done'
        ]);
    

    Simply open www.example.com/paypal/agreement and it should take you to PayPal

提交回复
热议问题