Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to Digg

Understanding the Amazon Simple Pay Button Samples

Amazon provides four sample-specific buttons in five programming languages which show you how to create a specific button programmatically. In this section, we will briefly go over the essential details for the standard button, Java version only. The other samples differ only in the parameters that comprise them, and the programming language used for rendering them. For specific comprehensive information on a particular sample, see its ButtonGenerationWithSignature/README.html file.

For information on which parameters are specific to which buttons, please see Amazon Simple Pay Button Input Reference.

When you download a sample file, such as ASPStandard-JAVA-2.0, it contains three separate samples. This section describes the sample contained in the ButtonGenerationWithSignature folder.

Each button generator sample contains three primary components in the ASPStandard-JAVA-2.0/ButtonGenerationWithSignature/src folder. For the standard button, these are:

Class

Description

StandardButtonSample.java

This class contains the program entry point. It sets up initial parameter values for the standard button, and then calls the static method ButtonGenerator.GenerateForm with those values. You set the static parameter environment to either sandbox or prod, depending on which target you are building the button for.

ButtonGenerator.javaInvoked from StandardButton.java, this class generates the HTML form, by assembling the parameter values provided to the GenerateForm method. It adds other parameters required by the form, such as signatureMethod and signingVersion. In addition, it obtains a well-formed signature version 2 signature from the SignatureUtils.java class.
SignatureUtils.javaInvoked from ButtonGenerator.java, this class uses the signature version 2 process to create the string to sign and calculate the button-specific signature. It contains static methods to compile the string to sign, URL encode the string, and sign it.

In addition to these primary components, a sample may include other required resources. For example, the Java samples all include the lib/commons-codec/jars/commons-codec-1.3.jar file, which must be in your classpath in order to compile the sample.

To use the sample, do the following

Using the Standard Button Generator Sample

1

Set up your programming environment so that the program compiles without warnings or errors. For the Java sample, this includes ensuring that the ASPStandard-JAVA-2.0/ButtonGenerationWithSignature/src folder and the lib/commons-codec/jars/commons-codec-1.3.jar file are available to the compiler, either by including them as a command line option, or, if you build using an IDE, by including them as project resources.

2

The StandardButtonSample class declares public static variables which correspond to the fields required by the Amazon Simple Pay button. Modify these values to suit the button you want to build. These are the fields most likely to change if you are creating a number of buttons using the sample.

Set the StandardButtonSample.environment variable to sandbox now. After you have debugged your button, you can set it to prod in step 6, below.

[Note]Note

These are the minimal values you need to change. If you want to change the signature method, the cobranding style, or the button image, you can change the appropriate static variables in the ButtonGenerator class.

3

Compile the sample. For example, if you are including the lib/commons-codec/jars/commons-codec-1.3.jar as using the linux command line, you would type

$javac -cp .:lib/commons-codec/jars/commons-codec-1.3.jar StandardButtonSample.java SignatureUtils.java StandardButtonSample.java

On Windows, you would type

$javac -cp .;lib/commons-codec/jars/commons-codec-1.3.jar StandardButtonSample.java SignatureUtils.java StandardButtonSample.java
4

Run the sample. Continuing the previous example, on linux, you would type

$javac -cp .:lib/commons-codec/jars/commons-codec-1.3.jar StandardButtonSample

On Windows, you would type

$javac -cp .;lib/commons-codec/jars/commons-codec-1.3.jar StandardButtonSample

The complete signed button is printed to standard out.

5

When you are satisfied with the way the button works, you can change the StandardButtonSample.environment variable to prod, and rebuild a button ready for your production environment.