Jump to content
Larry Ullman's Book Forums

Create Subscription That Initializes Months Later


Recommended Posts

I have a for-sale-by-owner real estate website that I want to charge a monthly listing subscription fee to keep a property listing active. But I also need to pre-sell my monthly subscription service to customers so that I don't lose business to my competitors ahead of the Spring/Summer home selling market.

 

Thanks to your wonderful book, I have the single Stripe charges working successfully. So I'm basically charging the customer for their first months' subscription upfront without knowing when the customer will actually initialize their property listing in the coming weeks or months (note: these pre-sale subscriptions will expire after 6 months of inactivation).

 

Each customer goes to their dashboard after logging in. The dashboard lists property listings that have already been previously activated, as well as, purchased property listing subscriptions that have not yet been activated. It is on this page that I would like to add PHP code that would create a new Stripe recurring payments subscription when the customer clicks the "Activate Listing Subscription" button.

 

The first month of the Stripe subscription would be free considering the customer has already paid for the first month when the customer initially purchased the listing subscription service. I have already created the Stripe plan for this payment scenario where the customer gets billed a monthly subscription fee after the first free month.

 

My question is how can I start a Stripe subscription without asking the customer for all of their credit card payment information again? (You can imagine that for a customer who wants to activate their listing subscription right away, having to input their credit card info a second time would be very frustrating - and for that customer I can use the same Stripe charge ID to start a subscription in the same PHP script that processes the initial purchase. What information from Stripe can I save in my database that I can use to process a Stripe subscription in the future?

Link to comment
Share on other sites

I should say the Stripe token, not charge ID. Or is it maybe that I should be using the charge ID? I don't know how to make this work. Can I make a call to the Stripe server to charge the same customer to start a Stripe subscription? What calls would I need to make? I'm sure there's a way to do this. I need to get the site up and running asap. Thanks, Larry!

Link to comment
Share on other sites

If I understand your question correctly, all you need to do is create a Customer object in Stripe (for each user of users) and store the token on the customer. You can then create standalone charges or subscriptions whenever you need. 

 

I don't know of any books about this particular subject, sorry! But thanks for the nice words on my book!

Link to comment
Share on other sites

Okay, so that will allow me to capture the token from the Customer object when performing the initial single charge and then use that same token to start a subscription at a later point in time (more than 7 days after initial credit card charge) without asking the customer for the credit card info all over again?

 

So how do I capture the Customer object's token using your single charge script?  Do I get that info back from the Stripe server as part of the response to your single charge script?  Or do I have to make a separate call to Stripe's server after we receive the initial token confirming successful credit card processing?

 

Also, I'm assuming I would need to make sure the credit card can still be charged (i.e., that it's not maxed out) at the time that it will be used?  Or does Stripe do that for me and notify me if there are any problems?  Would the same possible errors/problems be received from Stripe's server as when making a single charge?

 

We already have a "customers" MySQL table, so I guess it would be logical to save the customer token there, correct?

Link to comment
Share on other sites

So the steps are:

 

1. Use Stripe.js or Checkout to tokenize the user's payment details

2. Make a "create Customer" API call to Stripe using server-side code, attaching the token to the customer (in Stripe)

3. Use the customer ID for future charges or subscriptions

 

See https://stripe.com/docs/quickstart for additional information and code examples.

Link to comment
Share on other sites

 Share

×
×
  • Create New...