# Amazon Simple Pay Standard Readme

## About this Library

- Dynamic button generation helper for Amazon Simple Pay Standard using signature version 2.
- Sample Code Version 2.0
- Release Date : 2009-11-03

## Prerequisites

- You must have an Amazon Web Services developer account.click here
- You must have an Amazon Payments Sandbox Business Account.Click here
- You must use the same email address and password for your Amazon Payments Sandbox Business Account and your Amazon Web Services developer account.
- You must have PHP 5.2.10 or later installed
- If you want to use this sdk to generate buttons for Production environment then you need to create a Amazon Payments Buisness Account Click here

## Contents of sample codes:

This package contains the following files for helping you to generate Dynamic Buttons for Amazon Simple Pay Standard .

1. SignatureUtils.php - This class contains the following helper functions for calculating signature.

- signParameters - Takes a map of all the request parameters and returns base64 encoded signature. Takes additional parameters like httpMethod, (GET or POST), host (e.g. authorize.payments-sandbox.amazon.com) and requestURI (e.g. /pba/paypipeline) for signature version 2. The input map should contain signature version parameter depending on which it computes the signature.
- _calculateStringToSignV2 - Takes a map of all the request parameters along with httpMethod, hostName, requestURL and returns string-to-sign calculated using signature version 2.
- _sign - Takes string-to-sign, aws secret key and signature algorithm (HmacSHA256/HmacSHA1) as inputs and returns base64 encoded signature.

2. ButtonGenerator.php - Generate the html form

- getSimplePayStandardParams - Takes all the parameters passed by user as input and returns a Map of key-value pairs
- getSimplePayStandardForm - Takes a Map of key-value pair as input and returns the html form
- GenerateForm - This function takes all the parameters from user, call appropriate function to get signature and generate html form. It prints the html form on console.

3. StandardButtonSample.php - Sample file to show how to generate buttons using ButtonGenerator.php

- It has only main method which makes a call to ButtonGenerator::GenerateForm()with appropriate parameters.

## Steps to use this sample:

### How to Populate the input in StandardButtonSample.php

1. Sign into your Amazon Web Services developer account and retrieve your Access Key ID and Secret Access Key from here.
2. Replace the value of the accessKey constant in the code sample with your Access Key ID
3. Replace the value of the secretKey constant in the code sample with your Secret Access Key
4. Replace the values of the following parameters of the Button:
Required Parameters:

- amount - Enter the amount you want to collect for the item
- description - Enter a description of the item

Optional Parameters:

- referenceId - Optionally enter an ID that uniquely identifies this transaction for your records
- abandonUrl - Optionally, enter the URL where senders should be redirected if they cancel their transaction
- returnUrl - Optionally enter the URL where buyers should be redirected after they complete the transaction
- immediateReturn - Optionally, enter "1" if you want to skip the final status page in Amazon Payments
- processImmediate - Optionally, enter "1" if you want to settle the transaction immediately else "0". Default value is "1"
- ipnUrl - Optionally, type the URL of your host page to which Amazon Payments should send the IPN transaction information.
- collectShippingAddress - Optionally, enter "1" if you want Amazon Payments to return the buyer's shipping address as part of the transaction information

5. Set the environment to "sandbox" or "prod". (For testing use sandbox)
6. You can also set the SignatureMethod to either "HmacSHA256" and "HmacSHA1".

### How to compile and run the code

1. Run the code sample as a php application:

    $php StandardButtonSample.php

2. The code sample will output the HTML for the ' Amazon Simple Pay Standard' widget to the ConsoleYou can now integrate this code into your website.

Note:You cannot use your Amazon Payments Business Account as a buyer while testing your ' Amazon Simple Pay Standard' Widgets. You should create a new Amazon Payments Personal Account which you can use as a buyer.

## Examples

Examples