About the library
- Based on the 2010-08-28 API version.
Before you begin
Extract the contents of amazon-fps-2010-08-28-php5-library.zip to a
folder. The folder "amazon-fps-2010-08-28-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', '<Your aws access key>');
- define('AWS_SECRET_ACCESS_KEY', '<Your aws secret key>');
- Update the FPS/CBUI endpoints (only required for sandbox environment, for prodouction no changes are required)
- Open the CBUIPipeline.php file
- Change the following line if needed and save the file
- protected static $CBUI_URL = "https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start";
- 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
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.
Steps to get authrorization from buyer
- Setup an app server at your side to receive HTTP redirect from Cobranded UI.
- Get the authorization from the buyer
- Go to <ROOT>/src/Amazon/CBUI/Samples directory and open CBUISingleUsePipelineSample.php
- In function test, set the following fields
$pipeline = new Amazon_FPS_CBUISingleUsePipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
$pipeline->setMandatoryParameters("callerReferenceSingleUse",
"http://www.mysite.com/call_back.jsp", "5");
//optional parameters
$pipeline->addParameter("currencyCode", "USD");
$pipeline->addParameter("paymentReason", "HarryPotter 1-5 DVD set");
//SingleUse url
print "Sample CBUI url for SingleUse pipeline : " . $pipeline->getUrl() . "\n";
- Run this smaple and 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 Payments CBUI actually redirected the customer to the Return URL specified. We use server-side validation using VerifySignature API call. Click here for steps.
Steps to make a payment
- Open PaySample.php in <ROOT>/src/Amazon/FPS/Samples
- 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.
- Set SenderTokenId the same as the one returned by CBUI above
- Run php PaySample.php to make the pay API call. You should see the output similar to the following:
PayResponse
PayResult
TransactionId
13L1AFBDB54MM68LBL8UDPJTQOZNP1F3PTC
TransactionStatus
Pending
ResponseMetadata
RequestId
85b069ef-8b27-43e1-89cf-f1cfcb3a0e72:0
...
- Experiment with other samples, examine samples sources. When ready, add library project to your solution, and use it.
- If the response status is Pending, you can use GetTransactionStatus API to get latest transaction status
- Amazon Payments will post an IPN for this transaction to your ipn url registered with us. We use server-side validation using VerifySignature API call . Click here for steps.
Related resources
More about Amazon FPS
Documentation
Code samples
Contact us for technical issues
Comments, Questions or Feedback
If you have any comments, questions or feedback on the library, please start discussion here (Amazon FPS forum).