Integrate Amazon FPS single use payment token using PHP
Amazon Flexible Payments ServiceTM (Amazon FPS) is the first payments service designed from the ground up for developers. It is built on top of Amazon’s reliable and scalable payments infrastructure and provides developers with a convenient way to charge Amazon’s tens of millions of customers (with their permission, of course!). Amazon customers can pay using the same login credentials, shipping address and payment information they already have on file with Amazon. For more details about Amazon FPS , visit here.
There are different kind of payment tokens and each behaves differently. Differen types of payment tokens include ‘single use’ , ‘recurring-use’ , ‘multi-use’ , ‘pre-paid’, ‘post-paid’, ‘editing’. Since all these different types sounds new as far as payment type is concerned. You can find the detailed information of the each payment types , their request parameters and case – study of each payment type in the official website of amazon FPS .
Before you prepare for the request parameters you have to make sure that you have Amazon AWS account. It is required because you need to have the following security credentials in order to make your amazon FPS request successful.
- AWS Access Key ID—You use this to identify yourself when you send requests to the Co-Branded service .
- AWS Secret Access Key—You use this to generate URL signatures that provide tamper-proof requests.
Here I will go with the simple process of how to integrate single use Amazon FPS payment token using PHP . Its usage differs little to other payment types.
- Determine the request parameters that is required for your project. You can see it here.
- Make array of name of the parameter and assign corresponding value to it.
- Sort the array with respect to key (i.e ksort ($arrayName))
- Then concatenate all the key and value of array to make it one string.
- Get the signature of the string that has been just created using Developer access key and secret key and assign the result to the same array with key named as ‘signature’ . (There is fixed rule to obtain the signature ) .
- Eventually create the html form with array you have and send the parameters to this url ‘https://authorize.payments.amazon.com/cobranded-ui/actions/start’.
PHP Script to obtain the HTML form.
// this page is required to create the signature of the parameters. require_once( "config.php"); $config= new Config(); // url where Amazon FPS returns the success or error parameters as the transaction is made. $returnUrl = 'http://yoursite.com/returnUrl'; //generic parameters //Developer Access key $formHiddenInputs['callerKey'] = $config->AWSAccessKeyID; //chose payment type $formHiddenInputs['pipelineName'] = "SingleUse"; //returning url $formHiddenInputs['returnURL'] = $returnUrl; // optional , description of your website that is displayed in the payment site during the payment session . $formHiddenInputs['websiteDescription'] = $config->websiteDescription; // url of the image logo that is displayed at the amazon site during the payment period. $formHiddenInputs['cobrandingUrl'] = "http://www.yoursite.com/images/logo.jpg"; $formHiddenInputs['cobrandingStyle'] = "logo"; //specific parameters // to collect the email address of the client which is returned to the merchant website as the payment is made successful. $formHiddenInputs['collectEmailAddress'] = "True"; // merchant id or merchant token Note: please put your own merchant token here. $formHiddenInputs['recipientToken'] = "P2GNL9U2KLKLRZ3GA94NNMXQFRXURECI58KNDZXBT5BU1EP62HGINFAYZLI2WDY9"; // provide the payment reason . $formHiddenInputs['paymentReason'] = " this is my payment reason. "; //unique reference Id for this particular transaction . $formHiddenInputs['callerReference'] = "SenderToken-".rand(0,99999999).time(); // Total amount to be paid to the merhant. $formHiddenInputs['transactionAmount'] = 20.00; // sort the above array with the keys . ksort($formHiddenInputs); // create the array key and value to string. $stringToSign = ""; // loop the array to create a single string. foreach ($formHiddenInputs as $formHiddenInputName => $formHiddenInputValue) { $stringToSign .= $formHiddenInputName . $formHiddenInputValue; } //generic parameter // create the signature of the above string with the config class and Crypt_HMAC class. $formHiddenInputs['signature'] = $config->getSignature($stringToSign); // create the html form and required parameter from the above array to send the request $form = "<form action=\"https://authorize.payments.amazon.com/cobranded-ui/actions/start\" id =\"amazonForm\" method=\"post\">\n"; foreach ($formHiddenInputs as $formHiddenInputName => $formHiddenInputValue) { $form = $form . "<input type=\"hidden\" name=\"$formHiddenInputName\" value=\"$formHiddenInputValue\" >\n"; } $form = $form . "<input type=\"image\" src=\"https://payments.amazon.com/img/paynow_with_amazon_orange_large.gif\" border=\"0\" >\n"; $form = $form . "</form>\n"; echo $form;
Note: Access key and Secret key has been defined in the member variable of config class. Some request parameters I have used may not be necessary or some useful parameters might be missing which depends upon the transaction requirement. So please refer to all the request parameters available for the single use payment.


Thanks this is look good. However this has been very old and amazon have upgraded the version.
I am getting this error when used the code.
Caller Input Exception: The following input(s) are not well formed: [signatureVersion = null. This signature version is no longer supported. Please use signature version 2 to sign requests]
Regards
Shyam