How to simulate Past-Due status on Subscription
Asked Answered
A

3

12

I have setup a PHP script on a cron which contacts Braintree via the API to look up the status of each subscription that we have on file. We then update our local records based on the customer's subscription status. Because I can manually cancel a subscription from the Braintree control panel, I have been able to test that my script can detect canceled subscriptions.

However, I can't find any way to test a past-due status other than to wait for the billing cycle to go 'round. Because the minimum length of a billing cycle in Braintree is one month, this makes debugging my script very difficult.

I know that in theory I should just see a different string for the status of the subscription, but I'm looking for a reproducible way to simulate past-due status, along with a positive balance and value for daysPastDue.

Can anyone help?

$BT_subscription = Braintree_Subscription::find($BT_subscription_id);
if ($BT_subscription && $BT_subscription instanceof Braintree_Subscription) {
    if ($BT_subscription->status == 'Past Due' && $BT_subscription->balance > 0) {
        // ...
Achlorhydria answered 16/7, 2013 at 1:50 Comment(0)
A
24

I got the following reply from Braintree support about this issue:

Because our sandbox environment is meant to replicate our production environment there is no way to force a subscription to past due. However here is a little work around that might make this testing easier:

To put a subscription in the Past Due status in the Sandbox, you can create a subscription with a trial period of one day and a price of $2000. Then, when the one day trial expires, it will trigger a transaction create that will fail because of the dollar amount.

The $2000 price tag is likely for the Test Amounts for Unsuccessful Transactions to trigger the credit card payment to fail. I have setup a test, and will edit this if the test proves unsuccessful.

Achlorhydria answered 16/7, 2013 at 2:12 Comment(13)
I work at Braintree. Yep, that's where that amount comes from. Should work fine. Drop a comment here so I get notified if you have any problems.Chafe
Glad to hear it. Let us know if we can answer and more questions about your integration.Chafe
I really like Braintree, but having to do this is a real bummer, and frankly, quite surprising. @Chafe Any new tools since the original post?Gluteus
@Gluteus if you're looking for better ways to test, I'd recommend emailing [email protected]. As far as I know, this is still the best advice.Chafe
So braintree expects their developers to write some code for handling cancel events, run it, and wait a day to see if it works? That's a sad way to build an integration.Stickseed
@Chafe That is the advice Braintree support offer to test this.Heng
Not to mention that this doesn't allow me to test my actual plans, with actual prices and no trial periods.Kakapo
This will also not allow you to test a customer updating their payment method and retrying the transaction, the charge will just fail again.Pharmacopoeia
Worth to mention that if you setup a 1 day trial, it won't try to charge the card exactly in 24 hours, but randomly between 12 and 24 hours in my tests...Hollenbeck
This is a lot of dead time just to test the subscription lifecycle and their webhooks. Maybe offering the ability to alter the trial expiration on a subscription isn't feasible, but even if you logged webhooks requests to view on other test subscriptions in the test environment, or offer a mock API to pass legit webhook requests (not fake barebones requests) would be a HUGE help. I understand most restrictions come from the PayPal API itself, but surely there are ways to expedite/work around this for developers?Rachmaninoff
This is indicative of my experience with Braintree overall. Really awful work arounds for things that should be built into the platform. @ChafeBeltran
The fact that I just had to create 100 trial subscriptions, and now have to wait till tomorrow before I can look at a bug, is pretty substandard.Musette
I tried to decline the settlement with gateway.testing.settlementDecline(transactionOfSubscription.transactionID), as Braintree suggested, that should also move Active subscription to Past Due but it would not do it. At least not in a few minutes.Pi
G
5

Adding on to Tyler V's response, and this is still the only way to test it, unfortunately.

From support:

Thanks for reaching out, and appreciate your patience. Using a sandbox account, the shortest amount of time you can simulate a result will be 1 day. Use the following example to create a Past Due status:

Create a plan with a 1 day trial and $2000 price 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 Please see the following page for Sandbox test values. I would recommend that the you create a LOT of these at one time so you have multiples to work with; otherwise you’ll have to wait a day for each new one they create to move into past due.

Gluteus answered 9/3, 2015 at 3:41 Comment(0)
N
-1

@Tyler V.

  • When creating a new subscription, you can set first_billing_date to one day ahead
  • You should enable Webhook, store the message, and replay it by using postman.
Nectarine answered 29/10, 2019 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.