Search code examples
paypalpaypal-sandbox

PayPal Server SDK: how to approve an order ID


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.


Solution

  • 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.