Giter Club home page Giter Club logo

flexpay's Introduction

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

flexpay's People

Contributors

cchandler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

flexpay's Issues

NoMethodError

Hi,
I am relatively new to RoR, but when I tried to include the flexpay gem I get this error:

/usr/lib/ruby/gems/1.8/gems/flexpay-0.2.1/lib/flexpay/api_module.rb:5:in included': private methodclass_variable_set' called for Flexpay::CobrandingAPI::V2009_01_09:Module (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/flexpay-0.2.1/lib/flexpay/api_module.rb:4:in class_eval' from /usr/lib/ruby/gems/1.8/gems/flexpay-0.2.1/lib/flexpay/api_module.rb:4:inincluded'
from /usr/lib/ruby/gems/1.8/gems/flexpay-0.2.1/lib/flexpay/cobranding_api/v2009_01_09.rb:4:in include' from /usr/lib/ruby/gems/1.8/gems/flexpay-0.2.1/lib/flexpay/cobranding_api/v2009_01_09.rb:4 from /usr/lib/ruby/gems/1.8/gems/flexpay-0.2.1/lib/flexpay.rb:12:inrequire'
from /usr/lib/ruby/gems/1.8/gems/flexpay-0.2.1/lib/flexpay.rb:12
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in require' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:inrequire'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in each' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:inrequire'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in each' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:inrequire'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in require' from /home/jemburula/Aptana Studio 3 Workspace/money_test/config/application.rb:7 from /home/jemburula/.gem/ruby/1.8/gems/railties-3.0.3/lib/rails/commands.rb:15:inrequire'
from /home/jemburula/.gem/ruby/1.8/gems/railties-3.0.3/lib/rails/commands.rb:15
from script/rails:6:in `require'
from script/rails:6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.