amazon_flex_pay 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +23 -0
- data/lib/amazon_flex_pay/api/base.rb +86 -0
- data/lib/amazon_flex_pay/api/cancel.rb +11 -0
- data/lib/amazon_flex_pay/api/cancel_token.rb +9 -0
- data/lib/amazon_flex_pay/api/get_account_activity.rb +21 -0
- data/lib/amazon_flex_pay/api/get_account_balance.rb +8 -0
- data/lib/amazon_flex_pay/api/get_recipient_verification_status.rb +9 -0
- data/lib/amazon_flex_pay/api/get_token_by_caller.rb +10 -0
- data/lib/amazon_flex_pay/api/get_token_usage.rb +9 -0
- data/lib/amazon_flex_pay/api/get_tokens.rb +13 -0
- data/lib/amazon_flex_pay/api/get_transaction.rb +9 -0
- data/lib/amazon_flex_pay/api/get_transaction_status.rb +13 -0
- data/lib/amazon_flex_pay/api/pay.rb +20 -0
- data/lib/amazon_flex_pay/api/refund.rb +14 -0
- data/lib/amazon_flex_pay/api/reserve.rb +20 -0
- data/lib/amazon_flex_pay/api/settle.rb +11 -0
- data/lib/amazon_flex_pay/api/verify_signature.rb +14 -0
- data/lib/amazon_flex_pay/api.rb +162 -0
- data/lib/amazon_flex_pay/data_types.rb +138 -0
- data/lib/amazon_flex_pay/enumerations.rb +23 -0
- data/lib/amazon_flex_pay/model.rb +130 -0
- data/lib/amazon_flex_pay/pipelines/base.rb +40 -0
- data/lib/amazon_flex_pay/pipelines/edit_token.rb +6 -0
- data/lib/amazon_flex_pay/pipelines/multi_use.rb +28 -0
- data/lib/amazon_flex_pay/pipelines/recipient.rb +10 -0
- data/lib/amazon_flex_pay/pipelines/single_use.rb +24 -0
- data/lib/amazon_flex_pay/pipelines.rb +41 -0
- data/lib/amazon_flex_pay/signing.rb +42 -0
- data/lib/amazon_flex_pay.rb +53 -0
- data/test/amazon_flex_pay_test.rb +117 -0
- data/test/api_test.rb +310 -0
- data/test/pipelines_test.rb +46 -0
- data/test/response_samples.rb +588 -0
- data/test/test_helper.rb +22 -0
- metadata +167 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Lance Ivy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= AmazonFlexPay
|
2
|
+
|
3
|
+
Library for Amazon's Flexible Payment Service.
|
4
|
+
|
5
|
+
== CONFIGURE
|
6
|
+
|
7
|
+
In config/initializers/amazon_flex_pay.rb, do the following:
|
8
|
+
|
9
|
+
AmazonFlexPay.access_key = 'your access key'
|
10
|
+
AmazonFlexPay.secret_key = 'your secret key'
|
11
|
+
AmazonFlexPay.go_live! # if you're done with the sandbox
|
12
|
+
|
13
|
+
== EXAMPLES
|
14
|
+
|
15
|
+
Note that while the examples are shown using Rails methods, the only Rails requirement is ActiveSupport's inflector.
|
16
|
+
|
17
|
+
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.
|
18
|
+
|
19
|
+
pipeline = AmazonFlexPay.single_use_pipeline('mypipeline3292', :recipient_token => 'RTOKEN', :transaction_amount => '12.99')
|
20
|
+
redirect_to pipeline.url('http://example.com/return')
|
21
|
+
|
22
|
+
2. Then on the return page, take the sender token and run a Pay request:
|
23
|
+
|
24
|
+
response = AmazonFlexPay.pay('12.99', 'USD', 'STOKEN', 'myrequest3292')
|
25
|
+
if response.error?
|
26
|
+
flash[:error] = "Sorry, something went wrong."
|
27
|
+
response.errors.each do |error|
|
28
|
+
# notify yourself about error.code and error.message
|
29
|
+
end
|
30
|
+
else
|
31
|
+
flash[:notice] = "Thanks! Your payment is processing."
|
32
|
+
end
|
33
|
+
redirect_to product_path
|
34
|
+
|
35
|
+
3. Then wait for a IPN to your registered listening URL and check that it's successful.
|
36
|
+
|
37
|
+
== LEARN MORE
|
38
|
+
|
39
|
+
All methods required for integrating API calls and Pipeline requests are found in the AmazonFlexPay module.
|
40
|
+
|
41
|
+
Copyright (c) 2011 Lance Ivy, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the AmazonFlexPay plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the AmazonFlexPay plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'AmazonFlexPay'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README.rdoc')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class Base < AmazonFlexPay::Model
|
3
|
+
# This compiles an API request object into a URL, sends it to Amazon, and processes
|
4
|
+
# the response.
|
5
|
+
def submit
|
6
|
+
url = AmazonFlexPay.api_endpoint + '?' + AmazonFlexPay.query_string(self.to_params)
|
7
|
+
response = begin
|
8
|
+
self.class::Response.from_xml(RestClient.get(url).body)
|
9
|
+
rescue RestClient::BadRequest, RestClient::Unauthorized, RestClient::Forbidden => e
|
10
|
+
ErrorResponse.from_xml(e.response.body)
|
11
|
+
end
|
12
|
+
response.request = self
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
# Converts the API request object into parameters and signs them.
|
17
|
+
def to_params
|
18
|
+
params = self.to_hash.merge(
|
19
|
+
'Action' => action_name,
|
20
|
+
'AWSAccessKeyId' => AmazonFlexPay.access_key,
|
21
|
+
'Version' => AmazonFlexPay::API_VERSION,
|
22
|
+
'Timestamp' => format_value(Time.now)
|
23
|
+
)
|
24
|
+
|
25
|
+
params['SignatureVersion'] = 2
|
26
|
+
params['SignatureMethod'] = 'HmacSHA256'
|
27
|
+
params['Signature'] = AmazonFlexPay.signature(AmazonFlexPay.api_endpoint, params)
|
28
|
+
|
29
|
+
params
|
30
|
+
end
|
31
|
+
|
32
|
+
class BaseResponse < AmazonFlexPay::Model
|
33
|
+
attribute :request
|
34
|
+
attribute :request_id
|
35
|
+
|
36
|
+
# Check response.error? to determine whether it's an ErrorResponse or not.
|
37
|
+
def error?
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
# Parses Amazon's XML response to REST requests and instantiates the response.
|
42
|
+
def self.from_xml(xml)
|
43
|
+
response = MultiXml.parse(xml)
|
44
|
+
|
45
|
+
response_key = response.keys.find{|k| k.match(/Response$/)}
|
46
|
+
hash = response[response_key]['ResponseMetadata']
|
47
|
+
|
48
|
+
result_key = response[response_key].keys.find{|k| k.match(/Result$/)}
|
49
|
+
hash.merge!(response[response_key][result_key]) if response[response_key][result_key] # not all APIs have a result object
|
50
|
+
|
51
|
+
new(hash)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class ErrorResponse < AmazonFlexPay::Model #:nodoc:
|
56
|
+
# Re-implements the XML parsing because ErrorResponse does not inherit from BaseResponse.
|
57
|
+
def self.from_xml(xml)
|
58
|
+
new(MultiXml.parse(xml)['Response'])
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check response.error? to determine whether Amazon accepted the request.
|
62
|
+
def error?
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
attribute :request
|
67
|
+
attribute :request_id
|
68
|
+
|
69
|
+
attr_reader :errors
|
70
|
+
def errors=(val)
|
71
|
+
@errors = [val['Error']].flatten.map{|e| Error.new(e)}
|
72
|
+
end
|
73
|
+
|
74
|
+
class Error < AmazonFlexPay::Model #:nodoc:
|
75
|
+
attribute :code
|
76
|
+
attribute :message
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
|
82
|
+
def action_name #:nodoc:
|
83
|
+
self.class.to_s.split('::').last
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class Cancel < Base #:nodoc:
|
3
|
+
attribute :transaction_id
|
4
|
+
attribute :description
|
5
|
+
|
6
|
+
class Response < BaseResponse #:nodoc:
|
7
|
+
attribute :transaction_id
|
8
|
+
attribute :transaction_status, :enumeration => :transaction_status
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class GetAccountActivity < Base #:nodoc:
|
3
|
+
attribute :start_date # required
|
4
|
+
attribute :end_date
|
5
|
+
attribute :'FPSOperation', :enumeration => :fps_operation
|
6
|
+
attribute :max_batch_size
|
7
|
+
attribute :payment_method, :enumeration => :payment_method
|
8
|
+
attribute :response_group
|
9
|
+
attribute :role, :enumeration => :transactional_role
|
10
|
+
attribute :sort_order_by_date, :enumeration => :sort_order_by_date
|
11
|
+
attribute :status, :type => :transaction_status
|
12
|
+
|
13
|
+
class Response < BaseResponse #:nodoc:
|
14
|
+
attribute :batch_size
|
15
|
+
attribute :start_time_for_next_transaction
|
16
|
+
attribute :transaction, :collection => :transaction
|
17
|
+
|
18
|
+
alias_method :transactions, :transaction
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class GetRecipientVerificationStatus < Base #:nodoc:
|
3
|
+
attribute :recipient_token_id
|
4
|
+
|
5
|
+
class Response < BaseResponse #:nodoc:
|
6
|
+
attribute :recipient_verification_status, :enumeration => :recipient_verification_status
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class GetTokens < Base #:nodoc:
|
3
|
+
attribute :caller_reference
|
4
|
+
attribute :token_status
|
5
|
+
attribute :token_type
|
6
|
+
|
7
|
+
class Response < BaseResponse #:nodoc:
|
8
|
+
attribute :token, :collection => :token
|
9
|
+
|
10
|
+
alias_method :tokens, :token
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class GetTransactionStatus < Base #:nodoc:
|
3
|
+
attribute :transaction_id
|
4
|
+
|
5
|
+
class Response < BaseResponse #:nodoc:
|
6
|
+
attribute :caller_reference
|
7
|
+
attribute :status_code
|
8
|
+
attribute :status_message
|
9
|
+
attribute :transaction_id
|
10
|
+
attribute :transaction_status, :enumeration => :transaction_status
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class Pay < Base #:nodoc:
|
3
|
+
attribute :caller_description
|
4
|
+
attribute :caller_reference # required
|
5
|
+
attribute :charge_fee_to, :enumeration => :charge_fee_to
|
6
|
+
attribute :descriptor_policy, :type => :descriptor_policy
|
7
|
+
attribute :marketplace_fixed_fee, :type => :amount
|
8
|
+
attribute :marketplace_variable_fee
|
9
|
+
attribute :recipient_token_id
|
10
|
+
attribute :sender_description
|
11
|
+
attribute :sender_token_id # required
|
12
|
+
attribute :transaction_amount, :type => :amount # required
|
13
|
+
attribute :transaction_timeout_in_mins
|
14
|
+
|
15
|
+
class Response < BaseResponse #:nodoc:
|
16
|
+
attribute :transaction_id
|
17
|
+
attribute :transaction_status, :enumeration => :transaction_status
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class Refund < Base #:nodoc:
|
3
|
+
attribute :caller_description
|
4
|
+
attribute :caller_reference # required
|
5
|
+
attribute :refund_amount, :type => :amount
|
6
|
+
attribute :transaction_id # required
|
7
|
+
attribute :marketplace_refund_policy, :enumeration => :marketplace_refund_policy
|
8
|
+
|
9
|
+
class Response < BaseResponse #:nodoc:
|
10
|
+
attribute :transaction_id
|
11
|
+
attribute :transaction_status, :enumeration => :transaction_status
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class Reserve < Base #:nodoc:
|
3
|
+
attribute :caller_description
|
4
|
+
attribute :caller_reference # required
|
5
|
+
attribute :charge_fee_to, :enumeration => :charge_fee_to
|
6
|
+
attribute :descriptor_policy, :type => :descriptor_policy
|
7
|
+
attribute :marketplace_fixed_fee, :type => :amount
|
8
|
+
attribute :marketplace_variable_fee
|
9
|
+
attribute :recipient_token_id
|
10
|
+
attribute :sender_description
|
11
|
+
attribute :sender_token_id # required
|
12
|
+
attribute :transaction_amount, :type => :amount # required
|
13
|
+
attribute :transaction_timeout_in_mins
|
14
|
+
|
15
|
+
class Response < BaseResponse #:nodoc:
|
16
|
+
attribute :transaction_id
|
17
|
+
attribute :transaction_status, :enumeration => :transaction_status
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class Settle < Base #:nodoc:
|
3
|
+
attribute :reserve_transaction_id
|
4
|
+
attribute :transaction_amount, :type => :amount
|
5
|
+
|
6
|
+
class Response < BaseResponse #:nodoc:
|
7
|
+
attribute :transaction_id
|
8
|
+
attribute :transaction_status, :enumeration => :transaction_status
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AmazonFlexPay::API #:nodoc:
|
2
|
+
class VerifySignature < Base #:nodoc:
|
3
|
+
attribute :url_end_point
|
4
|
+
attribute :http_parameters
|
5
|
+
|
6
|
+
class Response < BaseResponse #:nodoc:
|
7
|
+
attribute :verification_status
|
8
|
+
|
9
|
+
def verified?
|
10
|
+
verification_status == 'Success'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# load all api classes
|
2
|
+
require 'amazon_flex_pay/api/base'
|
3
|
+
Dir[File.dirname(__FILE__) + '/api/*'].each do |p| require "amazon_flex_pay/api/#{File.basename(p)}" end
|
4
|
+
|
5
|
+
module AmazonFlexPay
|
6
|
+
class << self
|
7
|
+
# Cancels a transaction.
|
8
|
+
#
|
9
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/Cancel.html
|
10
|
+
def cancel(transaction_id, options = {})
|
11
|
+
API::Cancel.new(options.merge(:transaction_id => transaction_id)).submit
|
12
|
+
end
|
13
|
+
|
14
|
+
# Cancels a token.
|
15
|
+
#
|
16
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/CancelToken.html
|
17
|
+
def cancel_token(token_id, options = {})
|
18
|
+
API::CancelToken.new(options.merge(:token_id => token_id)).submit
|
19
|
+
end
|
20
|
+
|
21
|
+
# Searches through transactions on your account. Helpful if you want to compare vs your own records,
|
22
|
+
# or print an admin report.
|
23
|
+
#
|
24
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/GetAccountActivity.html
|
25
|
+
def get_account_activity(start_date, end_date, options = {})
|
26
|
+
API::GetAccountActivity.new(options.merge(:start_date => start_date, :end_date => end_date)).submit
|
27
|
+
end
|
28
|
+
|
29
|
+
# Gets your Amazon Payments account balance.
|
30
|
+
#
|
31
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/GetAccountBalance.html
|
32
|
+
def get_account_balance
|
33
|
+
API::GetAccountBalance.new.submit
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the status of a recipient's Amazon account. This is a high-level status indicating whether
|
37
|
+
# the recipient can receive up to $10k per month (VerificationComplete) or has no receiving limitations
|
38
|
+
# at all (VerificationCompleteNoLimits).
|
39
|
+
#
|
40
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/GetRecipientVerificationStatus.html
|
41
|
+
def get_recipient_verification_status(recipient_token_id)
|
42
|
+
API::GetRecipientVerificationStatus.new(:recipient_token_id => recipient_token_id).submit
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns information about a token's state from a caller reference.
|
46
|
+
#
|
47
|
+
# This is the closest thing that Amazon's API has to getting the status of a pipeline. Provide the caller
|
48
|
+
# reference for your pipeline (you are saving caller references, right?), and if this returns a token you
|
49
|
+
# can assume the pipeline finished successfully.
|
50
|
+
#
|
51
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/GetTokensByCaller.html
|
52
|
+
def get_token_by_caller_reference(ref)
|
53
|
+
API::GetTokenByCaller.new(:caller_reference => ref).submit
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns information about a token's state from a token id.
|
57
|
+
#
|
58
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/GetTokensByCaller.html
|
59
|
+
def get_token_by_id(id)
|
60
|
+
API::GetTokenByCaller.new(:token_id => id).submit
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns information about how much of the token has been used, and what remains.
|
64
|
+
#
|
65
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/GetTokenUsage.html
|
66
|
+
def get_token_usage(id)
|
67
|
+
API::GetTokenUsage.new(:token_id => id).submit
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns all of your tokens. Note that when you send someone through a recipient pipeline, that registers
|
71
|
+
# a recipient token on _their_ account, not yours. And when you send someone through a single use pipeline,
|
72
|
+
# that registers a sender token on _their_account, not yours.
|
73
|
+
#
|
74
|
+
# So basically this will only return recipient tokens where _you_ are the recipient, or sender tokens where
|
75
|
+
# _you_ are the sender.
|
76
|
+
#
|
77
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/GetTokens.html
|
78
|
+
def get_tokens(options = {})
|
79
|
+
API::GetTokens.new(options).submit
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns all of Amazon's details about a transaction, such as its status and when it began and finished
|
83
|
+
# processing.
|
84
|
+
#
|
85
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/GetTransaction.html
|
86
|
+
def get_transaction(id)
|
87
|
+
API::GetTransaction.new(:transaction_id => id).submit
|
88
|
+
end
|
89
|
+
|
90
|
+
# Returns the current status of the transaction. Note that this information is also available from
|
91
|
+
# <tt>get_transaction</tt>.
|
92
|
+
#
|
93
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/GetTransactionStatus.html
|
94
|
+
def get_transaction_status(id)
|
95
|
+
API::GetTransactionStatus.new(:transaction_id => id).submit
|
96
|
+
end
|
97
|
+
|
98
|
+
# Begins a Pay request for a sender token. If you are not also the recipient (this is a three-party marketplace
|
99
|
+
# transaction) then you must also specify the recipient token.
|
100
|
+
#
|
101
|
+
# Sign up for Instant Payment Notifications to be told when this has finished.
|
102
|
+
#
|
103
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/Pay.html
|
104
|
+
def pay(value, currency, sender_token_id, caller_reference, options = {})
|
105
|
+
API::Pay.new(options.merge(
|
106
|
+
:transaction_amount => {:value => value, :currency_code => currency},
|
107
|
+
:sender_token_id => sender_token_id,
|
108
|
+
:caller_reference => caller_reference
|
109
|
+
)).submit
|
110
|
+
end
|
111
|
+
|
112
|
+
# Begins a Reserve request for the sender token. Very similar to <tt>pay</tt>.
|
113
|
+
#
|
114
|
+
# Sign up for Instant Payment Notifications to be told when this has finished.
|
115
|
+
#
|
116
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/Reserve.html
|
117
|
+
def reserve(value, currency, sender_token_id, caller_reference, options = {})
|
118
|
+
API::Reserve.new(options.merge(
|
119
|
+
:transaction_amount => {:value => value, :currency_code => currency},
|
120
|
+
:sender_token_id => sender_token_id,
|
121
|
+
:caller_reference => caller_reference
|
122
|
+
)).submit
|
123
|
+
end
|
124
|
+
|
125
|
+
# Refunds a transaction. By default it will refund the entire transaction, but you can
|
126
|
+
# provide an amount for partial refunds.
|
127
|
+
#
|
128
|
+
# Sign up for Instant Payment Notifications to be told when this has finished.
|
129
|
+
#
|
130
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/Refund.html
|
131
|
+
def refund(transaction_id, caller_reference, options = {})
|
132
|
+
API::Refund.new(options.merge(:transaction_id => transaction_id, :caller_reference => caller_reference)).submit
|
133
|
+
end
|
134
|
+
|
135
|
+
# If you have a Reserve transaction, use this to Settle (capture) it.
|
136
|
+
#
|
137
|
+
# Sign up for Instant Payment Notifications to be told when this has finished.
|
138
|
+
#
|
139
|
+
# See http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/Settle.html
|
140
|
+
def settle(transaction_id, options = {})
|
141
|
+
API::Settle.new(options.merge(:reserve_transaction_id => transaction_id)).submit
|
142
|
+
end
|
143
|
+
|
144
|
+
# This is how you verify IPNs and pipeline responses.
|
145
|
+
# Pass the entire request object.
|
146
|
+
def verify_request(request)
|
147
|
+
verify_signature(
|
148
|
+
# url without query string
|
149
|
+
request.protocol + request.host_with_port + request.path,
|
150
|
+
# raw parameters
|
151
|
+
request.get? ? request.query_string : request.raw_post
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Verifies the signature embedded in the params string for the given url.
|
156
|
+
#
|
157
|
+
# Please use <tt>verify_request</tt> instead to make sure the URL and params remain properly formatted.
|
158
|
+
def verify_signature(url, params)
|
159
|
+
API::VerifySignature.new(:url_end_point => url, :http_parameters => params).submit
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|