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

Commit

Permalink
aaaaaand final name is AmazonFlexPay
Browse files Browse the repository at this point in the history
  • Loading branch information
cainlevy committed Mar 8, 2011
1 parent a975ca5 commit e36c561
Show file tree
Hide file tree
Showing 36 changed files with 163 additions and 163 deletions.
16 changes: 8 additions & 8 deletions README.rdoc
@@ -1,27 +1,27 @@
= RubyFPS
= AmazonFlexPay

Library for Amazon's Flexible Payment Service.

== CONFIGURE

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

RubyFPS.access_key = 'your access key'
RubyFPS.secret_key = 'your secret key'
RubyFPS.go_live! # if you're done with the sandbox
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 = RubyFPS.single_use_pipeline('mypipeline3292', :recipient_token => 'RTOKEN', :transaction_amount => '12.99')
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:

response = RubyFPS.pay('12.99', 'USD', 'STOKEN', 'myrequest3292')
response = AmazonFlexPay.pay('12.99', 'USD', 'STOKEN', 'myrequest3292')
if response.error?
flash[:error] = "Sorry, something went wrong."
response.errors.each do |error|
Expand All @@ -36,6 +36,6 @@ Note that while the examples are shown using Rails methods, the only Rails requi

== LEARN MORE

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

Copyright (c) 2011 Lance Ivy, released under the MIT license.
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -5,18 +5,18 @@ require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test

desc 'Test the RubyFPS plugin.'
desc 'Test the AmazonFlexPay plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the RubyFPS plugin.'
desc 'Generate documentation for the AmazonFlexPay plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'RubyFPS'
rdoc.title = 'AmazonFlexPay'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
Expand Down
8 changes: 4 additions & 4 deletions ruby_fps.gemspec → amazon_flex_pay.gemspec
@@ -1,12 +1,12 @@
$LOAD_PATH << File.dirname(__FILE__) + '/lib'
require 'ruby_fps'
require 'amazon_flex_pay'

Gem::Specification.new do |s|
s.name = 'ruby_fps'
s.version = RubyFPS::VERSION
s.name = 'amazon_flex_pay'
s.version = AmazonFlexPay::VERSION
s.authors = ['Lance Ivy']
s.email = 'lance@kickstarter.com'
s.homepage = 'http://github.com/kickstarter/ruby_fps'
s.homepage = 'http://github.com/kickstarter/amazon_flex_pay'
s.summary = 'API layer for Amazon FPS'
s.description = 'A straight-forward REST API for Amazon\'s Flexible Payments Services.'

Expand Down
16 changes: 8 additions & 8 deletions lib/ruby_fps.rb → lib/amazon_flex_pay.rb
Expand Up @@ -7,17 +7,17 @@
require 'multi_xml'
require 'active_support/core_ext/string/inflections' # camelcase, underscore

require 'ruby_fps/signing'
require 'ruby_fps/model'
require 'ruby_fps/data_types'
require 'ruby_fps/enumerations'
require 'amazon_flex_pay/signing'
require 'amazon_flex_pay/model'
require 'amazon_flex_pay/data_types'
require 'amazon_flex_pay/enumerations'

require 'ruby_fps/api'
require 'ruby_fps/pipelines'
require 'amazon_flex_pay/api'
require 'amazon_flex_pay/pipelines'

RestClient.log = 'stdout'

module RubyFPS
module AmazonFlexPay
VERSION = '0.9'
API_VERSION = '2010-08-28'
PIPELINE_VERSION = '2009-01-09'
Expand All @@ -44,7 +44,7 @@ def pipeline_endpoint

# By default all API calls and pipeline redirects are in the Amazon Payments sandbox.
#
# Call <tt>RubyFPS.go_live!</tt> to enable live transactions and real money in this environment.
# Call <tt>AmazonFlexPay.go_live!</tt> to enable live transactions and real money in this environment.
def go_live!
self.api_endpoint = 'https://fps.amazonaws.com/'
self.pipeline_endpoint = 'https://authorize.payments.amazon.com/cobranded-ui/actions/start'
Expand Down
8 changes: 4 additions & 4 deletions lib/ruby_fps/api.rb → lib/amazon_flex_pay/api.rb
@@ -1,8 +1,8 @@
# load all api classes
require 'ruby_fps/api/base'
Dir[File.dirname(__FILE__) + '/api/*'].each do |p| require "ruby_fps/api/#{File.basename(p)}" end
require 'amazon_flex_pay/api/base'
Dir[File.dirname(__FILE__) + '/api/*'].each do |p| require "amazon_flex_pay/api/#{File.basename(p)}" end

module RubyFPS
module AmazonFlexPay
class << self
# Cancels a transaction.
#
Expand Down Expand Up @@ -162,7 +162,7 @@ def verify_signature(url, params)
protected

def submit(action, *args) #:nodoc:
RubyFPS::API.const_get(action.to_s.camelcase).new(*args).submit
AmazonFlexPay::API.const_get(action.to_s.camelcase).new(*args).submit
end
end
end
16 changes: 8 additions & 8 deletions lib/ruby_fps/api/base.rb → lib/amazon_flex_pay/api/base.rb
@@ -1,14 +1,14 @@
module RubyFPS::API #:nodoc:
class Base < RubyFPS::Model
module AmazonFlexPay::API #:nodoc:
class Base < AmazonFlexPay::Model
# This compiles an API request object into a URL, sends it to Amazon, and processes
# the response.
def submit
begin
url = RubyFPS.api_endpoint + '?' + RubyFPS.query_string(self.to_params)
url = AmazonFlexPay.api_endpoint + '?' + AmazonFlexPay.query_string(self.to_params)
response = RestClient.get(url)
self.class::Response.from_xml(response.body)
rescue RestClient::BadRequest, RestClient::Unauthorized, RestClient::Forbidden => e
RubyFPS::API::ErrorResponse.from_xml(e.response.body)
AmazonFlexPay::API::ErrorResponse.from_xml(e.response.body)
end
end

Expand All @@ -21,19 +21,19 @@ def error?
def to_params
params = self.to_hash.merge(
'Action' => action_name,
'AWSAccessKeyId' => RubyFPS.access_key,
'Version' => RubyFPS::API_VERSION,
'AWSAccessKeyId' => AmazonFlexPay.access_key,
'Version' => AmazonFlexPay::API_VERSION,
'Timestamp' => format_value(Time.now)
)

params['SignatureVersion'] = 2
params['SignatureMethod'] = 'HmacSHA256'
params['Signature'] = RubyFPS.signature(RubyFPS.api_endpoint, params)
params['Signature'] = AmazonFlexPay.signature(AmazonFlexPay.api_endpoint, params)

params
end

class BaseResponse < RubyFPS::Model
class BaseResponse < AmazonFlexPay::Model
attribute :request_id

# Parses Amazon's XML response to REST requests and instantiates the response.
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class Cancel < Base #:nodoc:
attribute :transaction_id
attribute :description
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class CancelToken < Base #:nodoc:
attribute :token_id
attribute :reason_text
Expand Down
@@ -1,5 +1,5 @@
module RubyFPS::API #:nodoc:
class ErrorResponse < RubyFPS::Model #:nodoc:
module AmazonFlexPay::API #:nodoc:
class ErrorResponse < AmazonFlexPay::Model #:nodoc:
# Re-implements the XML parsing because ErrorResponse does not inherit from BaseResponse.
def self.from_xml(xml)
new(MultiXml.parse(xml)['Response'])
Expand All @@ -17,7 +17,7 @@ def errors=(val)
@errors = [val['Error']].flatten.map{|e| Error.new(e)}
end

class Error < RubyFPS::Model #:nodoc:
class Error < AmazonFlexPay::Model #:nodoc:
attribute :code
attribute :message
end
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetAccountActivity < Base #:nodoc:
attribute :start_date # required
attribute :end_date
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetAccountBalance < Base #:nodoc:

class Response < BaseResponse #:nodoc:
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetRecipientVerificationStatus < Base #:nodoc:
attribute :recipient_token_id

Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetTokenByCaller < Base #:nodoc:
attribute :token_id
attribute :caller_reference
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetTokenUsage < Base #:nodoc:
attribute :token_id

Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetTokens < Base #:nodoc:
attribute :caller_reference
attribute :token_status
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetTransaction < Base #:nodoc:
attribute :transaction_id

Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class GetTransactionStatus < Base #:nodoc:
attribute :transaction_id

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_fps/api/pay.rb → lib/amazon_flex_pay/api/pay.rb
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class Pay < Base #:nodoc:
attribute :caller_description
attribute :caller_reference # required
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class Refund < Base #:nodoc:
attribute :caller_description
attribute :caller_reference # required
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class Reserve < Base #:nodoc:
attribute :caller_description
attribute :caller_reference # required
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class Settle < Base #:nodoc:
attribute :reserve_transaction_id
attribute :transaction_amount, :type => :amount
Expand Down
@@ -1,4 +1,4 @@
module RubyFPS::API #:nodoc:
module AmazonFlexPay::API #:nodoc:
class VerifySignature < Base #:nodoc:
attribute :url_end_point
attribute :http_parameters
Expand Down
32 changes: 16 additions & 16 deletions lib/ruby_fps/data_types.rb → lib/amazon_flex_pay/data_types.rb
@@ -1,63 +1,63 @@
# Complex Data Types pulled from the documentation, with some obvious corrections.
#
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/ComplexDataTypes.html
module RubyFPS::DataTypes
module AmazonFlexPay::DataTypes
# moved from Enumerations
class AccountBalance < RubyFPS::Model #:nodoc:
class AccountBalance < AmazonFlexPay::Model #:nodoc:
attribute :available_balances, :type => :available_balances
attribute :pending_in_balance, :type => :amount
attribute :pending_out_balance, :type => :amount
attribute :total_balance, :type => :amount
end

class Amount < RubyFPS::Model #:nodoc:
class Amount < AmazonFlexPay::Model #:nodoc:
attribute :currency_code, :enumeration => :currency_code
attribute :value
end

class AvailableBalances < RubyFPS::Model #:nodoc:
class AvailableBalances < AmazonFlexPay::Model #:nodoc:
attribute :disburse_balance, :type => :amount
attribute :refund_balance, :type => :amount
end

class DebtBalance < RubyFPS::Model #:nodoc:
class DebtBalance < AmazonFlexPay::Model #:nodoc:
attribute :available_balance, :type => :amount
attribute :pending_out_balance, :type => :amount
end

class DescriptorPolicy < RubyFPS::Model #:nodoc:
class DescriptorPolicy < AmazonFlexPay::Model #:nodoc:
attribute :'CSOwner', :enumeration => :cs_owner
attribute :soft_descriptor_type, :enumeration => :soft_descriptor_type
end

class OutstandingDebtBalance < RubyFPS::Model #:nodoc:
class OutstandingDebtBalance < AmazonFlexPay::Model #:nodoc:
attribute :outstanding_balance, :type => :amount
attribute :pending_out_balance, :type => :amount
end

class OutstandingPrepaidLiability < RubyFPS::Model #:nodoc:
class OutstandingPrepaidLiability < AmazonFlexPay::Model #:nodoc:
attribute :outstanding_balance, :type => :amount
attribute :pending_in_balance, :type => :amount
end

class PrepaidBalance < RubyFPS::Model #:nodoc:
class PrepaidBalance < AmazonFlexPay::Model #:nodoc:
attribute :available_balance, :type => :amount
attribute :pending_in_balance, :type => :amount
end

class RelatedTransaction < RubyFPS::Model #:nodoc:
class RelatedTransaction < AmazonFlexPay::Model #:nodoc:
attribute :relation_type, :enumeration => :relation_type
attribute :transaction_id
end

class StatusHistory < RubyFPS::Model #:nodoc:
class StatusHistory < AmazonFlexPay::Model #:nodoc:
attribute :amount, :type => :amount
attribute :date
attribute :status_code
attribute :transaction_status, :enumeration => :transaction_status
end

class Token < RubyFPS::Model #:nodoc:
class Token < AmazonFlexPay::Model #:nodoc:
attribute :caller_reference
attribute :date_installed
attribute :friendly_name
Expand All @@ -68,15 +68,15 @@ class Token < RubyFPS::Model #:nodoc:
attribute :token_type, :enumeration => :token_type
end

class TokenUsageLimit < RubyFPS::Model #:nodoc:
class TokenUsageLimit < AmazonFlexPay::Model #:nodoc:
attribute :amount, :type => :amount
attribute :last_reset_amount, :type => :amount
attribute :count
attribute :last_reset_count
attribute :last_reset_timestamp
end

class Transaction < RubyFPS::Model #:nodoc:
class Transaction < AmazonFlexPay::Model #:nodoc:
attribute :balance, :type => :amount
attribute :caller_name
attribute :caller_transaction_date
Expand All @@ -98,7 +98,7 @@ class Transaction < RubyFPS::Model #:nodoc:
attribute :transaction_status, :enumeration => :transaction_status
end

class TransactionDetail < RubyFPS::Model #:nodoc:
class TransactionDetail < AmazonFlexPay::Model #:nodoc:
attribute :caller_name
attribute :caller_description
attribute :caller_reference
Expand Down Expand Up @@ -127,7 +127,7 @@ class TransactionDetail < RubyFPS::Model #:nodoc:
attribute :transaction_status, :enumeration => :transaction_status
end

class TransactionPart < RubyFPS::Model #:nodoc:
class TransactionPart < AmazonFlexPay::Model #:nodoc:
attribute :description
attribute :fees_paid, :type => :amount
attribute :instrument_id
Expand Down

0 comments on commit e36c561

Please sign in to comment.