Amazon Flexible Payments System on Google App Engine

by radomir on October 18, 2010

Dom Derrien did a great job earlier this year publishing his patch for Amazon FPS on Google’s App Engine. However, his project did not go live with FPS so few bugs remained unnoticed. Today I pushed my fixes to the cloned project on the  GitHub project at http://github.com/radomirml/amazon-fps-gaej (If anyone is interested in what’s been changed, please check the project history.)

Beside fixing the library, I was free to make few more changes…

Bonus: Using the same FPS jar for production and Amazon’s Sandbox

Before using Amazon’s FPS library in your application, you need build a custom jar specify your Amazon AWS keys in the config.properties. The same configuration file also contains end-point URL’s to Amazon’s AWS and CBUI service. You can not change end-point URL’s during runtime so if you wanted to test your application with Amazon’s Sandbox, you would have to create a separate jar with URL’s to the Sandbox.

I did not like the idea of switching jar files as it appeared error-prone to me and did not fit with my release procedure for GAE application. So, I made few small changes to the FPS to support environment selection and here’s how to use it…

Creating FPS service

This does not differ much from the “regular” AmazonFPS service creation:

String accessKeyId = PropertyBundle.getProperty(PropertyKeys.AWS_ACCESS_KEY);
String secretAccessKey = PropertyBundle.getProperty(PropertyKeys.AWS_SECRET_KEY);

String serviceURL = PropertyBundle.getProperty(PropertyKeys.AWS_SERVICE_END_POINT);
if(!MyContextHolder.isProductionSite())
  serviceURL = PropertyBundle.getProperty(PropertyKeys.AWS_SERVICE_END_POINT_SANDBOX);

AmazonFPSConfig config = new AmazonFPSConfig();
config.setServiceURL(serviceURL);
AmazonFPS service = new AmazonFPSClient(accessKeyId, secretAccessKey, config);

Obviously, in lines 5-6 I check if my application is running on the production server and switch to the sandbox environment if it does not. (This is possible with the official FPS library too but I’ve added a new property key for convenience.)

Creating CBUI Pipeline

Unfortunately, Amazon did not support runtime change of CBUI URL so I added a method setUsingSandbox(boolean) to the AmazonFPSCBUIPipeline that will change URL accordingly. Example use:

AmazonFPSRecurringTokenPipeline pipeline = new AmazonFPSRecurringTokenPipeline(accessKey, secretKey);
if(!MyContextHolder.isProductionSite())
  pipeline.setUsingSandbox(true);
... set other mandatory and optional parameters...
String cbuiUrl = pipeline.getUrl();

This update to the FPS is already included in the above GitHub project.

Disclaimer: I’m not responsible for any issue that may be a result of my changes to the library. :-)

Using Java? Speed-up bug fixing and improve customer satisfaction using LogDigger to create detailed error reports and notifications for your web application

{ 2 comments… read them below or add one }

Dom Derrien October 19, 2010 at 1:41 pm

Hi Radomir,

“Two heads are better than one.” ;) Thanks for the updates. I’m going to merge your updates in my repository so other contributors can benefit from your hard work.

By putting the config.properties, is it possible you open the access to the file with your account keys? (public & secret). We surely don’t want a malicious 3rd party library to be able to look up the AmazonFPS keys…

Regards,
A+, Dom

radomir October 19, 2010 at 2:02 pm

Hi Dom, I agree there’s some small risk but I generally use proven (open source) libraries. :-)

Anyway, in the post I quoted an approach that Amazon has in its docs. However, I believe you’re not required to put your keys to the config.properties because both FPS service and CBUI pipeline implementations accept AWS keys, meaning you can store them in some other private property or class member.

Leave a Comment

Previous post:

Next post: