About the library
- Based on the 2008-09-17 API version.
- Version 1.0.1
Before you begin
Extract the contents of amazon-fps-2008-09-17-php5-library.zip to a
folder. The folder "amazon-fps-2008-09-17-php5-library" will be created. This folder will be referred to as <ROOT> from this point onwards.
This folder should contain the following sub-directories:
- src — This folder contains the code files for the library and
sample API calls to Amazon FPS.
Prerequisites
Configuration
- Update the keys required to make the API call. This is one time activity and should be same for all APIs
- Goto <ROOT>/src/Amazon/FPS/Samples directory
- Open the .config.inc.php file
- Change the following two lines and save the file
- define('AWS_ACCESS_KEY_ID', '');
- define('AWS_SECRET_ACCESS_KEY', '');
- Update the FPS endpoint (only required for sandbox environment, for prodouction no changes are required)
- Open the CBUIUtils.php file
- Change the following line if needed and save the file
- private static $cbui_url = "https://authorize.payments-sandbox.amazon.com";
- Open the Client.php file
- Change the following line if needed and save the file
- private $_config = array ('ServiceURL' ='https://fps.sandbox.amazonaws.com')
Steps to make a payment
Description : Making a payment involves two parts. First, you obtain a payment authorization from buyers by redirecting them to co-branded pages hosted by Amazon FPS. When buyers return to your web site, you receive a payment authorization(also called a sender token) as part of the return URL. Second, you use this payment authorization or sender token in a 'Pay' API call to make a payment.
- Setup an app server at your side to receive HTTP redirect from Cobranded UI.
- Get the authorization from the buyer
- Go to Samples directory and open CBUISample.php
- In function getURLForSingleUseToken, set the corresponding fields
$obj = new Amazon_FPS_CBUIUtils(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY);
$obj->setMandatoryParams("SingleUse", "<Your Return URL>");
$obj->setCallerReference("<some unique id to identify the request>");
$obj->setTransactionAmount("<transaction amount>");
$obj->setPaymentReason("<payment reason>");
$qs = $obj->getURL();
....
//getURLForSingleUseToken();
- Uncomment the function call to getURLForSingleUseToken and run php CBUISample.php
- Copy the URL printed on console and paste it on your browser. You will be redirected to Amazon FPS CBUI
- Go through the pipeline. Make sure you use a different Amazon FPS account, while acting as buyer. At the end of the pipeline, you(buyer) will be redirected back to the return URL provided in the query string above.
- The return URL will include expiry, tokenID, status, callerReference and signature parameters. Please note that tokenID will be used in Pay later.
- Validate that Amazon FPS actually returned the URL
- Go to Samples directory and open CBUISample.php
- In function validateQueryString, set the corresponding fields
echo "validing the query string now\n";
$querystring = "< query string returned by CBUI >";
$obj = new Amazon_FPS_CBUIUtils(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY);
//Original signature received in response from Amazon FPS should be specified.
$signatureMatched=$obj->validateQueryString($querystring,urldecode("<signature parameter returned in the query string>"));
...
//validateQueryString();
- Uncomment the function call to validateQueryString and run php CBUISample.php
- Make sure the signature is valid
- Now we need to make the payment
- Open PaySample.php in <ROOT>/src/Amazon/FPS/Samples
- Set SenderTokenId the same as the one returned by CBUI above
- Replace the following line
// @TODO: set request. Action can be passed as Amazon_FPS_Model_PayRequest
with the code snippet below:
$request = new Amazon_FPS_Model_PayRequest();
$request->setSenderTokenId('A12345666666BCDEFFF');//set the proper senderToken here.
$amount = new Amazon_FPS_Model_Amount();
$amount->setCurrencyCode("USD");
$amount->setValue('1'); //set the transaction amount here;
$request->setTransactionAmount($amount);
$request->setCallerReference('CallerReference123456789'); //set the unique caller reference here.
- Run php PaySample.php to make the pay API call
- If the response status is Pending, you can use GetTransactionStatus API to get latest transaction status
Congratulations!! You made first call go through
Trouble shooting
- The signature received in response doesn't match.
- Make sure you pass the URL decoded signature to Amazon_FPS_CBUIUtils->validateQueryString() method.
- Fatal error: require_once(): Failed opening required 'Crypt/HMAC.php'
- Download Crypt/HMAC from here
- Include it in your package.
Related resources
Amazon Flexible Payments Service
Resources