I have a problem with the new PayPal API (v2) and sandbox
1- Create an order https://api.sandbox.paypal.com/v2/checkout/orders
{
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": 10
},
"payee": {
"email": "[email protected]",
"merchant_id": "xxxx"
}
}
],
"application_context": {
"shipping_preference": "NO_SHIPPING"
}
}
2- Go to the approve
link in the response
If the sandbox account has a credit card, PayPal shows: "Sorry, we are not able to process your request. Please try again later"
3- Log in and approve the order
The sandbox account doesn't have a credit card
When the continue button is clicked, the page show the loading indicator and it disappears again and nothing happens
4- Check the order's status and it's APPROVED
{
...
"status": "APPROVED"
...
}
5- Try to capture the payment https://api.sandbox.paypal.com/v2/checkout/orders/xxx/capture
{
"name": "UNPROCESSABLE_ENTITY",
"details": [
{
"issue": "TRANSACTION_REFUSED",
"description": "The request was refused"
}
],
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "939b641049ad2",
"links": [
{
"href": "https://developer.paypal.com/docs/api/orders/v2/#error-TRANSACTION_REFUSED",
"rel": "information_link",
"method": "GET"
}
]
}
I figured it out. It's quite simple. The body payload was missing the return_url
in application_context
.
PayPal really needs to document errors better.
The UNPROCESSABLE_ENTITY
error covers a huge swathe of issues, as covered in their docs here:
https://developer.paypal.com/docs/api/reference/orders-v2-errors/#capture-order
In my instance it was that I was using the old test Visa 4111 1111 1111 1111. These days you have to use a test card number that you generate in your developer account here: https://developer.paypal.com/developer/creditCardGenerator
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With