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.

275750359_469571404855980_2792334719003541290_n.jpg

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.

  1. User clicks buy now button
  2. Frontend informs the backend
  3. Backend creates a checkout session and returns a stripe hosted checkout url
  4. Frontend redirects the user to that URL
  5. Stripe continuously sends events to the backend informing about all the status of payment
  6. Once payment is successful, backend commits that the product is bought
  7. User is redirected to a success URL.

275671604_754385308859800_5448255093974577246_n.jpg