简体   繁体   中英

PayPal Sandbox Execute Call returning Error 400 Bad Request

In implementing a server Paypal integration, the POST Create call works correctly to https://api.sandbox.paypal.com/v1/payments/payment with the response object matching that found in the API. The server successfully returns the result to the Client, and res.id for the .then(res) function of paypal.request.post is: PAY-76T970067E989851JLPLCMKA

After the user authorizes payment, the client sends a request to my server's execute endpoint with a payload of:

{
    "paymentID" : "PAY-76T970067E989851JLPLCMKA",
    "payerID" : "3LSD3Q8J7T3ZL"
}

The server then remodels the payload for a query to paypal's POST Execute endpoint as follows:

headers:

Content-Type = "application/json"
Authorization = "Bearer " + accessToken // checked not expired

and a body payload of:

{"payer_id" : "3LSD3Q8J7T3ZL"}

The post is then made to:

https://api.sandbox.paypal.com/v1/payments/payment/PAY-76T970067E989851JLPLCMKA/execute

at which point, the paypal server responds with: The remote server returned an error: (400) Bad Request.

Form what I can see, this matches the API requirements outlined here: https://developer.paypal.com/docs/api/payments/v1/#payment_execute

As a side note, I setup an endpoint on my own server to check the headers and JSON payload being submitted to the Paypal execute endpoint are correct.

Any suggestions would be greatly appreciated.

Resolved: Although the error is being returned when calling the Paypal's Execute endpoint, the problem actually resides in the Create payload. The soft_descriptor property submitted to the Create endpoint must be unique , just like the invoice_number property. Both of these values are found in the Transaction object, as shown here:

https://developer.paypal.com/docs/api/payments/v1/#definition-transaction .

Really, the error should be caught when creating the payment and not when executing it, but, hopefully this helps someone else.

Note to Paypal: A bit more information in the API would have saved a lot of headaches.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM