5

I want to add some unit tests for our billing system which is using braintree but I don't know how to change the subscription period from 1 month (minimum in braintree for now) to 1 day. I cannot wait 1 month to execute my test. is there any solution to do that?

Minh Dang
  • 149
  • 1
  • 6

2 Answers2

4

I recently asked Braintree support a similar question and here is the advice I was given:-

The sandbox environment is setup to mimic the production environment exactly. Unfortunately, this leaves us at the mercy of real time as well. However you can definitely test the subscription_charged_unsuccessfully and subscription_went_past_due webhooks in the sandbox by creating a past due subscription using the steps below:

Create a plan with a 1 day trial and $2000 price (a test amount that will automatically simulate a decline) Create a customer with a credit card Create a new subscription using the plan and customer The first charge attempt will be after 1 day (when the trial expires) and will fail The automatic retries will be at +10 and +20 days of the subscription going past due – this timeline can be changed by updating the recurring billing retry logic in your Control Panel You could also test the subscription_charged_successfully webhook using the same basic principles – simply create a plan with a 1 day trial and a price less than $2000.

I hope that helps.

Liam Weston
  • 233
  • 1
  • 3
  • 11
0

I work at Braintree. Feel free to reach out to support@braintreepayments.com with any further questions.

You can't modify the subscription billing period to shorter then a month. Sandbox is designed to mimic production for end-to-end testing and since Braintree doesn't offer subscription billing in smaller increments then a month we have decided to not offer a shorter billing period in sandbox.

matdevdug
  • 9
  • 1
  • 1
    Thanks for your answer. Is there any workaround for that? How can I ensure it will work as expected before go to production? – Minh Dang Feb 11 '15 at 03:35
  • What functionality in particular are you trying to test? – matdevdug Feb 11 '15 at 17:08
  • 1
    I want to test renew & cancel subscription. – Minh Dang Feb 16 '15 at 02:27
  • 1
    This is really unfortunate given that the sample notifications produced by webhookTesting are missing most of the fields of a real notification. At this point I'm not sure how we're intended to test a webhook handler with any kind of complexity in it. I guess capturing a notification of each type and reusing it would work, so long as your handler doesn't need to make any subsequent calls to BT (in which case the state of the sandbox won't match). – mmitchell Jul 18 '18 at 23:40