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/lib/remit/get_pipeline.rb
CHANGED
@@ -5,6 +5,7 @@ require 'remit/common'
|
|
5
5
|
module Remit
|
6
6
|
module GetPipeline
|
7
7
|
class Pipeline
|
8
|
+
|
8
9
|
@parameters = []
|
9
10
|
attr_reader :parameters
|
10
11
|
|
@@ -20,7 +21,12 @@ module Remit
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def convert_key(key)
|
23
|
-
key
|
24
|
+
key = key.to_s
|
25
|
+
if key == 'return_url'
|
26
|
+
:returnURL
|
27
|
+
else
|
28
|
+
key.gsub(/_(.)/) { $1.upcase }.to_sym
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
# Returns a hash of all of the parameters for this request, including
|
@@ -31,31 +37,30 @@ module Remit
|
|
31
37
|
end
|
32
38
|
|
33
39
|
attr_reader :api
|
34
|
-
|
40
|
+
attr_reader :pipeline_url
|
41
|
+
|
42
|
+
parameter :caller_key
|
43
|
+
parameter :cobranding_style
|
44
|
+
parameter :cobranding_url
|
35
45
|
parameter :pipeline_name
|
36
46
|
parameter :return_url
|
37
|
-
parameter :
|
38
|
-
parameter :version
|
47
|
+
parameter :signature
|
39
48
|
parameter :signature_version
|
40
|
-
parameter :
|
41
|
-
parameter :
|
42
|
-
parameter :
|
43
|
-
parameter :city
|
44
|
-
parameter :state
|
45
|
-
parameter :zip
|
46
|
-
parameter :country
|
47
|
-
parameter :phone_number
|
49
|
+
parameter :signature_method
|
50
|
+
parameter :version
|
51
|
+
parameter :website_description
|
48
52
|
|
49
|
-
def initialize(api, options)
|
53
|
+
def initialize(api, pipeline, options)
|
50
54
|
@api = api
|
51
|
-
|
55
|
+
@pipeline_url = pipeline
|
56
|
+
|
52
57
|
options.each do |k,v|
|
53
58
|
self.send("#{k}=", v)
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
57
62
|
def url
|
58
|
-
uri = URI.parse(
|
63
|
+
uri = URI.parse(self.pipeline_url)
|
59
64
|
|
60
65
|
query = {}
|
61
66
|
self.class.parameters.each do |p|
|
@@ -64,143 +69,218 @@ module Remit
|
|
64
69
|
# Convert Time values to seconds from Epoch
|
65
70
|
val = val.to_i if val.is_a?(Time)
|
66
71
|
|
67
|
-
query[self.class.convert_key(p
|
72
|
+
query[self.class.convert_key(p)] = val
|
68
73
|
end
|
69
74
|
|
70
75
|
# Remove any unused optional parameters
|
71
|
-
query.reject! { |key, value| value.nil?
|
76
|
+
query.reject! { |key, value| value.nil? }
|
72
77
|
|
73
|
-
uri.query = SignedQuery.new(
|
78
|
+
uri.query = SignedQuery.new(self.pipeline_url, self.api.secret_key, query).to_s
|
74
79
|
uri.to_s
|
75
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
|
76
104
|
end
|
77
105
|
|
78
|
-
class
|
106
|
+
class RecipientPipeline < Pipeline
|
79
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).
|
80
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
|
81
148
|
parameter :payment_method
|
82
|
-
parameter :
|
149
|
+
parameter :payment_reason
|
83
150
|
parameter :recipient_token
|
151
|
+
parameter :reserve
|
152
|
+
parameter :shipping
|
153
|
+
parameter :tax
|
154
|
+
parameter :transaction_amount
|
155
|
+
parameter :collect_email_address
|
84
156
|
|
85
157
|
def pipeline_name
|
86
158
|
Remit::PipelineName::SINGLE_USE
|
87
159
|
end
|
88
160
|
end
|
89
161
|
|
90
|
-
class MultiUsePipeline <
|
162
|
+
class MultiUsePipeline < SenderPipeline
|
163
|
+
parameter :amount_type
|
91
164
|
parameter :caller_reference
|
165
|
+
parameter :collect_shipping_address
|
166
|
+
parameter :currency_code
|
167
|
+
parameter :global_amount_limit
|
168
|
+
parameter :is_recipient_cobranding
|
169
|
+
parameter :payment_method
|
92
170
|
parameter :payment_reason
|
93
171
|
parameter :recipient_token_list
|
94
|
-
parameter :amount_type
|
95
172
|
parameter :transaction_amount
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
parameter :global_amount_limit
|
100
|
-
parameter :usage_limit_type_1
|
101
|
-
parameter :usage_limit_period_1
|
102
|
-
parameter :usage_limit_value_1
|
103
|
-
parameter :usage_limit_type_2
|
104
|
-
parameter :usage_limit_period_2
|
105
|
-
parameter :usage_limit_value_2
|
106
|
-
parameter :is_recipient_cobranding
|
173
|
+
|
174
|
+
include ValidityPeriod
|
175
|
+
include UsageLimits
|
107
176
|
|
108
177
|
def pipeline_name
|
109
178
|
Remit::PipelineName::MULTI_USE
|
110
179
|
end
|
111
180
|
end
|
112
|
-
|
113
|
-
class
|
181
|
+
|
182
|
+
class EditTokenPipeline < Pipeline
|
114
183
|
parameter :caller_reference
|
115
|
-
parameter :validity_start # Time or seconds from Epoch
|
116
|
-
parameter :validity_expiry # Time or seconds from Epoch
|
117
184
|
parameter :payment_method
|
118
|
-
parameter :
|
119
|
-
|
120
|
-
parameter :max_variable_fee
|
121
|
-
parameter :max_fixed_fee
|
122
|
-
|
185
|
+
parameter :token_id
|
186
|
+
|
123
187
|
def pipeline_name
|
124
|
-
Remit::PipelineName::
|
188
|
+
Remit::PipelineName::EDIT_TOKEN
|
125
189
|
end
|
126
190
|
end
|
127
191
|
|
128
|
-
class RecurringUsePipeline <
|
192
|
+
class RecurringUsePipeline < SenderPipeline
|
129
193
|
parameter :caller_reference
|
194
|
+
parameter :collect_shipping_address
|
195
|
+
parameter :currency_code
|
196
|
+
parameter :is_recipient_cobranding
|
197
|
+
parameter :payment_method
|
130
198
|
parameter :payment_reason
|
131
199
|
parameter :recipient_token
|
200
|
+
parameter :recurring_period
|
132
201
|
parameter :transaction_amount
|
133
|
-
|
134
|
-
|
135
|
-
parameter :payment_method
|
136
|
-
parameter :recurring_period
|
202
|
+
|
203
|
+
include ValidityPeriod
|
137
204
|
|
138
205
|
def pipeline_name
|
139
206
|
Remit::PipelineName::RECURRING
|
140
207
|
end
|
141
208
|
end
|
142
209
|
|
143
|
-
class PostpaidPipeline <
|
210
|
+
class PostpaidPipeline < SenderPipeline
|
144
211
|
parameter :caller_reference_sender
|
145
212
|
parameter :caller_reference_settlement
|
146
|
-
parameter :
|
147
|
-
parameter :payment_method
|
148
|
-
parameter :validity_start # Time or seconds from Epoch
|
149
|
-
parameter :validity_expiry # Time or seconds from Epoch
|
213
|
+
parameter :collect_shipping_address
|
150
214
|
parameter :credit_limit
|
215
|
+
parameter :currency_code
|
151
216
|
parameter :global_amount_limit
|
152
|
-
parameter :
|
153
|
-
parameter :
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
parameter :usage_limit_value2
|
217
|
+
parameter :payment_method
|
218
|
+
parameter :payment_reason
|
219
|
+
|
220
|
+
include ValidityPeriod
|
221
|
+
include UsageLimits
|
158
222
|
|
159
223
|
def pipeline_name
|
160
224
|
Remit::PipelineName::SETUP_POSTPAID
|
161
225
|
end
|
162
226
|
end
|
163
227
|
|
164
|
-
class PrepaidPipeline <
|
165
|
-
parameter :caller_reference_sender
|
228
|
+
class PrepaidPipeline < SenderPipeline
|
166
229
|
parameter :caller_reference_funding
|
167
|
-
parameter :
|
168
|
-
parameter :
|
169
|
-
parameter :
|
170
|
-
parameter :validity_expiry # Time or seconds from Epoch
|
230
|
+
parameter :caller_reference_sender
|
231
|
+
parameter :collect_shipping_address
|
232
|
+
parameter :currency_code
|
171
233
|
parameter :funding_amount
|
234
|
+
parameter :payment_method
|
235
|
+
parameter :payment_reason
|
236
|
+
|
237
|
+
include ValidityPeriod
|
238
|
+
|
172
239
|
def pipeline_name
|
173
240
|
Remit::PipelineName::SETUP_PREPAID
|
174
241
|
end
|
175
242
|
end
|
176
|
-
|
177
|
-
|
178
|
-
|
243
|
+
|
244
|
+
class EditTokenPipeline < Pipeline
|
245
|
+
parameter :caller_reference
|
246
|
+
parameter :token_id
|
247
|
+
parameter :payment_method
|
248
|
+
|
249
|
+
def pipeline_name
|
250
|
+
Remit::PipelineName::EDIT_TOKEN
|
251
|
+
end
|
179
252
|
end
|
180
253
|
|
254
|
+
def get_single_use_pipeline(options)
|
255
|
+
get_pipeline(Remit::GetPipeline::SingleUsePipeline, options)
|
256
|
+
end
|
181
257
|
def get_multi_use_pipeline(options)
|
182
|
-
|
258
|
+
get_pipeline(Remit::GetPipeline::MultiUsePipeline, options)
|
183
259
|
end
|
184
|
-
|
185
260
|
def get_recipient_pipeline(options)
|
186
|
-
|
261
|
+
get_pipeline(Remit::GetPipeline::RecipientPipeline, options)
|
187
262
|
end
|
188
|
-
|
189
263
|
def get_recurring_use_pipeline(options)
|
190
|
-
|
264
|
+
get_pipeline(Remit::GetPipeline::RecurringUsePipeline, options)
|
191
265
|
end
|
192
|
-
|
193
266
|
def get_postpaid_pipeline(options)
|
194
|
-
|
267
|
+
get_pipeline(Remit::GetPipeline::PostpaidPipeline, options)
|
195
268
|
end
|
196
|
-
|
197
269
|
def get_prepaid_pipeline(options)
|
198
|
-
|
270
|
+
get_pipeline(Remit::GetPipeline::PrepaidPipeline, options)
|
199
271
|
end
|
200
|
-
|
272
|
+
def get_edit_token_pipeline(options)
|
273
|
+
get_pipeline(Remit::GetPipeline::EditTokenPipeline, options)
|
274
|
+
end
|
275
|
+
|
201
276
|
def get_pipeline(pipeline_subclass, options)
|
202
|
-
|
203
|
-
|
277
|
+
# TODO: How does @pipeline_url work here?
|
278
|
+
# instance variable is setup in initializer of class.
|
279
|
+
pipeline_subclass.new(self, @pipeline_url, {
|
280
|
+
:caller_key => @access_key,
|
281
|
+
:signature_version=>Remit::API::SIGNATURE_VERSION,
|
282
|
+
:signature_method=>Remit::API::SIGNATURE_METHOD,
|
283
|
+
:version=>Remit::API::PIPELINE_VERSION
|
204
284
|
}.merge(options))
|
205
285
|
end
|
206
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
|
data/lib/remit/ipn_request.rb
CHANGED
@@ -1,43 +1,8 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'openssl/digest'
|
3
|
-
|
4
1
|
module Remit
|
5
|
-
# Encapsulates the logic for IPN request validation and attribute retrieval.
|
6
|
-
#
|
7
|
-
# Note: if your responses from Amazon are not validating, please pass the
|
8
|
-
# :version parameter to your original CBUI request.
|
9
|
-
class IpnRequest
|
10
|
-
# Signature key name used by AmazonFPS IPNs
|
11
|
-
SIGNATURE_KEY = 'signature'
|
12
|
-
|
13
|
-
# +params+ should be your controllers request parameters.
|
14
|
-
def initialize(params, uri, access_key, secret_key)
|
15
|
-
raise ArgumentError, "Expected the request params hash, received: #{params.inspect}" unless params.kind_of?(Hash)
|
16
|
-
@params = strip_keys_from(params, 'action', 'controller')
|
17
|
-
@uri = URI.parse(uri)
|
18
|
-
@url_end_point = @uri.scheme + '://' + @uri.host + @uri.path
|
19
|
-
@access_key = access_key
|
20
|
-
@secret_key = secret_key
|
21
|
-
end
|
22
|
-
|
23
|
-
def valid?
|
24
|
-
utils = Amazon::FPS::SignatureUtilsForOutbound.new(@access_key, @secret_key);
|
25
|
-
utils.validate_request(:parameters => @params, :url_end_point => @url_end_point, :http_method => "GET")
|
26
|
-
end
|
27
2
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
super(method, *args)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def strip_keys_from(params, *ignore_keys)
|
37
|
-
parsed = params.dup
|
38
|
-
ignore_keys.each { |key| parsed.delete(key) }
|
39
|
-
parsed
|
40
|
-
end
|
41
|
-
private :strip_keys_from
|
3
|
+
class IpnRequest < InboundRequest
|
4
|
+
# signature key name
|
5
|
+
SIGNATURE_KEY = 'signature'
|
42
6
|
end
|
7
|
+
|
43
8
|
end
|