Step 2: Making a Pay Request and Handling the Response

Topics

This section explains how to make a Pay request, which uses the senderTokenId you received in the Co-Branded service response. The Pay request initiates the Amazon FPS transfer of money from the sender's payment instrument to the recipient's Amazon Payments account.

The sample code presented in this section shows how to send a Pay request. The following table shows the specific file in each SDK that contains that code. Each file also includes code to handle the response. For the location of the SDK downloads, see Getting an Amazon FPS SDK. The <Sample_App_Root> is the folder where you have extracted the SDK.

[Tip]Tip

The ReadMe file in each SDK gives step-by-step instructions on how to get set up and initiate a payment.

API Name

Language

Location

Pay

Java

Filename: <Sample_App_Root>\src\com\amazonaws\fps\samples\PaySample.java

C#

Filename: <Sample_App_Root>\src\Amazon.FPS.Samples\Amazon.FPS.Samples\PaySample.cs

PHP

Filename: <Sample_App_Root>\src\Amazon\FPS\Samples\PaySample.php

[Tip]Tip

You can hide the sections of this guide that don't apply to the programming language you are using. There is a language selection menu in the upper-right corner of pages with language-specific text. Select your language to hide all others, or select All to show the examples in all available languages.

Turning on language filter

Constructing a Pay Request

The following code snippet makes a Pay request to Amazon FPS. For code to handle the response, see the file listed in the preceding table.

Java

PayRequest request = new PayRequest();

/* Setting input parameters */

// senderTokenID is obtained from the Co-Branded service's return URL
request.setSenderTokenId(senderTokenID);

Amount amount = new Amount();
amount.setCurrencyCode(CurrencyCode.USD);
amount.setValue("1"); //set the transaction amount here
request.setTransactionAmount(amount);

request.setCallerReference(<unique caller reference>);


// Make a Pay call
AmazonFPS service = new AmazonFPSClient(accessKeyId, secretAccessKey);
PaySample.invokePay(service, request);

C#

PayRequest request = new PayRequest();
				
/* Setting input parameters */

// senderTokenID is obtained from the Co-Branded service's return URL
request.SenderTokenId = senderTokenID;
request.CallerReference = <unique caller reference>;
	
Amount amount = new Amount();
amount.CurrencyCode = CurrencyCode.USD;
amount.Value = "1"; // set the transaction amount here
request.TransactionAmount = amount;


// Make a Pay call
AmazonFPS service = new AmazonFPSClient(accessKeyId, secretAccessKey);
PaySample.InvokePay(service, request);

PHP

$request =  new Amazon_FPS_Model_PayRequest();
				
/* Setting input parameters */

// $senderTokenID is obtained from the Co-Branded service's return URL
$request->setSenderTokenId($senderTokenID);

$amount = new Amazon_FPS_Model_Amount();
$amount->setCurrencyCode("USD");
$amount->setValue('1'); //set the transaction amount here;
$request->setTransactionAmount($amount);
$request->setCallerReference(<unique caller reference>); 


// Make a Pay call
$service = new Amazon_FPS_Client(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
invokePay($service, $request);

Resending a Request

Your Pay request or the response from Amazon FPS might not reach its destination due to underlying network failures. If this happens, you can resend the same request within 7 days, and Amazon FPS returns the result of the previous request. Amazon FPS doesn't execute a new transaction.

[Important]Important

All the parameters in the request you resend should have exactly the same parameters and values (inclusive of date and time) that were in the initial request. Any change in the request will result in Amazon FPS returning an error or processing this request as a new transaction.

Sample Response

When you send the request, you receive a response similar to the following.

<PayResponse xmlns="http://fps.amazonaws.com/doc/2008-09-17/">
    <PayResult>
        <TransactionId>13N8UPFET32I4I7FCF9T4ZKFETETINTK56Q</TransactionId>
        <TransactionStatus>Pending</TransactionStatus>
    </PayResult>
    <ResponseMetadata>
        <RequestId>b415f09d-5924-4315-b31a-21c977c85c39:0</RequestId>
    </ResponseMetadata>
</PayResponse>
  • Line 3 is the transaction ID for this transaction.

  • Line 4 is the status of the payment transaction.

  • Line 7 is the request ID of the Pay action request.

You should store the transaction ID and request ID in your database and cross-reference them to the caller reference value you provided in the Pay request.