4

I'm currently implementing a payments platform for my website which is very similar to Stripe, but I still can't understand the process or how should I use WebHooks since I need to specify one on my account in the payments platform.

So let's say a person pays on my website for a product that costs $5, I take them to the payment form where they will introduce credit card details. Now when they click "Pay Now" everything gets verified via javascript/jquery and sent to my server and I'm able to charge the user successfully and see it reflected on my Sandbox from my account on the payment platform. Where or when should WebHooks be used or called, or why do I need them?

Thanks in advance

1
  • Hey, we also creating Similar Payment Processor service in our company. Could we connect to help each other? Linkedin or Facebook Commented Oct 28, 2018 at 1:07

2 Answers 2

12

Webhooks are a way to communicate with your application. With many APIs, you send them a request and the API response is included in the response to your request. But what if the request you make is asynchronous, or if for some reason the API you're using wants to be able to communicate with your application by calling it directly as opposed to waiting for you to make the request.

With webhooks, you'd open an endpoint on your application that the other API / service can send requests to so that you can process their requests. You can almost think of it as push notifications for web applications.

With payments the standard use case for webhooks is to handle subscription renewals. So a customer would sign up today and you'd now in response to your createSubscription call whether or not the subscription was created successfully, but how do you know whether or not the subscription renewed successfully? You could either just poll the payments API over and over again, or the payments API can send you a webhook event saying the subscription renewed and in your webhook handler logic you can handle what to do internally (like send a receipt, update some db fields, etc)

2
  • Thank you for your time and answer, I understand it now. One more question.. Should I store to my database if a payment was successfull after the a webhook contacts to a my server NOT inmediatly after the API tells me it was successfull? And what a webhook should have in the code (generally speaking), it should be able to identify the payment ID and data sent by the payment platform so I can save it to my database right? Again, thank you
    – Daniel
    Commented May 31, 2015 at 21:42
  • 1
    Normally, I prefer to do things synchronously, so if I know immediately whether or not the payment succeeded then I'd ignore that webhook and I'd only use webhooks for things that happen asynchronously. Webhooks normally include some sort of event id, the id of the affected object, some information about the event (payment failed vs payment succeeded, etc) Commented May 31, 2015 at 22:55
0

Imagine when you book a hotel room on a travel website. You select the check-in date and check-out date, the website calculates the price and you click on the pay button. Stripe takes care of the payment process.

Now since you booked a hotel room, the website has to save that booking details in their database to make sure that room is reserved for you on certain days so that someone else cannot try to book the same room on those days. Before the website reserves that room for you, it has to be sure that your payment process is successfully completed. Stripe uses webhooks to notify the website and actually, website is subscribed to listening for checkout.session.completed event by stripe. Once the website receives that notification then it will book your room.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.