Stripe's documentation explains that their charges API is synchronous. Why then do we need webhooks?
If my application performs a Stripe_Charge::create()
(in PHP) then can I not take the return value and log that as a successful transaction in our database and send a confirmation email right in the same execution?
Is webhooks only used if you have a different back office system that needs to be notified? What other types of events are useful to listen to on a webhook?
When calling Stripe_Charge::create(), you can indeed, as you stated, log that as a successful transaction (assuming it didn't fail) and send your confirmation email.
Webhooks are extremely useful when using stripe to manage recurring payments, such as when selling a subscription. Under this scenario, many things are happening that were not directly initiated by a user request.
Assume for example that a user subscribes to your Gold Plan, which has a 30 day free trial. Three days before the trial ends, the customer.subscription.trial_will_end webhook is triggered. You might respond to this by sending the customer an email thanking him for trying out your subscription, and remind him that his card is about to be charged.
Then, 3 days later when his card is charged, and the payment succeeds, you can respond to the charge.succeeded webhook to send him an invoice every month.
Another very useful webhook is charge.failed. Depending on your retry settings, you can respond to this by letting the user know that their card is being declined, and warn him that in n days his subscription will be terminated.
In summary, if you're not utilizing subscriptions or invoices, the webhooks have limited usefulness. But if you are, they are indispensable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With