PayPal Server SDK: how to approve an order ID

限于喜欢 提交于 2021-01-28 10:12:18

问题


I was trying to implement paypal api for one of my projects

I am using sandbox environment and server side sdk

In the request i have

{
    "intent": "CAPTURE",
    "application_context": {
      "brand_name": "EXAMPLE INC",
      "landing_page": "BILLING",
      "shipping_preference": "SET_PROVIDED_ADDRESS",
      "user_action": "PAY_NOW"
    },

i.e

"intent": "CAPTURE"
"user_action": "PAY_NOW"

I created an order using the api OrdersCreateRequest(). In the response i get the

result.id = "IDVALUE"
result.status = "CREATED"

and also the links

"links": [
    {
        "href": "https://api.sandbox.paypal.com/v2/checkout/orders/XXXXXXXX",
        "method": "GET",
        "rel": "self"
    },
    {
        "href": "https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX",
        "method": "GET",
        "rel": "approve"
    },
    {
        "href": "https://api.sandbox.paypal.com/v2/checkout/orders/XXXXXXXXXXXXXX",
        "method": "PATCH",
        "rel": "update"
    },
    {
        "href": "https://api.sandbox.paypal.com/v2/checkout/orders/XXXXXXXXXXXXXX/capture",
        "method": "POST",
        "rel": "capture"
    }
],

I have tried to open the url

        {
            "href": "https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX",
            "method": "GET",
            "rel": "approve"
        },

In the browser, it asks for PayPal login, what credentials we have to use as login and password. I have only client_id and client_secret

How to get an approved order id. What should I do now.


回答1:


The next step is to redirect the payer to that approval_url or use the Order ID with Smart Payment Buttons, which is better than redirecting. Either way the payer will be signing in with their PayPal (sandbox) buyer account or entering their (sandbox) buyer information in a PayPal window or form.

The best approval flow to use is the one at https://developer.paypal.com/demo/checkout/#/pattern/server

Note that it pairs with two routes on your server, one that creates the order and one that captures the order after approval.




回答2:


How to get the username and the password for the sandbox account.

Navigate to

And we see the email and password which can used to as paypal login credentials while approve the order

So now go to the approve url https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX

and click on login (paypal account) and enter email and password

And after successful login pay here

So now the order gets approved.



来源:https://stackoverflow.com/questions/64097005/paypal-server-sdk-how-to-approve-an-order-id

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