AmazonFlexPay

Library for Amazon’s Flexible Payment Service.

CONFIGURE

In config/initializers/amazon_flex_pay.rb, do the following:

AmazonFlexPay.access_key = 'your access key'
AmazonFlexPay.secret_key = 'your secret key'
AmazonFlexPay.go_live! # if you're done with the sandbox

EXAMPLES

Note that while the examples are shown using Rails methods, the only Rails requirement is ActiveSupport’s inflector.

  1. Construct a single-use pipeline for the user. This is where the user will agree to pay a certain amount to a specific recipient.

    pipeline = AmazonFlexPay.single_use_pipeline('mypipeline3292', :recipient_token => 'RTOKEN', :transaction_amount => '12.99')
    redirect_to pipeline.url('http://example.com/return')
    
  2. Then on the return page, take the sender token and run a Pay request:

    begin
      response = AmazonFlexPay.pay('12.99', 'USD', 'STOKEN', 'myrequest3292')
      flash[:notice] = "Thanks! Your payment is processing."
    rescue AmazonFlexPay::API::ErrorResponse => e
      flash[:error] = "Sorry, something went wrong."
      e.errors.each do |error|
        # notify yourself about error.code and error.message
      end
    end
    redirect_to product_path
    
  3. Then wait for a IPN to your registered listening URL and check that it’s successful.

LEARN MORE

All methods required for integrating API calls and Pipeline requests are found in the AmazonFlexPay module.

Copyright © 2012 Kickstarter, released under the MIT license.