revo-remit 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +122 -0
- data/lib/remit.rb +132 -0
- data/lib/remit/common.rb +151 -0
- data/lib/remit/data_types.rb +265 -0
- data/lib/remit/error_codes.rb +118 -0
- data/lib/remit/get_pipeline.rb +286 -0
- data/lib/remit/inbound_request.rb +85 -0
- data/lib/remit/ipn_request.rb +8 -0
- data/lib/remit/operations/cancel.rb +20 -0
- data/lib/remit/operations/cancel_subscription_and_refund.rb +26 -0
- data/lib/remit/operations/cancel_token.rb +19 -0
- data/lib/remit/operations/fund_prepaid.rb +33 -0
- data/lib/remit/operations/get_account_activity.rb +31 -0
- data/lib/remit/operations/get_account_balance.rb +32 -0
- data/lib/remit/operations/get_all_credit_instruments.rb +20 -0
- data/lib/remit/operations/get_all_prepaid_instruments.rb +20 -0
- data/lib/remit/operations/get_debt_balance.rb +28 -0
- data/lib/remit/operations/get_outstanding_debt_balance.rb +25 -0
- data/lib/remit/operations/get_payment_instruction.rb +23 -0
- data/lib/remit/operations/get_prepaid_balance.rb +27 -0
- data/lib/remit/operations/get_recipient_verification_status.rb +25 -0
- data/lib/remit/operations/get_token_by_caller.rb +23 -0
- data/lib/remit/operations/get_token_usage.rb +22 -0
- data/lib/remit/operations/get_tokens.rb +24 -0
- data/lib/remit/operations/get_total_prepaid_liability.rb +26 -0
- data/lib/remit/operations/get_transaction.rb +18 -0
- data/lib/remit/operations/get_transaction_status.rb +28 -0
- data/lib/remit/operations/install_payment_instruction.rb +29 -0
- data/lib/remit/operations/pay.rb +31 -0
- data/lib/remit/operations/refund.rb +46 -0
- data/lib/remit/operations/reserve.rb +28 -0
- data/lib/remit/operations/settle.rb +21 -0
- data/lib/remit/operations/settle_debt.rb +28 -0
- data/lib/remit/operations/subscribe_for_caller_notification.rb +20 -0
- data/lib/remit/operations/unsubscribe_for_caller_notification.rb +19 -0
- data/lib/remit/operations/write_off_debt.rb +26 -0
- data/lib/remit/pipeline_response.rb +20 -0
- 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 +42 -0
- data/spec/integrations/get_tokens_spec.rb +39 -0
- data/spec/integrations/integrations_helper.rb +15 -0
- data/spec/integrations/ipn_request_spec.rb +40 -0
- 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 +85 -0
- 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 +181 -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 +112 -0
- 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 +25 -0
- data/spec/units/write_off_debt_spec.rb +41 -0
- metadata +236 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
# Scraped and categorized from http://docs.amazonwebservices.com/AmazonFPS/\
|
2
|
+
# 2007-01-08/FPSDeveloperGuide/index.html?ErrorCodesTable.html. You can use
|
3
|
+
# these categories to specify default error handling in your application such
|
4
|
+
# as asking users to retry or sending an exception email.
|
5
|
+
module Remit::ErrorCodes
|
6
|
+
class << self
|
7
|
+
def sender_error?(code)
|
8
|
+
SENDER.include? code.to_sym
|
9
|
+
end
|
10
|
+
|
11
|
+
def recipient_error?(code)
|
12
|
+
RECIPIENT.include? code.to_sym
|
13
|
+
end
|
14
|
+
|
15
|
+
def caller_error?(code)
|
16
|
+
CALLER.include?(code.to_sym)
|
17
|
+
end
|
18
|
+
|
19
|
+
def amazon_error?(code)
|
20
|
+
AMAZON.include? code.to_sym
|
21
|
+
end
|
22
|
+
|
23
|
+
def api_error?(code)
|
24
|
+
API.include? code.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
def unknown_error?(code)
|
28
|
+
UNKNOWN.include? code.to_sym
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
SENDER = [
|
33
|
+
:InactiveAccount_Sender, # The sender's account is in suspended or closed state.
|
34
|
+
:InactiveInstrument, # The payment instrument used for this transaction is no longer active.
|
35
|
+
:InstrumentExpired, # The prepaid or the postpaid instrument has expired.
|
36
|
+
:InstrumentNotActive, # The prepaid or postpaid instrument used in the transaction is not active.
|
37
|
+
:InvalidAccountState_Sender, # Sender account cannot participate in the transaction.
|
38
|
+
:InvalidInstrumentForAccountType, # The sender account can use only credit cards
|
39
|
+
:InvalidInstrumentState, # The prepaid or credit instrument should be active
|
40
|
+
:InvalidTokenId_Sender, # The send token specified is either invalid or canceled or the token is not active.
|
41
|
+
:PaymentInstrumentNotCC, # The payment method specified in the transaction is not a credit card. You can only use a credit card for this transaction.
|
42
|
+
:PaymentInstrumentMissing, # There needs to be a payment instrument defined in the token which defines the payment method.
|
43
|
+
:TokenNotActive_Sender, # The sender token is canceled.
|
44
|
+
:UnverifiedAccount_Sender, # The sender's account must have a verified U.S. credit card or a verified U.S bank account before this transaction can be initiated
|
45
|
+
:UnverifiedBankAccount, # A verified bank account should be used for this transaction
|
46
|
+
:UnverifiedEmailAddress_Sender, # The sender account must have a verified e-mail address for this payment
|
47
|
+
]
|
48
|
+
|
49
|
+
RECIPIENT = [
|
50
|
+
:InactiveAccount_Recipient, # The recipient's account is in suspended or closed state.
|
51
|
+
:InvalidAccountState_Recipient, # Recipient account cannot participate in the transaction
|
52
|
+
:InvalidRecipientRoleForAccountType, # The recipient account is not allowed to receive payments
|
53
|
+
:InvalidRecipientForCCTransaction, # This account cannot receive credit card payments.
|
54
|
+
:InvalidTokenId_Recipient, # The recipient token specified is either invalid or canceled.
|
55
|
+
:TokenNotActive_Recipient, # The recipient token is canceled.
|
56
|
+
:UnverifiedAccount_Recipient, # The recipient's account must have a verified bank account or a credit card before this transaction can be initiated.
|
57
|
+
:UnverifiedEmailAddress_Recipient, # The recipient account must have a verified e-mail address for receiving payments.
|
58
|
+
]
|
59
|
+
|
60
|
+
CALLER = [
|
61
|
+
:InactiveAccount_Caller, # The caller's account is in suspended or closed state.
|
62
|
+
:InvalidAccountState_Caller, # The caller account cannot participate in the transaction
|
63
|
+
:InvalidTokenId_Caller, # The caller token specified is either invalid or canceled or the specified token is not active.
|
64
|
+
:TokenNotActive_Caller, # The caller token is canceled.
|
65
|
+
:UnverifiedEmailAddress_Caller, # The caller account must have a verified e-mail address
|
66
|
+
]
|
67
|
+
|
68
|
+
AMAZON = [
|
69
|
+
:InternalError # A retriable error that happens due to some transient problem in the system.
|
70
|
+
]
|
71
|
+
|
72
|
+
# bad syntax or logic
|
73
|
+
API = [
|
74
|
+
:AmountOutOfRange, # The transaction amount is more than the allowed range.
|
75
|
+
:BadRule, # One of the GK constructs is not well defined
|
76
|
+
:CannotSpecifyUsageForSingleUseToken, # Token usages cannot be specified for a single use token.
|
77
|
+
:ConcurrentModification, # A retriable error can happen due to concurrent modification of data by two processes.
|
78
|
+
:DuplicateRequest, # A different request associated with this caller reference already exists.
|
79
|
+
:IncompatibleTokens, # The transaction could not be completed because the tokens have incompatible payment instructions.
|
80
|
+
:InstrumentAccessDenied, # The external calling application is not the recipient for this postpaid or prepaid instrument. The caller should be the liability holder
|
81
|
+
:InvalidCallerReference, # The CallerReferece does not have a token associated with it.
|
82
|
+
:InvalidDateRange, # The end date specified is before the start date or the start date is in the future.
|
83
|
+
:InvalidEvent, # The event specified was not subscribed using the SubscribeForCallerNotification operation.
|
84
|
+
:InvalidParams, # One or more parameters in the request is invalid.
|
85
|
+
:InvalidPaymentInstrument, # The payment method used in the transaction is invalid.
|
86
|
+
:InvalidPaymentMethod, # Payment method specified in the GK construct is invalid.
|
87
|
+
:InvalidSenderRoleForAccountType, # This token cannot be used for this operation.
|
88
|
+
:InvalidTokenId, # The token that you are trying to cancel was not installed by you.
|
89
|
+
:InvalidTokenType, # Invalid operation performed on the token. Example, getting the token usage information on a single use token.
|
90
|
+
:InvalidTransactionId, # The specified transaction could not be found or the caller did not execute the transaction or this is not a Pay or Reserve call.
|
91
|
+
:InvalidTransactionState, # The transaction is not completed or it has been temporarily failed.
|
92
|
+
:InvalidUsageDuration, # The duration cannot be less than one hour.
|
93
|
+
:InvalidUsageLimitCount, # The usage count is null or empty.
|
94
|
+
:InvalidUsageStartTime, # The start time specified for the token is not valid.
|
95
|
+
:InvalidUsageType, # The usage type specified is invalid.
|
96
|
+
:OriginalTransactionIncomplete, # The original transaction is still in progress.
|
97
|
+
:OriginalTransactionFailed, # The original transaction has failed
|
98
|
+
:PaymentMethodNotDefined, # Payment method is not defined in the transaction.
|
99
|
+
:RefundAmountExceeded, # The refund amount is more than the refundable amount.
|
100
|
+
:SameTokenIdUsedMultipleTimes, # This token is already used in earlier transactions.
|
101
|
+
:SenderNotOriginalRecipient, # The sender in the refund transaction is not the recipient of the original transaction.
|
102
|
+
:SettleAmountGreaterThanReserveAmount, # The amount being settled is greater than the reserved amount.
|
103
|
+
:TransactionDenied, # This transaction is not allowed.
|
104
|
+
:TransactionExpired, # Returned when the Caller attempts to explicitly retry a transaction that is temporarily declined and is in queue for implicit retry.
|
105
|
+
:TransactionFullyRefundedAlready, # The complete refund for this transaction is already completed
|
106
|
+
:TransactionTypeNotRefundable, # You cannot refund this transaction.
|
107
|
+
:TokenAccessDenied, # Permission is denied to cancel the token.
|
108
|
+
:TokenUsageError, # The token usage limit is exceeded.
|
109
|
+
:UsageNotDefined, # For a multi-use token or a recurring token the usage limits are not specified in the GateKeeper text.
|
110
|
+
]
|
111
|
+
|
112
|
+
# these errors don't specify who is at fault
|
113
|
+
UNKNOWN = [
|
114
|
+
:InvalidAccountState, # The account is either suspended or closed. Payment instructions cannot be installed on this account.
|
115
|
+
:InsufficientBalance, # The sender, caller, or recipient's account balance has insufficient funds to complete the transaction.
|
116
|
+
:AccountLimitsExceeded, # The spending or the receiving limit on the account is exceeded
|
117
|
+
]
|
118
|
+
end
|
@@ -0,0 +1,286 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
require 'remit/common'
|
4
|
+
|
5
|
+
module Remit
|
6
|
+
module GetPipeline
|
7
|
+
class Pipeline
|
8
|
+
|
9
|
+
@parameters = []
|
10
|
+
attr_reader :parameters
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Create the parameters hash for the subclass.
|
14
|
+
def inherited(subclass) #:nodoc:
|
15
|
+
subclass.instance_variable_set('@parameters', [])
|
16
|
+
end
|
17
|
+
|
18
|
+
def parameter(name)
|
19
|
+
attr_accessor name
|
20
|
+
@parameters << name
|
21
|
+
end
|
22
|
+
|
23
|
+
def convert_key(key)
|
24
|
+
key = key.to_s
|
25
|
+
if key == 'return_url'
|
26
|
+
:returnURL
|
27
|
+
else
|
28
|
+
key.gsub(/_(.)/) { $1.upcase }.to_sym
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns a hash of all of the parameters for this request, including
|
33
|
+
# those that are inherited.
|
34
|
+
def parameters #:nodoc:
|
35
|
+
(superclass.respond_to?(:parameters) ? superclass.parameters : []) + @parameters
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :api
|
40
|
+
attr_reader :pipeline_url
|
41
|
+
|
42
|
+
parameter :caller_key
|
43
|
+
parameter :cobranding_style
|
44
|
+
parameter :cobranding_url
|
45
|
+
parameter :pipeline_name
|
46
|
+
parameter :return_url
|
47
|
+
parameter :signature
|
48
|
+
parameter :signature_version
|
49
|
+
parameter :signature_method
|
50
|
+
parameter :version
|
51
|
+
parameter :website_description
|
52
|
+
|
53
|
+
def initialize(api, pipeline, options)
|
54
|
+
@api = api
|
55
|
+
@pipeline_url = pipeline
|
56
|
+
|
57
|
+
options.each do |k,v|
|
58
|
+
self.send("#{k}=", v)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def url
|
63
|
+
uri = URI.parse(self.pipeline_url)
|
64
|
+
|
65
|
+
query = {}
|
66
|
+
self.class.parameters.each do |p|
|
67
|
+
val = self.send(p)
|
68
|
+
|
69
|
+
# Convert Time values to seconds from Epoch
|
70
|
+
val = val.to_i if val.is_a?(Time)
|
71
|
+
|
72
|
+
query[self.class.convert_key(p)] = val
|
73
|
+
end
|
74
|
+
|
75
|
+
# Remove any unused optional parameters
|
76
|
+
query.reject! { |key, value| value.nil? }
|
77
|
+
|
78
|
+
uri.query = SignedQuery.new(self.pipeline_url, self.api.secret_key, query).to_s
|
79
|
+
uri.to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
module ValidityPeriod
|
85
|
+
def self.included(base)
|
86
|
+
base.class_eval do
|
87
|
+
parameter :validity_expiry # Time or seconds from Epoch
|
88
|
+
parameter :validity_start # Time or seconds from Epoch
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
module UsageLimits
|
94
|
+
def self.included(base)
|
95
|
+
base.class_eval do
|
96
|
+
parameter :usage_limit_type_1
|
97
|
+
parameter :usage_limit_period_1
|
98
|
+
parameter :usage_limit_value_1
|
99
|
+
parameter :usage_limit_type_2
|
100
|
+
parameter :usage_limit_period_2
|
101
|
+
parameter :usage_limit_value_2
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class RecipientPipeline < Pipeline
|
107
|
+
parameter :caller_reference
|
108
|
+
parameter :max_fixed_fee
|
109
|
+
parameter :max_variable_fee
|
110
|
+
parameter :payment_method
|
111
|
+
parameter :recipient_pays_fee
|
112
|
+
# BJM: missing??
|
113
|
+
# PHB: Amazon only documents this parameter as being part of responses, never as part of a request.
|
114
|
+
# Not sure if it is a documentation oversight.
|
115
|
+
# I am sure the documentation is terrible (with four fingers pointed back at me).
|
116
|
+
parameter :payment_reason
|
117
|
+
|
118
|
+
include ValidityPeriod
|
119
|
+
|
120
|
+
def pipeline_name
|
121
|
+
Remit::PipelineName::RECIPIENT
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class SenderPipeline < Pipeline
|
126
|
+
# I think these should be moved down to the subclasses, or perhaps, all sender pipeline requests
|
127
|
+
parameter :address_name
|
128
|
+
parameter :address_line_1
|
129
|
+
parameter :address_line_2
|
130
|
+
parameter :city
|
131
|
+
parameter :state
|
132
|
+
parameter :zip
|
133
|
+
parameter :phone_number
|
134
|
+
|
135
|
+
def pipeline_name
|
136
|
+
raise NotImplementedError, 'SenderPipeline is abstract. Use a concrete subclass.'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class SingleUsePipeline < SenderPipeline
|
141
|
+
parameter :caller_reference
|
142
|
+
parameter :collect_shipping_address
|
143
|
+
parameter :currency_code
|
144
|
+
parameter :discount
|
145
|
+
parameter :gift_wrapping
|
146
|
+
parameter :handling
|
147
|
+
parameter :item_total
|
148
|
+
parameter :payment_method
|
149
|
+
parameter :payment_reason
|
150
|
+
parameter :recipient_token
|
151
|
+
parameter :reserve
|
152
|
+
parameter :shipping
|
153
|
+
parameter :tax
|
154
|
+
parameter :transaction_amount
|
155
|
+
|
156
|
+
def pipeline_name
|
157
|
+
Remit::PipelineName::SINGLE_USE
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class MultiUsePipeline < SenderPipeline
|
162
|
+
parameter :amount_type
|
163
|
+
parameter :caller_reference
|
164
|
+
parameter :collect_shipping_address
|
165
|
+
parameter :currency_code
|
166
|
+
parameter :global_amount_limit
|
167
|
+
parameter :is_recipient_cobranding
|
168
|
+
parameter :payment_method
|
169
|
+
parameter :payment_reason
|
170
|
+
parameter :recipient_token_list
|
171
|
+
parameter :transaction_amount
|
172
|
+
|
173
|
+
include ValidityPeriod
|
174
|
+
include UsageLimits
|
175
|
+
|
176
|
+
def pipeline_name
|
177
|
+
Remit::PipelineName::MULTI_USE
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
class EditTokenPipeline < Pipeline
|
182
|
+
parameter :caller_reference
|
183
|
+
parameter :payment_method
|
184
|
+
parameter :token_id
|
185
|
+
|
186
|
+
def pipeline_name
|
187
|
+
Remit::PipelineName::EDIT_TOKEN
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class RecurringUsePipeline < SenderPipeline
|
192
|
+
parameter :caller_reference
|
193
|
+
parameter :collect_shipping_address
|
194
|
+
parameter :currency_code
|
195
|
+
parameter :is_recipient_cobranding
|
196
|
+
parameter :payment_method
|
197
|
+
parameter :payment_reason
|
198
|
+
parameter :recipient_token
|
199
|
+
parameter :recurring_period
|
200
|
+
parameter :transaction_amount
|
201
|
+
|
202
|
+
include ValidityPeriod
|
203
|
+
|
204
|
+
def pipeline_name
|
205
|
+
Remit::PipelineName::RECURRING
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
class PostpaidPipeline < SenderPipeline
|
210
|
+
parameter :caller_reference_sender
|
211
|
+
parameter :caller_reference_settlement
|
212
|
+
parameter :collect_shipping_address
|
213
|
+
parameter :credit_limit
|
214
|
+
parameter :currency_code
|
215
|
+
parameter :global_amount_limit
|
216
|
+
parameter :payment_method
|
217
|
+
parameter :payment_reason
|
218
|
+
|
219
|
+
include ValidityPeriod
|
220
|
+
include UsageLimits
|
221
|
+
|
222
|
+
def pipeline_name
|
223
|
+
Remit::PipelineName::SETUP_POSTPAID
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
class PrepaidPipeline < SenderPipeline
|
228
|
+
parameter :caller_reference_funding
|
229
|
+
parameter :caller_reference_sender
|
230
|
+
parameter :collect_shipping_address
|
231
|
+
parameter :currency_code
|
232
|
+
parameter :funding_amount
|
233
|
+
parameter :payment_method
|
234
|
+
parameter :payment_reason
|
235
|
+
|
236
|
+
include ValidityPeriod
|
237
|
+
|
238
|
+
def pipeline_name
|
239
|
+
Remit::PipelineName::SETUP_PREPAID
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class EditTokenPipeline < Pipeline
|
244
|
+
parameter :caller_reference
|
245
|
+
parameter :token_id
|
246
|
+
parameter :payment_method
|
247
|
+
|
248
|
+
def pipeline_name
|
249
|
+
Remit::PipelineName::EDIT_TOKEN
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def get_single_use_pipeline(options)
|
254
|
+
get_pipeline(Remit::GetPipeline::SingleUsePipeline, options)
|
255
|
+
end
|
256
|
+
def get_multi_use_pipeline(options)
|
257
|
+
get_pipeline(Remit::GetPipeline::MultiUsePipeline, options)
|
258
|
+
end
|
259
|
+
def get_recipient_pipeline(options)
|
260
|
+
get_pipeline(Remit::GetPipeline::RecipientPipeline, options)
|
261
|
+
end
|
262
|
+
def get_recurring_use_pipeline(options)
|
263
|
+
get_pipeline(Remit::GetPipeline::RecurringUsePipeline, options)
|
264
|
+
end
|
265
|
+
def get_postpaid_pipeline(options)
|
266
|
+
get_pipeline(Remit::GetPipeline::PostpaidPipeline, options)
|
267
|
+
end
|
268
|
+
def get_prepaid_pipeline(options)
|
269
|
+
get_pipeline(Remit::GetPipeline::PrepaidPipeline, options)
|
270
|
+
end
|
271
|
+
def get_edit_token_pipeline(options)
|
272
|
+
get_pipeline(Remit::GetPipeline::EditTokenPipeline, options)
|
273
|
+
end
|
274
|
+
|
275
|
+
def get_pipeline(pipeline_subclass, options)
|
276
|
+
# TODO: How does @pipeline_url work here?
|
277
|
+
# instance variable is setup in initializer of class.
|
278
|
+
pipeline_subclass.new(self, @pipeline_url, {
|
279
|
+
:caller_key => @access_key,
|
280
|
+
:signature_version=>Remit::API::SIGNATURE_VERSION,
|
281
|
+
:signature_method=>Remit::API::SIGNATURE_METHOD,
|
282
|
+
:version=>Remit::API::PIPELINE_VERSION
|
283
|
+
}.merge(options))
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'remit/common'
|
2
|
+
|
3
|
+
module Remit
|
4
|
+
|
5
|
+
class InboundRequest
|
6
|
+
include ConvertKey
|
7
|
+
extend SignatureUtilsForOutbound
|
8
|
+
|
9
|
+
protected :convert_key
|
10
|
+
|
11
|
+
attr_reader :supplied_signature
|
12
|
+
attr_reader :allow_sigv1
|
13
|
+
|
14
|
+
# BJM: need to access sometimes from the app
|
15
|
+
attr_reader :hash_params
|
16
|
+
# signature key name
|
17
|
+
SIGNATURE_KEY = 'signature'
|
18
|
+
|
19
|
+
##
|
20
|
+
# +request_url+ is the full request path up to the query string, as from request.url in the controller
|
21
|
+
# +params+ is the full params hash from the controller
|
22
|
+
# +client+ is a fully instantiated Remit::API with access keys and sandbox settings
|
23
|
+
#
|
24
|
+
# Only clean params hash is params is sent as a hash.
|
25
|
+
# Assume caller has cleaned string if string is sent as params
|
26
|
+
def initialize(request_url, params, client, options = {})
|
27
|
+
if params.is_a?(String)
|
28
|
+
@string_params = params
|
29
|
+
@hash_params = Hash.from_url_params(params)
|
30
|
+
else
|
31
|
+
unless options.kind_of?(Hash)
|
32
|
+
options = {}
|
33
|
+
end
|
34
|
+
options[:skip_param_keys] ||= []
|
35
|
+
#this is a bit of helpful sugar for rails framework users
|
36
|
+
options[:skip_param_keys] |= ['action','controller']
|
37
|
+
|
38
|
+
if params.respond_to?(:reject)
|
39
|
+
params.reject! {|key, val| options[:skip_param_keys].include?(key) }
|
40
|
+
else
|
41
|
+
params = {}
|
42
|
+
end
|
43
|
+
@hash_params = params
|
44
|
+
@string_params = InboundRequest.get_http_params(@hash_params)
|
45
|
+
end
|
46
|
+
#puts "Params are: #{params.inspect}"
|
47
|
+
@request_url = request_url
|
48
|
+
@client = client
|
49
|
+
@supplied_signature = @hash_params[self.class::SIGNATURE_KEY]
|
50
|
+
@allow_sigv1 = options[:allow_sigv1] || false
|
51
|
+
end
|
52
|
+
|
53
|
+
def valid?
|
54
|
+
if @hash_params['signatureVersion'].to_i == 2
|
55
|
+
#puts "\nhash_params: #{@hash_params.inspect}\n"
|
56
|
+
#puts "\nstring_params: #{@string_params.inspect}\n"
|
57
|
+
return false unless InboundRequest.check_parameters(@hash_params)
|
58
|
+
verify_request = Remit::VerifySignature::Request.new(
|
59
|
+
:url_end_point => @request_url,#InboundRequest.urlencode(@request_url),
|
60
|
+
:version => Remit::API::API_VERSION,
|
61
|
+
:http_parameters => @string_params
|
62
|
+
)
|
63
|
+
#puts "\nurl_end_point#{@request_url.inspect}\n"
|
64
|
+
#puts "\nhttp_parameters: #{verify_request.http_parameters.inspect}\n"
|
65
|
+
result = @client.verify_signature(verify_request)
|
66
|
+
#puts "\nresult: #{result.raw.inspect}\n"
|
67
|
+
result.verify_signature_result.verification_status == 'Success'
|
68
|
+
elsif @hash_params['signatureVersion'].nil? and self.allow_sigv1
|
69
|
+
self.supplied_signature == Remit::API.signature_v1(URI.parse(@request_url).path, @hash_params, @client.secret_key).gsub('+', ' ')
|
70
|
+
else
|
71
|
+
false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def method_missing(method, *args, &block) #:nodoc:
|
76
|
+
return @hash_params[method.to_s] if @hash_params.has_key?(method.to_s)
|
77
|
+
return @hash_params[method.to_sym] if @hash_params.has_key?(method.to_sym)
|
78
|
+
key = self.convert_key(method)
|
79
|
+
return @hash_params[key] if @hash_params.has_key?(key)
|
80
|
+
return @hash_params[key.to_s] if @hash_params.has_key?(key.to_s)
|
81
|
+
super
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|