How to test negative responses for test values with PayumBundle and Paypal

288 Views Asked by At

I am using PayumBundle (https://github.com/Payum/PayumBundle) with my symfony application (2.8.49).

I would like to test how my application interacts with payment error responses.

With Stripe gateway, it is not an issue since some card numbers will make the stripe API render an error response.

But With Paypal, I don't know how to do it ? I read the documentation of the Paypal Sandbox API (https://developer.paypal.com/docs/api/test-values/#) and this is what they say :

To trigger the SENDER_EMAIL_UNCONFIRMED simulation response, set the items[0]/note value to ERRPYO002 in the POST v1/payments/payouts call.

curl -X POST https://api.sandbox.paypal.com/v1/payments/payouts \
  -H "content-type: application/json" \
  -H "Authorization: Bearer Access-Token" \
  -d '{
  "sender_batch_header": {
    "sender_batch_id": "1524086406556",
    "email_subject": "This email is related to simulation"
  },
  "items": [
  {
    "recipient_type": "EMAIL",
    "receiver": "[email protected]",
    "note": "ERRPYO002",
    "sender_item_id": "15240864065560",
    "amount": {
      "currency": "USD",
      "value": "1.00"
    }
  }]
}'

How can we test errors with Paypal using Payum Bundle?

Thank you in advance

2

There are 2 best solutions below

1
Ezequiel Esnaola On

What you should evaluate are the response and the status code. To generate the requests you could use Guzzle that simplifies all.

Regards!

0
Nadjib On

UPDATE / ANSWER

Actually, I managed to do negative tests.

What you had to do is first enable negative testing for your business account within your Paypal Dashboard check this URL for documentation: https://developer.paypal.com/docs/classic/lifecycle/nt-classic/#

Then, once negative testing is enabled, in the payment field, during payment checkout, you need to select amounts that match the Paypal amounts trigerring an error, which are listed in this link: https://developer.paypal.com/docs/classic/api/errors/#10000-to-10099

For example, if you want to trigger the amount-related error code 10009, on your website, when selecting the amount you want to pay with your paypal account, select the amount "100.09". If you want the error code 10014, select the amount "100.14" etc etc

The reason I did not found this in the first place is that the Paypal documentation is not clear enough. In their documentation, https://developer.paypal.com/docs/classic/lifecycle/nt-classic/#test-api-error-handling-routines,

they don't tell you explicitly "enter an amount equal to the error code with the two last digits to the right of the decimal point". Instead they tell you: "To trigger an error condition on an amount-related field, specify a error code value as a number with two digits to the right of the decimal point. For example, specify a value of 107.55 to trigger the 10755 error."

Which is not very clear to me.

Problem solved.