Photo by Mika Baumeister on Unsplash
Implementing Stripe workflow with golang and react
Prebuild checkout payment workflow
The Initial Situation
We didn't have SSL enabled on our server. We had an IP address of a digital ocean droplet where we've been continually deploying our projects for continuous development. We were in a hurry to show a working demo to our client. The working demo included an admin being able to create a product and a customer being able to buy the product using stripe for payment. A quick look on the stripe doc provides us with two different ways to implement stripe. One of the ways required the backend to be deployed on SSL enabled server. For testing, I could have used stripe CLI but that wasn't possible for the demo.
The Problem
I had no idea how to do connect a domain name with our IP, let alone enable SSL. So, I went the other way around and created a custom payment workflow that didn't require an SSL-enabled server. The demo went well, but the client was hoping for stripe hosted checkout form, and to be honest, I wasn't so happy about the custom payment workflow because it involved the frontend informing the backend about payment status.
What I did today
A new DevOps engineer joined our team yesterday. He quickly pointed the domain name to our server's IP and used Nginx as a reverse proxy to map all subdomains to their respective port and used cerbot to enable SSL. So with SSL enabled, I implemented the "prebuilt checkout form" workflow. All the steps were well documented on the stripe docs. Let me just point out the flow of the newly implemented payment flow:
Backend has a route exposed which will be used by stripe to send events of stripe transactions. This is basically a webhook.
- User clicks buy now button
- Frontend informs the backend
- Backend creates a checkout session and returns a stripe hosted checkout url
- Frontend redirects the user to that URL
- Stripe continuously sends events to the backend informing about all the status of payment
- Once payment is successful, backend commits that the product is bought
- User is redirected to a success URL.