Amazon Flexible Payments Service
Basic Quick Start (API Version 2010-08-28)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Did this page help you?  Yes | No |  Tell us about it...

Understanding the Amazon CBUI Samples

Amazon provides five samples in four programming languages (C#, Java, Perl, and PHP) which show you how to build Co-Branded User Interface request URLs.

When you download a sample file, such as amazon-fps-2008-09-17-java-library, the [package root]/src/com/amazonaws/cbui/samples folder contains sample classes showing how to generate pipeline-specific CBUI URLs from your code ([package root] is the location you extracted your sample package).

Each sample describes its requirements in its Readme.html file, located at the package root. Typically, the entire library structure must be available to the compiler. For example, the amazon-fps-2008-09-17-php-library.zip file contains the src/Amazon/CBUI and folders which the files in src/Amazon/CBUI/Samples require.

In addition to these primary components, a sample may include other required resources. For example, the Java samples all include numerous jar files in the [package-root]/third-party folder, which must also be in your classpath in order to compile the sample.

For each sample, you must set your security credentials and Amazon FPS sandbox endpoints in a library-dependant way. For example, to use the C# library, you set your security credentials in the [package-root]/src/Amazon.FPS.Samples/Amazon.FPS.Samples/AmazonFPSSamples.cs file, while for the perl library you set them in the individual [package-root]/src/Amazon/CBUI/Samples/*.pl file you are working with.

The following samples are provided with each sample library:

Class

Description

CBUI Single Use Pipeline Sample

Requests authorization for a one-time payment.

CBUI Multi-Use Pipeline Sample

Requests authorization for multiple payments.

CBUI Recipient Pipeline Sample

Requests authorization for a recipient token pipeline, such as that needed for marketplace fixed and variable fees.

CBUI Recurring Token Pipeline Sample

Requests authorization for a recurring token pipeline, such as that needed for periodic charges.

CBUI Edit Token Pipeline Sample

Requests authorization for an edit-token pipeline.

In the following section, we show how to work with the CBUI Single Use Pipeline sample using the Java library. This sample enables you to set up a single-use token for a one-time payment. You will find that the basic process you use for the CBUI Single Use Pipeline sample is the same for all the other samples in the CBUI/Samples (or, in the case of Amazon.CBUI.Samples) folder. (The process for the FPS and Return URL/IPN Validations samples are different. For more information, see Understanding the Amazon FPS Samples.)

Java

This section describes the Java version of the CBUISingleUsePipeline. The files for the C#, Perl, and PHP CBUISingleUsePipeline samples are listed in Locations of the CBUISingleUsePipeline Files in Other Libraries

The CBUISingleUsePipeline sample centers on the following files:

File

Description

config.properties

Set your AWS access key ID, AWS secret key, and sandbox endpoint in this file.

Important

Your Secret Access Key is a secret, which only you and Amazon should know. It is important to keep it confidential to protect your account. Store it securely. Never include it in your requests to the Amazon Flexible Payments Service (Amazon FPS), and never email it to anyone. Do not share it outside your organization, even if an inquiry appears to come from Amazon Web Services (AWS) or Amazon.com. No one who legitimately represents Amazon will ever ask you for your Secret Access Key.

CBUISingleUsePipelineSample.javaIn the main method, you create an AmazonFPSSingleUsePipeline object and use it to add parameters specific to your application.
AmazonFPSSingleUsePipeline.javaInvoked from CBUISingleUsePipelineSample.java, this class contains the setMandatoryParameters and validateParameters functions which you can customize for your application.

Co-Branded service request with Java SDK Sample

1

Open the file [package-root]/src/config.properties, and set AwsAccessKey and AwsSecretKey properties to your AWS access key and AWS secret key, respectively.

Important

Your Secret Access Key is a secret, which only you and Amazon should know. It is important to keep it confidential to protect your account. Store it securely. Never include it in your requests to the Amazon Flexible Payments Service (Amazon FPS), and never email it to anyone. Do not share it outside your organization, even if an inquiry appears to come from Amazon Web Services (AWS) or Amazon.com. No one who legitimately represents Amazon will ever ask you for your Secret Access Key.

To get your security credentials, see Getting an AWS Account in the Amazon Flexible Payments Service Getting Started Guide.

2

In the same file, set the AwsServiceEndPoint to https://fps.sandbox.amazonaws.com/ (the Amazon FPS sandbox).

3

In the same file, set the CBUIServiceEndPoint to https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start (the Co-Branded service sandbox).

4

Open the file [package-root]/src/com/amazonaws/cbui/ samples/CBUISingleUsePipelineSample.java, and find the following line:

AmazonFPSSingleUsePipeline pipeline= new AmazonFPSSingleUsePipeline(accessKey, secretKey);

Change the pipeline.setMandatoryParameters and pipeline.addParameters method calls to the following:

//pipeline name, your return URL, and the amount
pipeline.setMandatoryParameters("callerReferenceSingleUse", 
"[your returnUrl]", "5"); 

//optional parameters
pipeline.addParameter("currencyCode", "USD");
pipeline.addParameter("paymentReason", "Now and Forever - Richard Mark");
pipeline.addParameter("paymentMethod", "ABT,ACH,CC">;
pipeline.addParameter("callerReference", "[Unique ID for the transaction]");

Save the file.

5

Ensure that all the jar files in the third-party folder and sub folders are in your java CLASSPATH.

6

Compile and run the sample. The Co-branded authorization page is printed to standard out.

7

Using a web browser, navigate to the URL produced by the sample. Because the sender and recipient cannot be the same, you must use an account different from your AWS developer or business accounts.

8

When complete, the page you specified as [your returnUrl] is hit with the Co-Branded service response. You validate this response by testing the signature.


You can customize the sample by modifying the file [package-root]/src/com/amazonaws/cbui/AmazonFPSSingleUsePipeline.java. The setMandatoryParameters only requires callerReference, returnUrl, and transactionAmount. If you want to make more parameters mandatory, modify this method.

In the same file, the validateParameters function ensures that the transactionAmount parameter is present. You can add custom validation checks to this method.