Payment Gateway Integration using Amazon Simple Pay Standard

Finding out a way to integrate Amazon Payment Gateway into the application needed lot of exploration. There is too much documentation available on AMAZON on this, but nowhere has it provided concrete guidelines to do this. I thought I would share my experience in achieving this for the community.

Creating an Amazon business Account.

To create an Amazon business account, the website should have a business name, contact information, credit card with US billing address.

https://payments-sandbox.amazon.com/sdui/sdui/index.htm

Click Create account on the top-right corner and continue with the procedure

You will have to use a Sandbox account while development so that you won’t use your real money

Creating an Amazon Developer Account.

Go to http://payments.amazon.com and click the Developer tab.

Click on Sign up for this Service

Then, on the next page showed up, click Sign Up

Creating the Configuration Keys

Sign in to https://payments-sandbox.amazon.com/sdui/sdui/index.htm

https://payments-sandbox.amazon.com/sdui/sdui/business/asp/standard#getting-started

Configure your Amazon Simple Pay Standard Button

 

 

Click on the Generate HTML Button

<form action=”https://authorize.payments-sandbox.amazon.com/pba/paypipeline” method=”post”>

  <input value=”1″ >

  <input value=”USD 10″ >

  <input value=”0″ >

  <input value=”qQrYG0ZOONZoEfMdGIYDiyyfuT7sRlKIbOvKduwni0Y=” >

  <input value=”0″ >

  <input value=”2″ >

  <input value=”HmacSHA256″ >

  <input value=”Items Purchased” >

  <input value=”FGDADFJKOCLR2Z75XNKN2K6N85KUNZ183JU9SM” >

  <input value=”11SEM03K88SD016FS1G2″ >

  <input value=”logo” >

  <input value=”1″ >

  <input src=”http://g-ecx.images-amazon.com/images/G/01/asp/beige_small_paynow_withmsg_whitebg.gif” border=”0″>

</form>

 

Please Note the “accessKey”, “signature”, “description”, “amazonPaymentsAccountId” and the action of the form and configure these as parameters in your configuration file.

Adding keys to the Configuration File

    <add key=”AccessKeyID” value=”11SEM03K88SD016FS1G2″/>

    <add key=”signature” value=”5cYOI8O6e01WyGgXq7nHT4JJam9hia51nD+H38B4H+Q=”/>

    <add key=”amazonPaymentsAccountId” value=”FGDADFJKOCLR2Z75XNKN2K6N85KUNZ183JU9SM”/>

    <add key=”description” value=”Candles Purchased”/>

    <add key=”AmazonPaymentUrl” value=”https://authorize.payments-sandbox.amazon.com/pba/paypipeline”/>

Wiring up the Shopping Cart

1)      Creating a class by name PaymentGatewayPost

public class PaymentGatewayPost

    {

        public System.Collections.Specialized.NameValueCollection ListParams = new System.Collections.Specialized.NameValueCollection();

        public string Url = “”;

        public string Method = “post”;

        public string FormName = “form1”;

 

        public void Add(string name, string value)

        {

            ListParams.Add(name, value);

        }

 

        public void Post()

        {

            System.Web.HttpContext.Current.Response.Clear();

            System.Web.HttpContext.Current.Response.Write(“<html><head>”);

            System.Web.HttpContext.Current.Response.Write(string.Format(“</head><body onload=”document.{0}.submit()”>”,FormName));

            System.Web.HttpContext.Current.Response.Write(string.Format(“<form name=”{0}” method=”{1}” action=”{2}” >”,FormName, Method, Url));

            int i = 0;

 

            while (i < ListParams.Keys.Count)

            {

                System.Web.HttpContext.Current.Response.Write(string.Format(“<input name=”{0}” type=”hidden” value=”{1}”>”,ListParams.Keys[i], ListParams[ListParams.Keys[i]]));

                i += 1;

            }

 

            System.Web.HttpContext.Current.Response.Write(“</form>”);

            System.Web.HttpContext.Current.Response.Write(“</body></html>”);

            System.Web.HttpContext.Current.Response.End();

        }

     }

 

2)      Create a method and attach this method to your check out functionality.

Check out http://docs.amazonwebservices.com/AmazonSimplePay/2008-09-17/ASPAdvancedUserGuide/ for the documentation of parameters.

     public void DoPayment(ShoppingCart order)

        {

           string amt = order.Amount ToString();

           Uri gatewayUrl = new Uri(GetConfigValue(“AmazonPaymentUrl”));

           PaymentGatewayPost post = new PaymentGatewayPost();

           post.FormName = “SimplePay”;

           post.Url = gatewayUrl.ToString();

           post.Method = “Post”;

           post.Add(“description”, GetConfigValue(“description”));

           post.Add(“immediateReturn”, “1”);

           post.Add(“signatureVersion”, “2”);

           post.Add(“signatureMethod”, “HmacSHA256”);

           post.Add(“accessKey”, GetConfigValue(“AccessKeyID”));

           post.Add(“referenceId”, order.ReceiptId);//

           post.Add(“signature”, GetConfigValue(“signature”));

           post.Add(“amazonPaymentsAccountId”, GetConfigValue(“amazonPaymentsAccountId”));

           post.Add(“amount”, order.CurrencyCode + ” ” + amt);//

          post.Add(“returnUrl”, GetConfigValue(“ThankYouUrl”) + “?PayType=Amazon”); //where to return after finishing with transaction

           post.Add(“processImmediate”, “1”); //0 will reserve the payment, 1 will process it immediatelly

           post.Add(“abandonUrl”, GetConfigValue(“CancelUrl”) + “?PayType=Amazon”); //same as return url

           post.Post(); //make the post

        }

3)       Reading the Response of the post on the return URL Page.

Check out for  http://docs.amazonwebservices.com/AmazonSimplePay/2008-09-17/ASPAdvancedUserGuide/ for the documentation of response parameters 

     if (Request.QueryString[“status”].Trim().Equals(“PS”) && !string.IsNullOrEmpty(Request.QueryString[“transactionId”].Trim()))

                    {

                        transactionId = Request.QueryString[“transactionId”];

                    }

Co-Branding the Amazon site.

Co-branding is the way you can provide your custom logo at the AMAZON site. This is the only way you can provide a user experience so that user feels that he is navigating in your website when integrating using this method.

 

https://payments-sandbox.amazon.com/sdui/sdui/managecobranding

Happy Coding!!!!

Posted in:

Leave a Reply