What happens in this situation?

110 views
Skip to first unread message

Steve Dillinger

unread,
Jun 16, 2016, 9:29:27 AM6/16/16
to Stripe API Discussion
Hi,

I asked this on IRC #stripe and was referred here for an answer.

Use case:

A user has a subscription.

The trial period has ended.

They have not yet entered a payment source.

Their subscription status is 'past_due'

---

When the user does add a card, I do this:

 customer = stripe.Customer.retrieve(stripe_customer_id)
 card = customer.sources.create(source=token.id)

 customer.default_source = card['id']
 customer.save()


---

It is my understanding that when I add the default payment source, the past_due invoice will immediately be charged.

Does that happen synchronously in the customer.save call?

ie:if my next line of code is this:

stripe.Subscription.retrieve(sub_...)

is the status is guaranteed to be active, if the card was good?

or can the charge end up being good, but I make the Subscription.retrieve call before the status is updated?

Thanks,

Steve




Remi J.

unread,
Jun 16, 2016, 9:42:21 AM6/16/16
to api-d...@lists.stripe.com
Hey Steve,

If you read the documentation for the Update Customer API [1], it says:

"When you update a customer to a new valid source: for each of the customer's current subscriptions, if the subscription is in the past_due state, then the latest unpaid, unclosed invoice for the subscription will be retried"

What this means is that this is only true if you explicitly pass a new card token in the `source` parameter of that API. When doing so, we delete the old default source, add the new one as default and then retry those invoices.

In your code, you don't do that, you add the new source and *then* you mark it as the default. This means you keep the old one on the customer and it won't trigger the automatic retries at that point. If you do want to keep the old source, you'll need to explicitly call the Pay Invoice API [2] for each invoice you want to retry.

Otherwise, if you're okay deleting the old card and pass the new token in `source` it will attempt to pay the invoices immediately. It doesn't guarantee that the subscription(s) will be back to active though since this is done separately (though automatically) and asynchronously. You'll need to listen for `invoice.payment_succeeded` events for those invoices.

Hope this helps!
Remi

--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Remi J.

unread,
Jun 17, 2016, 2:47:53 AM6/17/16
to api-d...@lists.stripe.com
Hey Steve,

Small correction on my previous answer. Assuming your customer has only one subscription that is past due, we will automatically and synchronously attempt to pay the latest past due invoice when you pass the card token in the `source` param. If that charge fails, the customer update will simply fail and you'll get an error. If the charge succeeds, you won't get an error and you'll know the subscription is now back to active. If you have multiple subscriptions past due then at least one invoice/subscription will be attempted/updated back synchronously while the others happen async.

All the best,
Remi
Reply all
Reply to author
Forward
0 new messages