I’m working on the code to cover negative scenarios like card declined and similar.
According to the documentation the only way to do it for Orders is to use the header PayPal-Mock-Response https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/
However, it doesn’t work for me, I’m getting the 403 error with an empty response every time I try to add the "PayPal-Mock-Response" header with any error, can’t get it working at all
Example, request:
POST https://api-m.sandbox.paypal.com/v2/checkout/orders
params:
{
"method": "post",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer A21[reducted]",
"PayPal-Mock-Response": "{"mock_application_codes":"DUPLICATE_INVOICE_ID"}"
},
"body": "{"intent":"CAPTURE","purchase_units":[{"custom_id":89534,"description":"my item name","reference_id":648,"amount":{"currency_code":"USD","value":"5.01"}}]}"
}
Response:
{
"statusCode": 403,
"responseText": ""
}
I’m using nodejs, node-fetch package, the auth token is correct as I’ve got positive scenario working, the 403 error is only being thrown when I add the "PayPal-Mock-Response" header.
what am I doing wrong or is there any other way to make a failed payment on sandbox?
2
Answers
DUPLICATE_INVOICE_ID
is not a valid error to mock for a /v2/checkout/orders creation API call…It is, however, a valid error for a v2 orders capture API call:
And this example is what is actually given in the documentation you reference.
—
Conceptually: understand that the invoice ID will be checked at capture time. You can create as many orders (for use in checkout attempts) as you want for a given invoice ID, there is no issue with duplication at that the point of retrying approvals for the same ID. A duplicate invoice error is when trying to capture (create a transaction with) an ID that has already resulted in a successful transaction being created for that account. The point is to prevent duplicate payments, not prevent repeat checkout attempts that haven’t yet resulted in a payment being created.
I still have the same problem. Negative testing is active and i used the following header:
Debugger Screenshot with Reponse code
The API is still responding with a 403. When i remove the header a new order is responded.