My First open-source Project: Building AmazonPay Gem
Recently at my workplace, I was assigned the task to implement the new Amazon Pay checkout v2 in our e-commerce application. A little bit of context, we currently use Ruby on Rails on the backend and use React for our frontend. We combine the application with a mix of server-side rendering and Single Page Application.
Amazon Payment Flow
For an e-commerce site using Amazon Pay Checkout v2, the following is the checkout and payment flow:
- Prepare the Payload
- Send the payload to the server and get a signature by signing the payload
- Send the signature and the string version of the payload to your frontend application
- Use the payload and the signature to render an Amazon Pay button
- A user clicks on the rendered Amazon Pay button
- S/He is taken to the Amazon website where the person logs in
- S/He payment method and shipping address if that is required
- Amazon returns to a review URL supplied by the user along with a URL parameter that contains the unique session ID
- Send the session ID to the server
- Retrieve details of the session using the session ID
- Update the checkout session if necessary
- Return the checkout session data to your frontend and display a review page where the user has the option of changing payment method and ship address
- Attached the amazon pay redirect URL returned from the session to a checkout button
- User presses the checkout button and is taken back to amazon website where the payment is processed
- Amazon calls the user return result URL with the same amazon checkout session parameter
- Send the session ID to the server and then call the SDK complete session method that allow amazon to complete the payment
- Display customary thank you page.
Amazon currently offers SDKs for PHP, .NET, Java and Node.js. For those of us that implemented our server in Ruby, we are up the creek without a paddle. You would have to go through a relatively complicated process to get every request authenticated.
To make it easy for everyone to use AmazonPay in their Ruby application, I have created the Amazon Pay Ruby SDK. This makes it as easy to implement Amazon Pay in ruby as it currently is in Node.js, or PHP, or .Net.
The SDK is mostly based off of the node.js SDK so it is as safe and secure as the Nodejs SDK is.
The SDK is currently published in the RubyGem repository at Amazon Pay Ruby Gem.
The codebase is at AmazonPay Ruby SDK.
I will try to ensure this Gem keeps in concert with any Amazon changes to the Nodejs SDK within at least a week.
I, however, welcome contributions and help maintaining the project.
I hope this gem serves the community as well as every open source project have ever used served me.