How To Use The Amazon FPS API Provided in Typica?
October 28th, 2008 by jeje, posted in UncategorizedAs part of Elastic Grid effort to provide an Amazon FPS webapp console, we’ve contributed an Amazon FPS API into Typica. The rationale for this, is first that we really like Typica, and second that we do consider the Java API provided by Amazon to be poorly designed and to stick to much to the underlying SOAP/Query APIs.
What we (Elastic Grid team) were in need of is a better Java API, and especially one masking the underlying complexity of the FPS API. So, we designed it in such a way that for most usages, some defaults are assumed and don’t need to be given each time you make a call.
For example, most of the FPS calls do need a caller token (a token identifying the participant making the call to FPS). Why should you give this parameter each time you need to call FPS? Instead we choose an approach where you (as a developer) specify the defaults for the caller and recipient tokens.
If you are in need of using advanced FPS features, you’ll still be able to use the FPS support in Typica because we also provide alternative calls in which you specify all parameters.
With that being said, let’s move to a quick introduction on how to use FPS support from Typica. First of all, you need to checkout Typica from Subversion and build it (because the FPS support is not yet officially released).
First of all you need to initialize the FPS service by giving it at least the credentials and ideally the default tokens. You also need to specify the server URL and CBUI pipeline URL (if you want to use the Sandbox instead of the default production mode):
FlexiblePaymentsService fps = new FlexiblePaymentsService(awsCredentials.getAccessId(), awsCredentials.getSecretKey(), true, defaultCallerTokenID, defaultRecipientTokenID, defaultDescriptorPolicy, awsCredentials.getServerURL(), awsCredentials.getCBUI());
If you don’t have any default value for the tokens, then for all the other FPS calls, you’ll have to use the methods allowing you to specify the value at the time you make a call to the API. If you gave the default values, then you won’t have to give them anymore.
If you want to retreive the account activity, it’s actually really simple:
AccountActivity activity = fps.getAccountActivity(fromDate);
You also have other alternatives allowing you to select activity between two dates, filter by operation type, payment method, etc. The JavaDocs are you friend as we put as much comments as possible.
Now if you want to install a Single Use Token on your sender account, you simply need to do this:
String cbuiPipelineUrl = fps.acquireSingleUseToken("Reference of my order", new Amount(17.45, Amount.USD), "http://myserver/mycallback", "this is the reason why I'm asking for a payment");
After your sender go through the CBUI pipeline, he will have an installed token in his account, and the CBUI pipeline will redirect him to the above callback URL. At that point, you’re supposed to verify the AWS signature (in order to make sure it’s the CBUI pipeline making a call and not a hacker) and extract the relevant information from the URL parameters:
String singleUseToken = fps.extractSingleUseTokenFromCBUI(requestGlobals.getHTTPServletRequest());
When you are ready to effectively bill the user using this token, you simply need to do the following call:
Transaction txn = fps.pay(singleUseToken, new Amount(amount, Amount.USD), "Reference of my order");
Of course, you can bill up to the amount you asked for at the time the user went through the CBUI pipeline.
We hope this really quick overview will help you start using FPS.


Recent Comments