3

I am trying to test out subscriptions using Braintree and PHP. I am able to post transactions successfully, but I am running into this issue with subscriptions.

Here are my steps:
1. Create customer with the credit card attached
2. Create subscription for the customer

Problem:
Step 1 or 2 both result in success even though the credit card I provided has an expiration date of Jan 2013.

I have followed the tutorial given on Braintree, with no luck or documentation help. Any ideas?

Thanks.

user2268247
  • 33
  • 1
  • 3

1 Answers1

10

I work at Braintree. Feel free to contact our support team if you need more detailed help.

We don't check expiration date in our Sandbox environment. If we did, and you hardcoded an expiration date in your tests, they could fail after that date had passed.

Instead, you use an amount equal to the desired processor response code to simulate failures:

Test Amounts for Unsuccessful Transactions

When working with transactions, you can pass specific amounts to simulate different responses from the gateway.

  • Amounts between $0.01 - $1999.99 will simulate a successful authorization
  • Amounts between $2000.00 - $2060.99 and $3000.00 - $3000.99 will decline with the > - coordinating Processor Response
  • Amounts between $2061.00 - $2999.99 will simulate the generic decline message “Processor Declined.”
  • Amounts $3001.00 and greater will also simulate a successful authorization

An expired card is processor response code 2004:

Code    Text
2000    Do Not Honor
2001    Insufficient Funds
2002    Limit Exceeded
2003    Cardholder's Activity Limit Exceeded
2004    Expired Card

So setting the amount of your subscription to $2004.00 will cause it to fail as if the card were expired, regardless of the expiration date you use.

This way, you can write your tests once, and have them keep working even after any expiration dates have passed.

agf
  • 171,228
  • 44
  • 289
  • 238
  • Thanks! That helps a lot. I have added a check on my side to not allow expired cards but then I can also show the error message from Braintree if that happens as well. – user2268247 Apr 13 '13 at 02:13
  • @user2268247 Glad to help. Don't hesitate to reach out to our support team if you have any more questions. – agf Apr 13 '13 at 02:24
  • This is not clear in the docs. I assume now that test credit card numbers are for production mode only, but i struggled with this for an hour – Shrolox Feb 02 '16 at 20:01
  • @Shrolox test numbers are also for sandbox mode but serve a different purpose. – agf Feb 02 '16 at 20:36
  • @agf Oh ok. But am i right saying that numbers like "4111 1111 1111 1111" won't trigger a Processor declined error ? – Shrolox Feb 02 '16 at 20:45
  • @agf Does "subscription_charged_unsuccessfully" webhook fire when a recurring payment fails. I want to confirm if this is equivalent to invoice.payment_failed on Stripe, where for instance, a guy is on a subscription, and 1 month later, he misses his payment, so will"subscription_charged_unsuccessfully" fire in that scenario? – Ali Gajani Apr 29 '16 at 17:29
  • @AliGajani Yes, that's the purpose of the webhook. Take a look at the [subscription webhook docs](https://developers.braintreepayments.com/reference/general/webhooks/subscription/php) and [reach out to Braintree support](https://support.braintreepayments.com/) if you have more questions. – agf Apr 30 '16 at 09:42
  • @agf How would we test a payment failing for a subscription? The amount is already specified on Braintree and I don't feel it would be secure having our server accept a payment amount from a client. I _could_ add a check if the server is in a testing environment, but is there a better way? – c1moore Jul 07 '16 at 14:28
  • @c1moore You can test failing subscription payments using the dollar amounts above without involving your client. Create a plan through the Braintree Gateway with a 1-day trial period, then make a direct API call to `Subscription.create()` with an error-inducing dollar amount. After the 1-day trial period expires and the subscription is unsuccessfully charged, you can make a `Subscription.retry_charge()` call. For integration testing in the sandbox, it might be useful to create a plan for each failure-state dollar amount from which you can create subscriptions that all fail consistently. – Dana K. Jul 07 '16 at 17:00