3
votes

In my Ruby on Rails SaaS application users can subscribe to monthly or yearly plans. I am using Stripe as a payment processor. Stripe also handles all the subscriptions and re-bills users on a monthly (or yearly) basis.

I am also a member of an affiliate network which gets notified about every new subscription / charge that a user makes, so that the advertiser may get rewarded (if there is one). This works great for new subscriptions because Stripe instantly notifies me if a payment went through or not.

But what about recurring subscription payments? I have to (and want to) inform my affiliate network about those too, however, in my web application I can't really detect whether a recurring payment has been made. I can assume that it will be made, say, on the 24th of each month but that's not for sure.

Is there a better way for a web app to detect when a recurring subscription payment has been successfully processed by Stripe? My affiliate network requires me to show some little Javascript snippet on the frontend whenever a charge has been made.

Thanks for any help.

2

2 Answers

7
votes

Yes, you can easily do it by using webhooks

Use webhooks to be notified about events that happen in a Stripe account. You have to do the following for successful recurring subscription payment notification.

  1. You have to create new endpoint (your application url which will accept the request from stripe) from dashboard which indicate Stripe to request after every successful Charges. You can create webhooks here
  2. Add endpoint -> Set URL of your application to be called, Filter event (charge.succeeded)
  3. In you application endpoint, you will receive Event object. Inside the object you can get "data"->"object" which will contain the charge object
  4. By this charge object you can get all of your needed information.
  5. When you get the information regarding the payment, then you can do your application stuffs...
0
votes

As Zico said, yes use webhooks. Here is a good tutorial of how to set up webhooks.

https://www.truespotmedia.com/testing-webhooks-in-stripe-with-php/