Receiving a Webhook Notification and subscribe user and renew user plan in stripe

1,685 views
Skip to first unread message

Sunny Bhakta

unread,
Mar 12, 2015, 7:58:30 AM3/12/15
to api-d...@lists.stripe.com
 

I am doing payment integration with stripe . I have to add a subscribe user functionality based on the plan what the user chooses. I am able to create plan and also able to subscribe the user to plan.
But My question is that I have to renew the user after their subscription ends; means one type on recurring payment.
I read this tutorial and this tutorial but not getting, how to Sync stripe and my site for webhook?

Ryan

unread,
Mar 14, 2015, 3:09:03 PM3/14/15
to api-d...@lists.stripe.com
Hi Sunny, 

We recently completed integration of the subscription module into our site. 

When a customer agrees to purchase a subscription from your site, Stripe should automatically bill them every month until the plan is cancelled. 

The webhooks are good because you can report data back into your site when certain events occur, than you can program how those events will work. For us, whenever a credit card is charged, or a new subscription is created, we basically add that event into our transaction log, and than we update the customer's account for an additional month of service. Ex: Let's say a customer is a Free user, and subscribed to a Gold plan for $100 .. today is 3/14, which means they will be active-until 4/14 within our system for a subscription. On 4/13 / 4/14, Stripe will automatically charge their credit card for an additional month of subscription service. The webhook for a successful charge will go through our system for that specific customer (we use metadata for each customer on the transaction in Stripe), and our system will than update the table "customers" to ensure their active-until date is 30 more days in advanced. 

In terms of the webhooks.. was there a particular once you're having trouble with? 

Thanks,
Ryan
RatingsBuddy.com

Sunny Bhakta

unread,
Mar 16, 2015, 2:00:40 AM3/16/15
to api-d...@lists.stripe.com
Thank you Ryan for you answer but yet i am not clear.

1) I set the webhook end point like http://example.com/webhook-mailer.php.
2) I send test webhook and i got Test webhook sent successfully

After that i used this code in my webhook-mailer.php

\Stripe\Stripe::setApiKey("sk_test_luVc0t9Tim0Pg9MuPhmcyKg8"); $input = @file_get_contents("php://input"); $event_json = json_decode($input); http_response_code(200);

But i want to know how it will notify to me that this customer customer is updated and how can i update the customer for next 30 days. I require that code to get status of customer and update their subscription. Thanks

Matthew Arkin

unread,
Mar 16, 2015, 2:05:17 AM3/16/15
to api-d...@lists.stripe.com
Stripe will automatically charge the customer's card every subscription renewal. When it does this you'll get a few webhooks sent out: invoice.created, invoice.payment_succeeded, charge.succeeded, subscription.updated. When dealing with subscriptions, most people just listen to invoice.payment_succeeded and invoice.payment_failed.

The invoice.payment_succeeded webhook will have the customer id, subscription id, and the new period start and end of the subscription.

Matt

--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at http://groups.google.com/a/lists.stripe.com/group/api-discuss/.

To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.

Sunny Bhakta

unread,
Mar 16, 2015, 4:47:59 AM3/16/15
to api-d...@lists.stripe.com
Thank Matthew Arkin for your reply .

i know this "
The invoice.payment_succeeded webhook will have the customer id, subscription id, and the new period start and end of the subscription.";

i am able to get from https://dashboard.stripe.com/account/webhooks

But how can i get it in my browser so i can update in database.

Thanks

Steve Sensenig

unread,
Mar 20, 2015, 8:53:45 AM3/20/15
to api-d...@lists.stripe.com
Once you have $event_json, it is an array that contains all the data you need, so you have to then parse it out to find out which type of event it is, and if it is invoice.payment_succeeded, parse further to find out which customer, the new end date, etc. as needed. For example:

$dataobj = $event_json['data']['object'];
$event_type = $event_json['type'];
if($event_type == "invoice.payment_succeeded")
        {
          $stripe_custid = $dataobj['customer'];
                //in my case, I've stored the stripe customer id with my customer info in my database so I process based on that
                .............
Reply all
Reply to author
Forward
0 new messages