PayPal-Mock-Response header not working -- got 403 error instead. Help!

zylvie
Contributor
Contributor

I'm following the guide here to simulate a negative/declined response: https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/

 

Here's a sample request I made using Python:

 

order_id = 'SOME_VALID_ORDER_ID'

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer THIS_IS_MY_ACCESS_TOKEN',
    'PayPal-Mock-Response': '{"mock_application_codes": "INSTRUMENT_DECLINED"}'
}

response = requests.post(f'https://api-m.sandbox.paypal.com/v2/checkout/orders/{ order_id }/capture/', headers = headers)

 

It returns an empty response body, with status code 403.

 

What can I be doing wrong here?

Login to Me Too
3 REPLIES 3

MTS_Jennifer
Moderator
Moderator

Hello @zylvie ,

Thank you for posting to the PayPal Sandbox Community.

I tested in Postman, putting all the values in the header and was able to get the correct response.

Here is what I passed in:

Post to this endpoint (with any order id you can even use this one 5O190127TN364715T)

https://api.sandbox.paypal.com/v2/checkout/orders/{{order_id}}/capture

 

Here are the header Key and Values:

Content-Type Value: application/json
Authorization Value: Bearer{{access_token}}
PayPal-Mock-Response Value: {"mock_application_codes": "INSTRUMENT_DECLINED"}

Here is the response:

Response:
{
    "name": "UNPROCESSABLE_ENTITY",
    "details": [
        {
            "issue": "INSTRUMENT_DECLINED",
            "description": "The instrument presented  was either declined by the processor or bank, or it can't be used for this payment."
        }
    ],
    "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
    "debug_id": "",
    "links": [
        {
            "href": "https://developer.paypal.com/docs/api/orders/v2/#error-INSTRUMENT_DECLINED",
            "rel": "information_link",
            "method": "GET"
        }
    ]
}

As long as you have an order id being passed into the endpoint you should get the valid Instrument Decline error.

Thank you,

Jennifer

MTS

PayPal

Login to Me Too

zylvie
Contributor
Contributor

Hi @MTS_Jennifer, thank you for your quick response.

 

Unfortunately I tried the same in Postman, and it still gave me a 403 error.

 

I generated my access token 3 times (to get 3 different bearer tokens for my Authorization header), and all 3 times it returned a 403 error.

 

Every other API call works using my bearer token (e.g. creating orders, capturing orders without the "PayPal-Mock-Response" header, etc.), so I don't understand why this particular API call fails.

 

Is there anything else I should troubleshoot?

 

Can I provide you with my credentials so you can look into it?

Login to Me Too

MTS_Jennifer
Moderator
Moderator

Hi @zylvie ,

Thank you for contributing to this post. Can you please open a ticket so we can troubleshoot this further with you.

Here is how:

  • Go to https://paypal.com/mts
  • Click Contact Us
  • Click Log in with PayPal
  • Log into your PayPal Account
  • Click Contact Us
  • Fill in the details including the Client ID and any debug ids

Once you open the case we can work directly with you to resolve this issue.

Thank you,

Jennifer

MTS

PayPal

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.