Skip to content

Latest commit

 

History

History
87 lines (56 loc) · 3.42 KB

README.rdoc

File metadata and controls

87 lines (56 loc) · 3.42 KB

Flexpay - Just-above-the-metal API for Amazon FPS & Simple Pay

A (hopefully) simple implementation of Amazon’s FPS and Simple Pay API for dealing with pipelines, FPS requests, and a few simple pay features.

At this stage this should be considered beta though it’s going to production in the next week or so. If you want more information on how to use stuff take a look at the specs.

Amazon Simple Pay Advanced Guide: docs.amazonwebservices.com/AmazonSimplePay/2008-09-17/ASPAdvancedUserGuide/

Amazon FPS Advanced Guide (includes Cobranding): docs.amazonwebservices.com/AmazonFPS/2008-09-17/FPSAdvancedGuide/

Getting an API object

require 'flexpay'
api = Flexpay::API.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)

Recurring payments that are NOT subscriptions

api = Flexpay::API.new(:access_key => FPS_ACCESS_KEY, :secret_key => FPS_SECRET_KEY, :sandbox => true)
recurring_pipeline = api.get_recurring_pipeline
recurring_pipeline.callerReference = Time.now.to_i.to_s # Keep this somewhere
recurring_pipeline.transactionAmount = order.amount
recurring_pipeline.recurringPeriod = "#{order.interval_in_months} Month"
recurring_pipeline.returnURL = "http://yoursite.com/wherever/"

redirect_to recurring_pipeline.generate_url

Verifying Signatures from Amazon

require 'cgi'
api = Flexpay::API.new(:access_key => FPS_ACCESS_KEY, :secret_key => FPS_SECRET_KEY, :sandbox => true)

url = request.url.split('?')[0]
query = request.query_string

verify_signature = api.get_verify_signature
verify_signature.UrlEndPoint = url
verify_signature.HttpParameters = CGI::escape(query)

result = verify_signature.go!(false)

if result[:VerificationStatus] == "Success"
  #Victory
end

Actually getting paid

api = Flexpay::API.new(:access_key => FPS_ACCESS_KEY, :secret_key => FPS_SECRET_KEY, :sandbox => true)

pay = api.get_pay
pay.CallerReference = Time.now.to_i.to_s
pay.SenderTokenId = order.tokenID
pay.TransactionAmount_Value = order.amount
pay.TransactionAmount_CurrencyCode = "USD"
pay.AWSAccessKeyId = FPS_ACCESS_KEY
pay.Timestamp = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
pay.Version = "2008-09-17"

pay_response = pay.go!
# pay_response is a simple hash containing :TransactionId and :TransactionStatus

Handling subscriptions

subscription = Flexpay::API.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY).get_subscription_button

subscription.accessKey = ACCESS_KEY
subscription.amount = "USD 10"
subscription.description = "The thing your subscribing too"
subscription.recurringFrequency = "1 month"
subscription.returnURL = "http://localhost:3000"

redirect_to subscription.generate_url

For Developers

I tried to make this pretty simple and maintainable, hence the no-frills approach. All the Amazon APIs are internally namespaced using Amazon’s classifications and by their published version numbers so newer/older versions of the API can easily be added side-by-side. You can look at any of the current ones to see how it’s done since the same structure is used everywhere.

Updates are happily accepted with tests :-).

Meta

Written by Chris Chandler(chrischandler.name) of Flatterline(flatterline.com)

Released under the MIT License: www.opensource.org/licenses/mit-license.php

Main page: github.com/cchandler/flexpay

Issue tracking: flatterline.lighthouseapp.com/projects/49220-flexpay/overview