PayPal Orders V2 not processing approve url

懵懂的女人 提交于 2021-01-07 02:49:58

问题


According to PayPal orders API as document here, We have to first create order then from the response, we have to copy the approve url and run in the browser. This will open PayPal page. There buyer will approve the request. After this a capture request should be made.

Issue details

I have following code that creates the order using PayPal API:

$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $uri, [
        'json' => [
            "intent" => "CAPTURE",
            "purchase_units" => [
                [
                    "amount" => [
                        "currency_code" => "USD",
                        "value" => "100.00"
                    ]
                ]
            ]
        ],
        'headers' => [
            'Accept' => 'application/json',
            'Accept-Language' => 'en_US',
            'Content-Type' => 'application/json',
        ],
        'auth' => [$clientId, $secret, 'basic']
    ]            
);
$data = json_decode($response->getBody(), true);
echo "<pre>";
print_r($data);
echo "</pre>";

This code works fine. This gives me 4 urls as shown in the below screenshot.

After this, I copy the url with rel = approve. This one: https://www.sandbox.paypal.com/checkoutnow?token=3C454469W0667862G

Now, run this url, this will open the sandbox PayPal page. After login with buyer, and click pay, it stays on same page without any error.

Any idea why this is happening?


回答1:


    'json' => [
        "intent" => "CAPTURE",
        "purchase_units" => [
            [
                "amount" => [
                    "currency_code" => "USD",
                    "value" => "100.00"
                ]
            ]
        ]
    ],

After login with buyer, and click pay, it stays on same page without any error.

Any idea why this is happening?


You haven't specified any return_url in the create body's application_context. There is nowhere for it to redirect next, so it simply stays on the same page.

For the best user experience, do not use any redirects to an approval_url or return url. Instead use no redirects. At all.

Rather, pair your two server-side routes of 'Create an Order' and 'Capture Order' with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

This keeps your site loaded at all times.



来源:https://stackoverflow.com/questions/65483806/paypal-orders-v2-not-processing-approve-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!