如何实施Payum的PayPal快速结账

I am trying to implement PayPal payments into my app. For the purpose, I am trying to use Payum. I got to a point where it redirects me to PayPal and I pay the sum using a PayPal account and then it redirects me back to my app, showing the following JSON output:

{
"status": "pending",
"details": {
"PAYMENTREQUEST_0_CURRENCYCODE": "EUR",
"PAYMENTREQUEST_0_AMT": "12.50",
"PAYMENTREQUEST_0_PAYMENTACTION": "Sale",
"AUTHORIZE_TOKEN_USERACTION": "commit",
"RETURNURL": "http://domovakniga.local/payment/capture/qQFU9Xv6tQDadQo22mIDHwlkGrl9TMRhMOeWmwgE8ec",
"CANCELURL": "http://domovakniga.local/payment/capture/qQFU9Xv6tQDadQo22mIDHwlkGrl9TMRhMOeWmwgE8ec?cancelled=1",
"PAYMENTREQUEST_0_NOTIFYURL": "http://domovakniga.local/payment/notify/k-kZP417hQExhiKjWnzEoFkLLMMwWP-zgjX6P8nqb2k",
"TOKEN": "EC-7TH62273TE605372U",
"TIMESTAMP": "2019-07-04T16:02:14Z",
"CORRELATIONID": "3fc016ddc111f",
"ACK": "Success",
"VERSION": "65.1",
"BUILD": "53232958",
"BILLINGAGREEMENTACCEPTEDSTATUS": "0",
"CHECKOUTSTATUS": "PaymentActionCompleted",
"CURRENCYCODE": "EUR",
"AMT": "12.50",
"SHIPPINGAMT": "0.00",
"HANDLINGAMT": "0.00",
"TAXAMT": "0.00",
"NOTIFYURL": "http://domovakniga.local/payment/notify/k-kZP417hQExhiKjWnzEoFkLLMMwWP-zgjX6P8nqb2k",
"INSURANCEAMT": "0.00",
"SHIPDISCAMT": "0.00",
"PAYMENTREQUEST_0_SHIPPINGAMT": "0.00",
"PAYMENTREQUEST_0_HANDLINGAMT": "0.00",
"PAYMENTREQUEST_0_TAXAMT": "0.00",
"PAYMENTREQUEST_0_INSURANCEAMT": "0.00",
"PAYMENTREQUEST_0_SHIPDISCAMT": "0.00",
"PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED": "false",
"PAYMENTREQUESTINFO_0_ERRORCODE": "0",
"EMAIL": "peter.v.vasilev2@gmail.com",
"PAYERID": "8Q3A8F8MYPPDA",
"PAYERSTATUS": "verified",
"FIRSTNAME": "Petar",
"LASTNAME": "Vasilevv",
"COUNTRYCODE": "US",
"SHIPTONAME": "Petar Vasilevv",
"SHIPTOSTREET": "1 Main St",
"SHIPTOCITY": "San Jose",
"SHIPTOSTATE": "CA",
"SHIPTOZIP": "95131",
"SHIPTOCOUNTRYCODE": "US",
"SHIPTOCOUNTRYNAME": "United States",
"ADDRESSSTATUS": "Confirmed",
"ITEMAMT": "12.50",
"INSURANCEOPTIONOFFERED": "false",
"PAYMENTREQUEST_0_ITEMAMT": "12.50",
"PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID": "peter.v.vasilev@gmail.com",
"PAYMENTREQUEST_0_SHIPTONAME": "Petar Vasilevv",
"PAYMENTREQUEST_0_SHIPTOSTREET": "1 Main St",
"PAYMENTREQUEST_0_SHIPTOCITY": "San Jose",
"PAYMENTREQUEST_0_SHIPTOSTATE": "CA",
"PAYMENTREQUEST_0_SHIPTOZIP": "95131",
"PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE": "US",
"PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME": "United States",
"PAYMENTREQUEST_0_ADDRESSSTATUS": "Confirmed",
"SUCCESSPAGEREDIRECTREQUESTED": "false",
"INSURANCEOPTIONSELECTED": "false",
"SHIPPINGOPTIONISDEFAULT": "false",
"PAYMENTINFO_0_TRANSACTIONID": "0TP060296E276454P",
"PAYMENTINFO_0_TRANSACTIONTYPE": "expresscheckout",
"PAYMENTINFO_0_PAYMENTTYPE": "instant",
"PAYMENTINFO_0_ORDERTIME": "2019-07-04T16:02:12Z",
"PAYMENTINFO_0_AMT": "12.50",
"PAYMENTINFO_0_TAXAMT": "0.00",
"PAYMENTINFO_0_CURRENCYCODE": "EUR",
"PAYMENTINFO_0_PAYMENTSTATUS": "Pending",
"PAYMENTINFO_0_PENDINGREASON": "unilateral",
"PAYMENTINFO_0_REASONCODE": "None",
"PAYMENTINFO_0_PROTECTIONELIGIBILITY": "Ineligible",
"PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE": "None",
"PAYMENTINFO_0_SELLERPAYPALACCOUNTID": "peter.v.vasilev@gmail.com",
"PAYMENTINFO_0_ERRORCODE": "0",
"PAYMENTINFO_0_ACK": "Success",
"TRANSACTIONID": "0TP060296E276454P",
"PAYMENTREQUEST_0_TRANSACTIONID": "0TP060296E276454P",
"PAYMENTREQUESTINFO_0_TRANSACTIONID": "0TP060296E276454P",
"PAYMENTREQUEST_0_PENDINGREASON": "None",
"PAYMENTREQUEST_0_REASONCODE": "None"
}
}

status "pending" I assume means that the payment is not yet finalized and I have to do something on my part to finalize the payment but I can't find information about that anywhere in the documentation.

Here is my Laravel controller:

<?php

namespace App\Http\Controllers\PayPal;

use Payum\LaravelPackage\Controller\PayumController;
use Payum\Core\Request\GetHumanStatus;
use Symfony\Component\HttpFoundation\Request;

class PaypalController extends PayumController
{
    public function prepareExpressCheckout()
    {
        $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');

        $details = $storage->create();
        $details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
        $details['PAYMENTREQUEST_0_AMT'] = 12.50;
        $storage->update($details);

        $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('paypal_ec', $details, 'payment_done');

        return \Redirect::to($captureToken->getTargetUrl());
    }

    public function done($payum_token)
    {
        /** @var Request $request */
        $request = \App::make('request');
        $request->attributes->set('payum_token', $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())
        ));
    }
}

I got to this point but there doesn't seem to be any information on how to proceed from here. One of the things, I think I need, is to finalize the payment so it's not in pending status anymore. The other thing I need is to pass an invoice or payment number to PayPal which then PayPal can return to me on the "payment done" page so I know which payment got through. I assume those are the only things I need to do. Any ideas on how to do them?

I tried googling various things like tutorials or examples but couldn't find any.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问