Search code examples
paypalpaypal-sandbox

Capturing payments: The requested action could not be performed, semantically incorrect, or failed business validation


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

Approve order image

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"
        }
    ]
}

Solution

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