Skip to content
This repository has been archived by the owner on Feb 14, 2018. It is now read-only.

kickstarter/amazon_flex_pay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AmazonFlexPay

Library for Amazon’s Flexible Payment Service.

As of 2015, Amazon Flexible Payment Service has shut down and as a result this gem is no longer maintained.

INITIALIZE

Initialize the gem, probably in config/initializers/amazon_flex_pay.rb (for Rails):

AmazonFlexPay.access_key = 'your access key'
AmazonFlexPay.secret_key = 'your secret key'
AmazonFlexPay.go_live! if Rails.env.production?

CALL

AmazonFlexPay::Pipelines

Start here. You’ll need tokens for API calls. These are generated by users via parameterized pipelines.

Example

Construct a single-use pipeline for the user. This is where the user will agree to pay a certain amount to a specific recipient (maybe you?).

redirect_to AmazonFlexPay.single_use_pipeline(
  'mypipeline3292',
  'http://example.com/return',
  :recipient_token => 'RTOKEN',
  :transaction_amount => '12.99'
)

AmazonFlexPay::API

With tokens, you can make API calls. Note that results are asynchronous via IPNs. Payment and Refund examples are below. You can see all available API methods here.

Payment Example

Once you have a sender token, you can attempt to collect.

begin
  response = AmazonFlexPay.pay('12.99', 'USD', 'senderToken123')
  flash[:notice] = "Thanks! Your payment is processing."
rescue AmazonFlexPay::API::Error => 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

Refund Example

If you would like to give your last order a $10 refund, you can call the refund method like this:

order = Order.last

AmazonFlexPay.refund(
  order.transaction_id,
  order.id,
  caller_description: 'Friends and family discount.',
  refund_amount: { value: 10, currency_code: 'USD' },
)

Note: In this example, we are using the order id as the caller reference. You can pass any reference that you like. Also, the ‘caller_description’ and ‘refund_amount’ options are not required. The default refund amount is the original transaction amount.

Copyright © 2013 Kickstarter, released under the MIT license.

About

API for Amazon's Flexible Payments Service

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages