Salesforce and Amazon Pay Integration

October 20, 2017 Appirio

By Rashmi Chauhan

Amazon Pay provides a convenient way to pay for purchases online. Integrating Amazon Pay with Salesforce Commerce Cloud provides the following advantages:

1. Eases the payment process directly from the SFDC community.
2. Aids sellers in exchanging/tracking data programmatically on orders and payments.
3. Allows sellers to build applications for their own Amazon seller account. (By simply choosing a payment method from the Visualforce (VF) page using the Amazon Pay button.)

We can add this integration on a VF page and handle it in the backend controller, using the Amazon Marketplace Web Service (Amazon MWS) API to complete the purchase. Amazon MWS is an integrated web service API that helps Amazon sellers programmatically exchange data on listings, orders, payments, reports, and more. With Amazon MWS, you can build applications for your own Amazon seller account. We simply need to choose a payment method from the VF page using the Amazon Pay button.

Steps to register as a developer

Create a new account to render the Amazon Pay button on the VF page and API integration. Once the registration process is completed, credentials for Seller ID (Merchant ID), AWS Access Key ID, Secret Key, and client ID will be received.

Custom integration for Visualforce page

Follow these steps to add an Amazon Pay button to your website:

Step 1. Add the Amazon Pay JavaScript reference.
To render the Amazon Pay button, add the following reference to your VF page:

widgetScriptUrl =
merchantId =  Your seller or merchant identifier.

Step 2. Specify the parameter values.

siteDomain= your website url.
clientId=clientId of seller account.

Step 3. Build and create an Amazon Pay button.

Custom integration for Controller class

We are using Amazon MWS to make API payment requests like authorize or refund. All the transactions made by these APIs are shown under Orders > Manage Transaction tab in your seller account.

Step 1. Create a Canonicalized Query String.

To create an Amazon MWS query request, you must first construct a query string with the query information.

Required parameters:

— AWSAccessKeyId: Your Amazon MWS account is identified by your access key ID, which Amazon           MWS uses to look up your Secret Access Key.
Action: The action you want to perform on the endpoint, such as “GetOrderReferenceDetails”
— SellerId: Your seller or merchant identifier.
— SignatureMethod: The HMAC hash algorithm is used to calculate your signature. Both                               HmacSHA256 and HmacSHA1 support hash algorithms; here the value used is HmacSHA256.
— SignatureVersion: This is the signature version being used. Here, the value is 2.
— Timestamp: System’s current DateTime in GMT format.
— Version: The version of the API section, which is ‘2013-01-01’ here.

Prerequisites for the query string to be signed:

a) urlEncode method: URL encode the parameter name and values.
b) calculateFormattedParam method: Sort the UTF-8 query string components by parameter name and separate the name-value pairs with an ampersand ( & ).
c) calculateParamForSignature method: Use the return String for creating final string for signature.

Step 2. Sign the query request.

The request signature is a part of the authentication process for identifying and verifying the sender. It is used as the value for signature parameter in the request URL constructed here:

– dataValue: string returned from step 1.
secretKey: your Secret Access Key of amazon central seller account.

Step 3. Make the http request.

Response format:
In response to an HTTP request, Amazon MWS returns an XML file that contains the result of the request. You can also check the response of any request using scratchpad.

Now you can login and pay using the Amazon Pay Integration in Salesforce. We can implement login and authorization of user using their Amazon credential via the Visualforce page, and process their orders using different Amazon API calls in controller.

Previous Article
Using IoT Explorer to Power Your Digital Transformation Projects
Using IoT Explorer to Power Your Digital Transformation Projects

Next Article
Reflecting on Appirio’s Summer ‘17 Salesforce Technical Architect Summit
Reflecting on Appirio’s Summer ‘17 Salesforce Technical Architect Summit

  This summer’s summit was amazing. It’s certainly invigorating to be surrounded by 30 of our top Salesforc...