remit 0.0.6 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +36 -5
- data/lib/remit.rb +35 -39
- data/lib/remit/common.rb +79 -24
- data/lib/remit/data_types.rb +118 -17
- data/lib/remit/get_pipeline.rb +160 -80
- data/lib/remit/inbound_request.rb +85 -0
- data/lib/remit/ipn_request.rb +4 -39
- data/lib/remit/operations/cancel.rb +20 -0
- data/lib/remit/operations/cancel_subscription_and_refund.rb +5 -1
- data/lib/remit/operations/cancel_token.rb +1 -0
- data/lib/remit/operations/fund_prepaid.rb +6 -4
- data/lib/remit/operations/get_account_activity.rb +5 -34
- data/lib/remit/operations/get_account_balance.rb +14 -11
- data/lib/remit/operations/get_all_credit_instruments.rb +2 -0
- data/lib/remit/operations/get_all_prepaid_instruments.rb +2 -0
- data/lib/remit/operations/get_debt_balance.rb +9 -4
- data/lib/remit/operations/get_outstanding_debt_balance.rb +8 -5
- data/lib/remit/operations/get_payment_instruction.rb +2 -0
- data/lib/remit/operations/get_prepaid_balance.rb +9 -5
- data/lib/remit/operations/get_recipient_verification_status.rb +25 -0
- data/lib/remit/operations/get_token_by_caller.rb +5 -1
- data/lib/remit/operations/get_token_usage.rb +5 -1
- data/lib/remit/operations/get_tokens.rb +5 -1
- data/lib/remit/operations/get_total_prepaid_liability.rb +9 -5
- data/lib/remit/operations/get_transaction.rb +1 -25
- data/lib/remit/operations/get_transaction_status.rb +28 -0
- data/lib/remit/operations/install_payment_instruction.rb +8 -1
- data/lib/remit/operations/pay.rb +5 -9
- data/lib/remit/operations/refund.rb +20 -11
- data/lib/remit/operations/reserve.rb +2 -4
- data/lib/remit/operations/settle.rb +2 -1
- data/lib/remit/operations/settle_debt.rb +2 -4
- data/lib/remit/operations/subscribe_for_caller_notification.rb +2 -0
- data/lib/remit/operations/unsubscribe_for_caller_notification.rb +2 -0
- data/lib/remit/operations/write_off_debt.rb +2 -4
- data/lib/remit/pipeline_response.rb +8 -41
- data/lib/remit/signature_utils_for_outbound.rb +74 -0
- data/lib/remit/verify_signature.rb +21 -0
- data/spec/integrations/get_account_activity_spec.rb +25 -19
- data/spec/integrations/get_tokens_spec.rb +9 -7
- data/spec/integrations/integrations_helper.rb +7 -0
- data/spec/integrations/ipn_request_spec.rb +28 -20
- data/spec/integrations/pipeline_response_spec.rb +27 -0
- data/spec/integrations/verify_signature_spec.rb +140 -0
- data/spec/mocks/CancelResponse.xml +13 -0
- data/spec/mocks/CancelSubscriptionAndRefundResponse.xml +10 -0
- data/spec/mocks/CancelTokenResponse.xml +6 -0
- data/spec/mocks/ErrorResponse.xml +15 -0
- data/spec/mocks/FundPrepaidResponse.xml +11 -0
- data/spec/mocks/GetAccountActivityResponse.xml +68 -0
- data/spec/mocks/GetAccountBalanceResponse.xml +34 -0
- data/spec/mocks/GetDebtBalanceResponse.xml +21 -0
- data/spec/mocks/GetOutstandingDebtBalanceResponse.xml +21 -0
- data/spec/mocks/GetPaymentInstructionResponse.xml +25 -0
- data/spec/mocks/GetPrepaidBalanceResponse.xml +21 -0
- data/spec/mocks/GetRecipientVerificationStatusResponse.xml +9 -0
- data/spec/mocks/GetTokenByCallerResponse.xml +22 -0
- data/spec/mocks/GetTokenUsageResponse.xml +28 -0
- data/spec/mocks/GetTokensResponse.xml +22 -0
- data/spec/mocks/GetTotalPrepaidLiabilityResponse.xml +21 -0
- data/spec/mocks/GetTransactionResponse.xml +76 -0
- data/spec/mocks/GetTransactionStatusResponse.xml +16 -0
- data/spec/mocks/InstallPaymentInstructionResponse.xml +10 -0
- data/spec/mocks/PayResponse.xml +11 -0
- data/spec/mocks/RefundResponse.xml +11 -0
- data/spec/mocks/ReserveResponse.xml +11 -0
- data/spec/mocks/SettleDebtResponse.xml +11 -0
- data/spec/mocks/SettleResponse.xml +11 -0
- data/spec/mocks/VerifySignatureResponse.xml +11 -0
- data/spec/mocks/WriteOffDebtResponse.xml +11 -0
- data/spec/mocks/errors/InvalidParameterValue.xml +10 -0
- data/spec/mocks/errors/InvalidParams_certificateUrl.xml +2 -0
- data/spec/mocks/errors/RequestExpired.xml +10 -0
- data/spec/spec_helper.rb +59 -10
- data/spec/units/cancel_subscription_and_refund_spec.rb +29 -0
- data/spec/units/cancel_token_spec.rb +24 -0
- data/spec/units/fund_prepaid_spec.rb +28 -0
- data/spec/units/get_account_activity_spec.rb +58 -0
- data/spec/units/get_account_balance_spec.rb +28 -0
- data/spec/units/get_debt_balance_spec.rb +29 -0
- data/spec/units/get_outstanding_debt_balance_spec.rb +29 -0
- data/spec/units/get_pipeline_spec.rb +16 -0
- data/spec/units/get_prepaid_balance_spec.rb +29 -0
- data/spec/units/get_recipient_verification_status_spec.rb +26 -0
- data/spec/units/get_token_by_caller_spec.rb +56 -0
- data/spec/units/get_token_usage_spec.rb +51 -0
- data/spec/units/get_tokens_spec.rb +56 -0
- data/spec/units/get_total_prepaid_liability_spec.rb +26 -0
- data/spec/units/get_transaction_spec.rb +103 -0
- data/spec/units/get_transaction_status_spec.rb +44 -0
- data/spec/units/pay_spec.rb +36 -57
- data/spec/units/refund_spec.rb +41 -0
- data/spec/units/reserve_spec.rb +41 -0
- data/spec/units/settle_debt_spec.rb +41 -0
- data/spec/units/settle_spec.rb +41 -0
- data/spec/units/units_helper.rb +23 -2
- data/spec/units/write_off_debt_spec.rb +41 -0
- metadata +116 -12
- data/lib/remit/operations/discard_results.rb +0 -18
- data/lib/remit/operations/get_results.rb +0 -27
- data/lib/remit/operations/retry_transaction.rb +0 -18
- data/spec/units/get_results_spec.rb +0 -49
data/README.markdown
CHANGED
@@ -38,13 +38,18 @@ make a simple call to get the tokens stored on the account:
|
|
38
38
|
puts response.tokens.first.token_id
|
39
39
|
|
40
40
|
|
41
|
+
VerifySignature API
|
42
|
+
-------------------
|
43
|
+
See spec/integrations/verify_signature_spec.rb for examples on correct and incorrect usage!
|
44
|
+
|
45
|
+
|
41
46
|
Using with Rails
|
42
47
|
----------------
|
43
48
|
|
44
49
|
To use Remit in a Rails application, you must first specify a dependency on the
|
45
|
-
Remit gem in your
|
50
|
+
Remit gem in your Gemfile:
|
46
51
|
|
47
|
-
|
52
|
+
gem 'remit', :git => "git://github.com/nyc-ruby-meetup/remit.git"
|
48
53
|
|
49
54
|
Then you should create an initializer to configure your Amazon keys. Create the
|
50
55
|
file config/initializers/remit.rb with the following contents:
|
@@ -84,8 +89,34 @@ Sites Using Remit
|
|
84
89
|
|
85
90
|
The following production sites are currently using Remit:
|
86
91
|
|
87
|
-
|
88
|
-
|
89
|
-
|
92
|
+
* [Storyenvy](http://www.storenvy.com/)
|
93
|
+
* [ObsidianPortal](http://www.obsidianportal.com/)
|
94
|
+
|
95
|
+
|
96
|
+
Amazon API Compliance
|
97
|
+
---------------------
|
98
|
+
These are the changes summarized by Amazon from the previous API, and the level of compliance in this branch:
|
99
|
+
|
100
|
+
1. You don't have to use InstallPaymentInstruction API to create Caller and Recipient tokens for your account. A Recipient token is now required only in Marketplace applications. We have completely removed the Caller token.
|
101
|
+
Compliance: Caller token references removed.
|
102
|
+
2. We removed parameters that are not being used by you today. For example, we removed metadata and recipient description, but we retained sender description and caller description.
|
103
|
+
Compliance: DONE! recipient_description and metadata have been removed from the code.
|
104
|
+
3. We simplified the transaction response object.
|
105
|
+
Compliance: The former Remit::TransactionResponse object has been accordingly simplified.
|
106
|
+
4. We simplified the GetTransaction response by removing unnecessary parameters.
|
107
|
+
Compliance: ?
|
108
|
+
5. By default, implicit retry and cancel will be the method used to handle temporary declines rather than the current explicit retry process.
|
109
|
+
Compliance: Removed deprecated statuses
|
110
|
+
6. GetResults, DiscardResults are replaced with GetTransactionStatus API.
|
111
|
+
Compliance: GetResults and Discard Results are gone. GetTransactionStatus takes their place.
|
112
|
+
7. Temporary decline status is not exposed to customers as we provide a simpler way to handle this status.
|
113
|
+
Compliance: Temporary decline status can no longer be tested for, as it will never be a status.
|
114
|
+
8. Web Service notification is removed and replaced with simplified IPN (Instant Payment Notification) mechanism.
|
115
|
+
|
116
|
+
Running Specification Suite
|
117
|
+
---------------------------
|
118
|
+
1. Copy test.sh.example to test.sh
|
119
|
+
2. Edit test.sh to have valid Amazon developer account access and secret keys
|
120
|
+
3. Run ./test.sh from the command line.
|
90
121
|
|
91
122
|
Copyright (c) 2007-2009 Tyler Hunt, released under the MIT license
|
data/lib/remit.rb
CHANGED
@@ -6,22 +6,27 @@ require 'uri'
|
|
6
6
|
require 'date'
|
7
7
|
require 'base64'
|
8
8
|
require 'erb'
|
9
|
+
require 'cgi'
|
9
10
|
|
10
11
|
require 'rubygems'
|
11
12
|
|
12
13
|
gem 'relax', '0.0.7'
|
13
14
|
require 'relax'
|
14
15
|
|
15
|
-
|
16
|
+
|
16
17
|
require 'remit/data_types'
|
18
|
+
require 'remit/common'
|
17
19
|
require 'remit/error_codes'
|
20
|
+
require 'remit/signature_utils_for_outbound'
|
21
|
+
require 'remit/verify_signature'
|
22
|
+
require 'remit/inbound_request'
|
18
23
|
require 'remit/ipn_request'
|
19
24
|
require 'remit/get_pipeline'
|
20
25
|
require 'remit/pipeline_response'
|
21
26
|
|
22
27
|
require 'remit/operations/cancel_subscription_and_refund'
|
23
28
|
require 'remit/operations/cancel_token'
|
24
|
-
require 'remit/operations/
|
29
|
+
require 'remit/operations/cancel'
|
25
30
|
require 'remit/operations/fund_prepaid'
|
26
31
|
require 'remit/operations/get_account_activity'
|
27
32
|
require 'remit/operations/get_account_balance'
|
@@ -31,17 +36,17 @@ require 'remit/operations/get_debt_balance'
|
|
31
36
|
require 'remit/operations/get_outstanding_debt_balance'
|
32
37
|
require 'remit/operations/get_payment_instruction'
|
33
38
|
require 'remit/operations/get_prepaid_balance'
|
34
|
-
require 'remit/operations/
|
39
|
+
require 'remit/operations/get_recipient_verification_status'
|
35
40
|
require 'remit/operations/get_token_by_caller'
|
36
41
|
require 'remit/operations/get_token_usage'
|
37
42
|
require 'remit/operations/get_tokens'
|
38
43
|
require 'remit/operations/get_total_prepaid_liability'
|
39
44
|
require 'remit/operations/get_transaction'
|
45
|
+
require 'remit/operations/get_transaction_status'
|
40
46
|
require 'remit/operations/install_payment_instruction'
|
41
47
|
require 'remit/operations/pay'
|
42
48
|
require 'remit/operations/refund'
|
43
49
|
require 'remit/operations/reserve'
|
44
|
-
require 'remit/operations/retry_transaction'
|
45
50
|
require 'remit/operations/settle'
|
46
51
|
require 'remit/operations/settle_debt'
|
47
52
|
require 'remit/operations/subscribe_for_caller_notification'
|
@@ -50,9 +55,11 @@ require 'remit/operations/write_off_debt'
|
|
50
55
|
|
51
56
|
module Remit
|
52
57
|
class API < Relax::Service
|
58
|
+
|
59
|
+
include VerifySignature
|
53
60
|
include CancelSubscriptionAndRefund
|
54
61
|
include CancelToken
|
55
|
-
include
|
62
|
+
include Cancel
|
56
63
|
include FundPrepaid
|
57
64
|
include GetAccountActivity
|
58
65
|
include GetAccountBalance
|
@@ -63,7 +70,7 @@ module Remit
|
|
63
70
|
include GetPaymentInstruction
|
64
71
|
include GetPipeline
|
65
72
|
include GetPrepaidBalance
|
66
|
-
include
|
73
|
+
include GetRecipientVerificationStatus
|
67
74
|
include GetTokenUsage
|
68
75
|
include GetTokens
|
69
76
|
include GetTokenByCaller
|
@@ -73,7 +80,6 @@ module Remit
|
|
73
80
|
include Pay
|
74
81
|
include Refund
|
75
82
|
include Reserve
|
76
|
-
include RetryTransaction
|
77
83
|
include Settle
|
78
84
|
include SettleDebt
|
79
85
|
include SubscribeForCallerNotification
|
@@ -84,53 +90,43 @@ module Remit
|
|
84
90
|
API_SANDBOX_ENDPOINT = 'https://fps.sandbox.amazonaws.com/'.freeze
|
85
91
|
PIPELINE_URL = 'https://authorize.payments.amazon.com/cobranded-ui/actions/start'.freeze
|
86
92
|
PIPELINE_SANDBOX_URL = 'https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start'.freeze
|
87
|
-
API_VERSION = Date.new(
|
93
|
+
API_VERSION = Date.new(2008, 9, 17).to_s.freeze
|
94
|
+
PIPELINE_VERSION = Date.new(2009, 1, 9).to_s.freeze
|
88
95
|
SIGNATURE_VERSION = 2.freeze
|
96
|
+
SIGNATURE_METHOD = "HmacSHA256".freeze
|
89
97
|
|
98
|
+
#attr_reader :pipeline # kickstarter
|
99
|
+
attr_reader :pipeline_url # nyc
|
90
100
|
attr_reader :access_key
|
91
101
|
attr_reader :secret_key
|
92
|
-
attr_reader :
|
102
|
+
attr_reader :api_endpoint
|
93
103
|
|
94
104
|
def initialize(access_key, secret_key, sandbox=false)
|
95
105
|
@access_key = access_key
|
96
106
|
@secret_key = secret_key
|
97
107
|
@pipeline_url = sandbox ? PIPELINE_SANDBOX_URL : PIPELINE_URL
|
98
|
-
|
99
|
-
super(
|
108
|
+
@api_endpoint = sandbox ? API_SANDBOX_ENDPOINT : API_ENDPOINT
|
109
|
+
super(@api_endpoint)
|
100
110
|
end
|
101
|
-
|
102
|
-
|
103
|
-
|
111
|
+
|
112
|
+
# generates v1 signatures, for historical purposes.
|
113
|
+
def self.signature_v1(path, params, secret_key)
|
114
|
+
params = params.reject {|key, val| ['awsSignature', 'action', 'controller', 'id'].include?(key) }.sort_by{ |k,v| k.to_s.downcase }.map{|k,v| "#{CGI::escape(k)}=#{Remit::SignedQuery.escape_value(v)}"}.join('&')
|
115
|
+
signable = path + '?' + params
|
116
|
+
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, secret_key, signable)).strip
|
104
117
|
end
|
105
|
-
private :new_query
|
106
118
|
|
107
|
-
|
108
|
-
|
119
|
+
private
|
120
|
+
|
121
|
+
# called from Relax::Service#call
|
122
|
+
def query(request)
|
123
|
+
params = request.to_query.merge(
|
109
124
|
:AWSAccessKeyId => @access_key,
|
110
|
-
:SignatureVersion => SIGNATURE_VERSION,
|
111
|
-
Amazon::FPS::SignatureUtils::SIGNATURE_METHOD_KEYNAME => Amazon::FPS::SignatureUtils::HMAC_SHA256_ALGORITHM,
|
112
125
|
:Version => API_VERSION,
|
113
126
|
:Timestamp => Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
114
|
-
|
115
|
-
|
116
|
-
private :default_query
|
117
|
-
|
118
|
-
def query(request)
|
119
|
-
query = super
|
120
|
-
query[:Signature] = sign(query)
|
121
|
-
query
|
127
|
+
)
|
128
|
+
ApiQuery.new(@endpoint, @secret_key, params)
|
122
129
|
end
|
123
|
-
private :query
|
124
|
-
|
125
|
-
def sign(values)
|
126
|
-
signature = Amazon::FPS::SignatureUtils.sign_parameters({
|
127
|
-
:parameters => values,
|
128
|
-
:aws_secret_key => @secret_key,
|
129
|
-
:host => @endpoint.host,
|
130
|
-
:verb => "GET",
|
131
|
-
:uri => @endpoint.path })
|
132
|
-
return signature
|
133
|
-
end
|
134
|
-
private :sign
|
135
130
|
end
|
136
131
|
end
|
132
|
+
|
data/lib/remit/common.rb
CHANGED
@@ -9,14 +9,19 @@ require File.dirname(__FILE__) + '/../amazon/fps/signatureutils'
|
|
9
9
|
require File.dirname(__FILE__) + '/../amazon/fps/signatureutilsforoutbound'
|
10
10
|
|
11
11
|
module Remit
|
12
|
+
|
13
|
+
module ConvertKey
|
14
|
+
def convert_key(key)
|
15
|
+
key.to_s.gsub(/(^|_)(.)/) { $2.upcase }.to_sym
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
12
19
|
class Request < Relax::Request
|
13
20
|
def self.action(name)
|
14
21
|
parameter :action, :value => name
|
15
22
|
end
|
16
23
|
|
17
|
-
|
18
|
-
key.to_s.gsub(/(^|_)(.)/) { $2.upcase }.to_sym
|
19
|
-
end
|
24
|
+
include ConvertKey
|
20
25
|
protected :convert_key
|
21
26
|
end
|
22
27
|
|
@@ -26,24 +31,38 @@ module Remit
|
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
34
|
+
class ResponseMetadata < BaseResponse
|
35
|
+
# Amazon FPS returns a RequestId element for every API call accepted for processing
|
36
|
+
# that means not *every* call will have a request ID.
|
37
|
+
parameter :request_id#, :required => true
|
38
|
+
parameter :signature_version
|
39
|
+
parameter :signature_method
|
40
|
+
end
|
41
|
+
|
29
42
|
class Response < BaseResponse
|
30
|
-
parameter :
|
43
|
+
parameter :response_metadata, :type => Remit::ResponseMetadata, :required => true
|
31
44
|
|
32
45
|
attr_accessor :status
|
33
46
|
attr_accessor :errors
|
34
47
|
|
48
|
+
def request_id
|
49
|
+
self.response_metadata.respond_to?(:request_id) ? self.response_metadata.request_id : nil
|
50
|
+
end
|
51
|
+
|
35
52
|
def initialize(xml)
|
36
53
|
super
|
37
54
|
|
38
|
-
|
39
|
-
|
55
|
+
# TODO: How to differentiate between Error and Service Error properly? - pboling
|
56
|
+
# TODO: Is this ServiceError still relevant? - pboling
|
57
|
+
if is?(:Response) and has?(:Errors)
|
58
|
+
@errors = elements('errors/error').collect do |error|
|
40
59
|
Error.new(error)
|
41
60
|
end
|
42
61
|
else
|
43
62
|
@status = text_value(element(:Status))
|
44
|
-
@errors = elements('
|
63
|
+
@errors = elements('errors/errors').collect do |error|
|
45
64
|
ServiceError.new(error)
|
46
|
-
end
|
65
|
+
end if not successful?
|
47
66
|
end
|
48
67
|
end
|
49
68
|
|
@@ -59,42 +78,78 @@ module Remit
|
|
59
78
|
end
|
60
79
|
|
61
80
|
class SignedQuery < Relax::Query
|
62
|
-
def initialize(uri, secret_key, query={})
|
81
|
+
def initialize(uri, secret_key, query = {})
|
63
82
|
super(query)
|
64
83
|
@uri = URI.parse(uri.to_s)
|
65
84
|
@secret_key = secret_key
|
85
|
+
sign
|
66
86
|
end
|
67
87
|
|
68
88
|
def sign
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
:parameters => self,
|
74
|
-
:aws_secret_key => @secret_key,
|
75
|
-
:host => @uri.host,
|
76
|
-
:verb => "GET",
|
77
|
-
:uri => @uri.path })
|
89
|
+
store(:signatureVersion, Remit::API::SIGNATURE_VERSION)
|
90
|
+
store(:signatureMethod, Remit::API::SIGNATURE_METHOD)
|
91
|
+
store(:signature, signature)
|
92
|
+
end
|
78
93
|
|
79
|
-
|
94
|
+
def signature
|
95
|
+
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, @secret_key, signable_string)).strip
|
80
96
|
end
|
81
97
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
98
|
+
def signable_string
|
99
|
+
[ 'GET',
|
100
|
+
@uri.host,
|
101
|
+
@uri.path,
|
102
|
+
to_s # the query string, sans :signature (but with :signatureVersion and :signatureMethod)
|
103
|
+
].join("\n")
|
85
104
|
end
|
86
105
|
|
87
106
|
class << self
|
88
107
|
def parse(uri, secret_key, query_string)
|
89
108
|
query = self.new(uri, secret_key)
|
90
|
-
|
91
109
|
query_string.split('&').each do |parameter|
|
92
110
|
key, value = parameter.split('=', 2)
|
93
111
|
query[key] = unescape_value(value)
|
94
112
|
end
|
95
|
-
|
96
113
|
query
|
97
114
|
end
|
115
|
+
|
116
|
+
UNSAFE = /[^A-Za-z0-9_.~-]/
|
117
|
+
# Amazon is very specific about what chars should be escaped, and which should not.
|
118
|
+
def escape_value(value)
|
119
|
+
# note that URI.escape(' ') => '%20', and CGI.escape(' ') => '+'
|
120
|
+
URI.escape(value.to_s, UNSAFE)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Frustratingly enough, API requests want the signature params with slightly different casing.
|
126
|
+
class ApiQuery < SignedQuery
|
127
|
+
def sign
|
128
|
+
store(:SignatureVersion, Remit::API::SIGNATURE_VERSION)
|
129
|
+
store(:SignatureMethod, 'HmacSHA256')
|
130
|
+
store(:Signature, signature)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
#Hack on Hash to make it s rocket
|
136
|
+
class Hash
|
137
|
+
def to_url_params
|
138
|
+
elements = []
|
139
|
+
keys.size.times do |i|
|
140
|
+
elements << "#{(keys[i])}=#{Remit::SignedQuery.escape_value(values[i])}"
|
141
|
+
end
|
142
|
+
elements.join('&')
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.from_url_params(url_params)
|
146
|
+
result = {}
|
147
|
+
url_params.split('&').each do |element|
|
148
|
+
element = element.split('=')
|
149
|
+
# BJM - need to unescape the values in the param string
|
150
|
+
#result[element[0]] = element[1]
|
151
|
+
result[element[0]] = CGI.unescape(element[1])
|
98
152
|
end
|
153
|
+
result
|
99
154
|
end
|
100
155
|
end
|
data/lib/remit/data_types.rb
CHANGED
@@ -3,10 +3,32 @@ require 'relax'
|
|
3
3
|
|
4
4
|
require 'remit/common'
|
5
5
|
|
6
|
+
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
7
|
+
if first_letter_in_uppercase
|
8
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
9
|
+
else
|
10
|
+
lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Relax
|
15
|
+
class Response
|
16
|
+
class << self
|
17
|
+
alias_method :alias_for_parameter, :parameter
|
18
|
+
def parameter(name, options = {})
|
19
|
+
opts = {
|
20
|
+
:element => camelize(name)
|
21
|
+
}.merge!(options)
|
22
|
+
alias_for_parameter(name, opts)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
6
28
|
module Remit
|
7
29
|
class Amount < BaseResponse
|
8
30
|
parameter :currency_code
|
9
|
-
parameter :
|
31
|
+
parameter :value, :type => :float
|
10
32
|
end
|
11
33
|
|
12
34
|
class TemporaryDeclinePolicy < BaseResponse
|
@@ -16,7 +38,7 @@ module Remit
|
|
16
38
|
|
17
39
|
class DescriptorPolicy < BaseResponse
|
18
40
|
parameter :soft_descriptor_type
|
19
|
-
parameter :
|
41
|
+
parameter :CS_owner
|
20
42
|
end
|
21
43
|
|
22
44
|
class ChargeFeeTo
|
@@ -27,6 +49,12 @@ module Remit
|
|
27
49
|
class Error < BaseResponse
|
28
50
|
parameter :code
|
29
51
|
parameter :message
|
52
|
+
def error_code
|
53
|
+
self.code
|
54
|
+
end
|
55
|
+
def reason_text
|
56
|
+
self.message
|
57
|
+
end
|
30
58
|
end
|
31
59
|
|
32
60
|
class InstrumentStatus
|
@@ -36,7 +64,7 @@ module Remit
|
|
36
64
|
end
|
37
65
|
|
38
66
|
class PaymentMethods
|
39
|
-
|
67
|
+
BALANCE_aFER = 'abt'
|
40
68
|
BANK_ACCOUNT = 'ach'
|
41
69
|
CREDIT_CARD = 'credit card'
|
42
70
|
PREPAID = 'prepaid'
|
@@ -63,9 +91,9 @@ module Remit
|
|
63
91
|
class Token < BaseResponse
|
64
92
|
parameter :token_id
|
65
93
|
parameter :friendly_name
|
66
|
-
parameter :
|
94
|
+
parameter :token_status
|
67
95
|
parameter :date_installed, :type => :time
|
68
|
-
parameter :caller_installed
|
96
|
+
#parameter :caller_installed
|
69
97
|
parameter :caller_reference
|
70
98
|
parameter :token_type
|
71
99
|
parameter :old_token_id
|
@@ -84,27 +112,65 @@ module Remit
|
|
84
112
|
parameter :last_reset_count
|
85
113
|
parameter :last_reset_time_stamp
|
86
114
|
end
|
115
|
+
|
116
|
+
class TransactionPart < Remit::BaseResponse
|
117
|
+
parameter :account_id
|
118
|
+
parameter :role
|
119
|
+
parameter :name
|
120
|
+
parameter :reference
|
121
|
+
parameter :description
|
122
|
+
parameter :fee_paid, :type => Amount
|
123
|
+
end
|
124
|
+
|
125
|
+
class Transaction < BaseResponse
|
126
|
+
|
127
|
+
parameter :caller_name
|
128
|
+
parameter :caller_reference
|
129
|
+
parameter :caller_description
|
130
|
+
parameter :caller_transaction_date, :type => :time
|
131
|
+
parameter :date_completed, :type => :time
|
132
|
+
parameter :date_received, :type => :time
|
133
|
+
parameter :error_code
|
134
|
+
parameter :error_message
|
135
|
+
parameter :fees, :element=>"FPSFees", :type => Amount
|
136
|
+
parameter :fps_fees_paid_by, :element=>"FPSFeesPaidBy"
|
137
|
+
parameter :fps_operation, :element=>"FPSOperation"
|
138
|
+
parameter :meta_data
|
139
|
+
parameter :payment_method
|
140
|
+
parameter :recipient_name
|
141
|
+
parameter :recipient_email
|
142
|
+
parameter :recipient_token_id
|
143
|
+
parameter :related_transactions
|
144
|
+
parameter :sender_email
|
145
|
+
parameter :sender_name
|
146
|
+
parameter :sender_token_id
|
147
|
+
parameter :transaction_status
|
148
|
+
parameter :status_code
|
149
|
+
parameter :status_history
|
150
|
+
parameter :status_message
|
151
|
+
parameter :transaction_amount, :type => Amount
|
152
|
+
parameter :transaction_id
|
153
|
+
parameter :transaction_parts, :collection => TransactionPart, :element=>"TransactionPart"
|
154
|
+
end
|
87
155
|
|
88
156
|
class TransactionResponse < BaseResponse
|
89
157
|
parameter :transaction_id
|
90
|
-
parameter :
|
91
|
-
parameter :status_detail
|
92
|
-
parameter :new_sender_token_usage, :type => TokenUsageLimit
|
158
|
+
parameter :transaction_status
|
93
159
|
|
94
|
-
%w(
|
160
|
+
%w(cancelled failure pending reserved success).each do |status_name|
|
95
161
|
define_method("#{status_name}?") do
|
96
|
-
self.
|
162
|
+
self.transaction_status == Remit::TransactionStatus.const_get(status_name.sub('_', '').upcase)
|
97
163
|
end
|
98
164
|
end
|
99
165
|
end
|
100
166
|
|
101
167
|
class TransactionStatus
|
168
|
+
#For IPN operations these strings are upcased. For Non-IPN operations they are not upcased
|
169
|
+
CANCELLED = 'Cancelled'
|
170
|
+
FAILURE = 'Failure'
|
171
|
+
PENDING = 'Pending'
|
102
172
|
RESERVED = 'Reserved'
|
103
173
|
SUCCESS = 'Success'
|
104
|
-
FAILURE = 'Failure'
|
105
|
-
INITIATED = 'Initiated'
|
106
|
-
REINITIATED = 'Reinitiated'
|
107
|
-
TEMPORARYDECLINE = 'TemporaryDecline'
|
108
174
|
end
|
109
175
|
|
110
176
|
class TokenType
|
@@ -121,11 +187,13 @@ module Remit
|
|
121
187
|
RECIPIENT = 'Recipient'
|
122
188
|
SETUP_PREPAID = 'SetupPrepaid'
|
123
189
|
SETUP_POSTPAID = 'SetupPostpaid'
|
190
|
+
EDIT_TOKEN = 'EditToken'
|
124
191
|
end
|
125
192
|
|
126
193
|
class PipelineStatusCode
|
127
194
|
CALLER_EXCEPTION = 'CE' # problem with your code
|
128
195
|
SYSTEM_ERROR = 'SE' # system error, try again
|
196
|
+
SUCCESS_UNCHANGED = 'SU' # edit token pipeline finished, but token is unchanged
|
129
197
|
SUCCESS_ABT = 'SA' # successful payment with Amazon balance
|
130
198
|
SUCCESS_ACH = 'SB' # successful payment with bank transfer
|
131
199
|
SUCCESS_CC = 'SC' # successful payment with credit card
|
@@ -138,10 +206,10 @@ module Remit
|
|
138
206
|
|
139
207
|
module RequestTypes
|
140
208
|
class Amount < Remit::Request
|
141
|
-
parameter :
|
209
|
+
parameter :value
|
142
210
|
parameter :currency_code
|
143
211
|
end
|
144
|
-
|
212
|
+
|
145
213
|
class TemporaryDeclinePolicy < Remit::Request
|
146
214
|
parameter :temporary_decline_policy_type
|
147
215
|
parameter :implicit_retry_timeout_in_mins
|
@@ -149,10 +217,42 @@ module Remit
|
|
149
217
|
|
150
218
|
class DescriptorPolicy < Remit::Request
|
151
219
|
parameter :soft_descriptor_type
|
152
|
-
parameter :
|
220
|
+
parameter :CS_owner
|
153
221
|
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
class SoftDescriptorType
|
226
|
+
STATIC = 'Static'
|
227
|
+
DYNAMIC = 'Dynamic'
|
228
|
+
end
|
229
|
+
|
230
|
+
#MarketplaceRefundPolicy is available in these APIs:
|
231
|
+
# Amazon FPS Advanced Quick Start
|
232
|
+
# Amazon FPS Marketplace Quick Start
|
233
|
+
# Amazon FPS Aggregated Payments Quick Start
|
234
|
+
# i.e. Not Basic Quick Start
|
235
|
+
#It really should be listed under Enumerated DataTypes:
|
236
|
+
#MarketplaceTxnOnly Caller refunds his fee to the recipient. String
|
237
|
+
#MasterAndMarketplaceTxn Caller and Amazon FPS refund their fees to the String
|
238
|
+
# sender, and the recipient refunds his amount
|
239
|
+
#MasterTxnOnly Caller does not refund his fee. Amazon FPS String
|
240
|
+
# refunds its fee and the recipient refunds his amount
|
241
|
+
# plus the caller's fee to the sender.
|
242
|
+
class MarketplaceRefundPolicy
|
243
|
+
POLICY = {
|
244
|
+
:marketplace_txn_only => 'MarketplaceTxnOnly',
|
245
|
+
:master_and_marketplace_txn => 'MasterAndMarketplaceTxn',
|
246
|
+
:master_txn_only => 'MasterTxnOnly' #default if not specified, set by Amazon FPS
|
247
|
+
}
|
154
248
|
end
|
155
249
|
|
250
|
+
class TemporaryDeclinePolicyType
|
251
|
+
EXPLICIT_RETRY = 'ExplicitRetry'
|
252
|
+
IMPLICIT_RETRY = 'ImplicitRetry'
|
253
|
+
FAILURE = 'Failure'
|
254
|
+
end
|
255
|
+
|
156
256
|
class Operation
|
157
257
|
PAY = "Pay"
|
158
258
|
REFUND = "Refund"
|
@@ -161,4 +261,5 @@ module Remit
|
|
161
261
|
WRITE_OFF_DEBT = "WriteOffDebt"
|
162
262
|
FUND_PREPAID = "FundPrepaid"
|
163
263
|
end
|
264
|
+
|
164
265
|
end
|