Authorization Charges for Trials using Stripe

By: Richard Buehling
Stripe API, Web Development
7/31/2022

[All Articles]

The idea

So it all started when, after Bounce Factory's first month using a subscription based plan, we were able to look at some of the data in regards to the trial conversion rate, and it was clear that our conversion rate was not where it needed to be.

And, after a closer examination, we saw that there was a large amount of cards that were used for the trial, but were registered as prepaid Visa cards with no balance - they could not be charged.

So we needed to find a solution to stop allowing cards that couldn't be charged access to the free trial and looked for a way to implement an authorization hold using the Stripe API.

The code

I couldn't find a way to do this on the Stipe Documentation and I even asked Stripe Support to help me out, but there was silence. So I started researching the docs line by line (yes- it was desperation time).

Eventually I find a page that explains how to put a card on hold and authorize funds... I think I'm getting somewhere.

Problem is, I need a payment method to create a hold, where could I get that?

Back to scouring the API documentation and I check the session object. The session object is the object of a custom checkout session - the system that I am using to handle the trial signups.

One entry in the session object says setup intent id - seems interesting let me take a look at that.

So, I hit the search bar, "Setup Intent Object", whats in store under here. I look through the json object and see payment method id - GOTCHA.

This is the id that I need to feed the payment intent method to create an authorization charge.

So I built a custom request handler function AFTER a checkout that takes the checkout id, grabs the resulting session object, locates the setup intent id, grabs the setup intent object, locates the payment method id, feeds that to a payment intent method to authorize $10 If it fails - nope, no access for the user. If it goes through, refund the hold, and then business as usual.

No more prepaid cards.

If you would like to see my code - feel free to reach out!

Recent