skip to Main Content

About the issue

This is about create order api in Paypal. Documentation link is here I am trying to pass below payload, so that the request could have my return and cancel url and everything works perfectly.

"intent": "CAPTURE",
"purchase_units": [
    {
        "amount": {
            "currency_code": "USD",
            "value": "100.00"
        }
    }
],
"application_context" => [
    "return_url" => "my return url",
    "cancel_url" => "my cancel url"
]

Just the return and cancel url has gone deprerated in application_context.

To overcome this problem, I removed application_context from payload and added payment_source like below which has return and cancel url

"intent": "CAPTURE",
"purchase_units": [
    {
        "amount": {
            "currency_code": "USD",
            "value": "100.00"
        }
    }
],
"payment_source": {
    "paypal": {
        "experience_context": {
            "return_url": "return Url",
            "cancel_url": "cancel Url"
        }
    }
}

Now, it gives an error message – PAYPAL_REQUEST_ID_REQUIRED

I need to pass return and cancel url and at this stage I only need to create the request to let user go to checkout page. that’s it. I really don’t have any payment info yet.

6

Answers


  1. https://developer.paypal.com/api/rest/reference/orders/v2/errors/

    PAYPAL_REQUEST_ID_REQUIRED: A PayPal-Request-Id is required if you are trying to process payment for an Order. Please specify a PayPal-Request-Id or Create the Order without a payment_source specified.
    

    Add this param in your headers

    PayPal-Request-Id   
    string [ 1 .. 36 ] characters
    The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager.
    
    Login or Signup to reply.
  2. To resolve the error message "PAYPAL_REQUEST_ID_REQUIRED", you need to including a unique identifier in the "request_id" field in the payload.

    something like:

    [
       "intent":"CAPTURE",
       "purchase_units":[
          {
             "amount":{
                "currency_code":"USD",
                "value":"100.00"
             }
          }
       ],
       "payment_source":{
          "paypal":{
             "experience_context":{
                "return_url":"return Url",
                "cancel_url":"cancel Url"
             }
          }
       },
       "request_id":"UNIQUE_REQUEST_ID"
    ]
    

    You may also verify that the return and cancel URLs provided in the payload are valid and accessible.

    Login or Signup to reply.
  3. Inside your payment_source add "request_id": "YOUR_UNIQUE_REQUEST_ID"

    Your system can generate this request Id yourself and must be unique to prevent getting error message DUPLICATED_REQUEST_ID

    See here in documentation https://developer.paypal.com/api/rest/requests

    PayPal-Request-Id
    "Optional. Contains a unique user-generated ID that the server stores for a period of time. Use this header to enforce idempotency on REST API POST calls. …."

    Login or Signup to reply.
  4. You need request_id could you try including reference_id.

    
    {
      "intent": "CAPTURE",
      "purchase_units": [
        {
          "reference_id": "d9f80740-38f0-11e8-b467-0ed5f89f718b",
          "amount": {
            "currency_code": "USD",
            "value": "100.00"
          }
        }
      ],
      "payment_source": {
        "paypal": {
          "experience_context": {
            "return_url": "https://example.com/returnUrl",
            "cancel_url": "https://example.com/cancelUrl"
          }
        }
      }
    }'
    
    Login or Signup to reply.
  5. This error is when:
    The request is not well-formed, is syntactically incorrect, or violates schema:
    https://developer.paypal.com/api/rest/reference/orders/v2/errors/

    I could solve it changing it for this sintaxis:

    /**
     * Recibe el valor de la orden de pago y la moneda
     */
    public function createOrder($value, $currency)
    {
        return $this->makeRequest(
            'POST',
            '/v2/checkout/orders',
            [],//queryParams
            [
                'intent' => 'CAPTURE',//required
                'purchase_units' => [//required
                    0 => [
                        'amount' => [
                            'currency_code' => strtoupper($currency),
                            'value' => $value,
                        ]
                    ]
                ],
                //'payment_source' => [
                    //'paypal' => [
                        'experience_context' => [
                            'payment_method_preference' => 'IMMEDIATE_PAYMENT_REQUIRED',
                            'payment_method_selected' => 'PAYPAL',
                            'brand_name' => config('app.name'),
                            //'locale' => 'es-ES', -> cambiar?
                            //'landing_page' => 'LOGIN', ?
                            'shipping_preference' => 'NO_SHIPPING',
                            'user_action' => 'PAY_NOW',
                            'return_url' => route('approval'),
                            'cancel_url' => route('cancelled'), 
                        ],
                    //]
                //],
                
            ],//cuerpo
            [],//cabeceras
            $isJsonRequest = true,//es un json lo que viene
        );
    }
    

    But I am using Guzzle client in PHP.

    Login or Signup to reply.
  6. Add and pass the header key as "PayPal-Request-Id" and for value you can pass any unique ID. It has to be unique for every transaction.
    Adding this header should fix issue for you.
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search