amazon_pay 2.0.0
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.
- checksums.yaml +7 -0
- data/LICENSE +202 -0
- data/NOTICE +9 -0
- data/README.md +428 -0
- data/lib/amazon_pay/client.rb +875 -0
- data/lib/amazon_pay/client_helper.rb +193 -0
- data/lib/amazon_pay/ipn_handler.rb +222 -0
- data/lib/amazon_pay/login.rb +75 -0
- data/lib/amazon_pay/request.rb +114 -0
- data/lib/amazon_pay/response.rb +42 -0
- data/lib/amazon_pay/version.rb +5 -0
- data/lib/amazon_pay.rb +7 -0
- metadata +54 -0
@@ -0,0 +1,875 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module AmazonPay
|
4
|
+
|
5
|
+
# AmazonPay API
|
6
|
+
#
|
7
|
+
# This client allows you to make all the necessary API calls
|
8
|
+
# to integrate with AmazonPay. This client only
|
9
|
+
# uses the standard Ruby library and is not dependant on Rails.
|
10
|
+
class Client
|
11
|
+
|
12
|
+
attr_reader(
|
13
|
+
:merchant_id,
|
14
|
+
:access_key,
|
15
|
+
:secret_key,
|
16
|
+
:sandbox,
|
17
|
+
:currency_code,
|
18
|
+
:region,
|
19
|
+
:platform_id,
|
20
|
+
:throttle,
|
21
|
+
:application_name,
|
22
|
+
:application_version)
|
23
|
+
|
24
|
+
attr_accessor(
|
25
|
+
:sandbox,
|
26
|
+
:proxy_addr,
|
27
|
+
:proxy_port,
|
28
|
+
:proxy_user,
|
29
|
+
:proxy_pass)
|
30
|
+
|
31
|
+
# API keys are located at:
|
32
|
+
# @see https://sellercentral.amazon.com
|
33
|
+
# @param merchant_id [String]
|
34
|
+
# @param access_key [String]
|
35
|
+
# @param secret_key [String]
|
36
|
+
# @optional sandbox [Boolean] Default: false
|
37
|
+
# @optional currency_code [Symbol] Default: :usd
|
38
|
+
# @optional region [Symbol] Default: :na
|
39
|
+
# @optional platform_id [String] Default: nil
|
40
|
+
# @optional throttle [Boolean] Default: true
|
41
|
+
# @optional application_name [String]
|
42
|
+
# @optional application_version [String]
|
43
|
+
# @optional proxy_addr [String]
|
44
|
+
# @optional proxy_port [String]
|
45
|
+
# @optional proxy_user [String]
|
46
|
+
# @optional proxy_pass [String]
|
47
|
+
def initialize(
|
48
|
+
merchant_id,
|
49
|
+
access_key,
|
50
|
+
secret_key,
|
51
|
+
sandbox: false,
|
52
|
+
currency_code: :usd,
|
53
|
+
region: :na,
|
54
|
+
platform_id: nil,
|
55
|
+
throttle: true,
|
56
|
+
application_name: nil,
|
57
|
+
application_version: nil,
|
58
|
+
proxy_addr: :ENV,
|
59
|
+
proxy_port: nil,
|
60
|
+
proxy_user: nil,
|
61
|
+
proxy_pass: nil)
|
62
|
+
|
63
|
+
@merchant_id = merchant_id
|
64
|
+
@access_key = access_key
|
65
|
+
@secret_key = secret_key
|
66
|
+
@currency_code = currency_code.to_s.upcase
|
67
|
+
@sandbox = sandbox
|
68
|
+
@sandbox_str = @sandbox ? 'OffAmazonPayments_Sandbox' : 'OffAmazonPayments'
|
69
|
+
@region = region
|
70
|
+
@mws_endpoint = region_hash[@region] ? region_hash[@region] : raise("Invalid Region Code. (#{@region})")
|
71
|
+
@platform_id = platform_id
|
72
|
+
@throttle = throttle
|
73
|
+
@application_name = application_name
|
74
|
+
@application_version = application_version
|
75
|
+
@proxy_addr = proxy_addr
|
76
|
+
@proxy_port = proxy_port
|
77
|
+
@proxy_user = proxy_user
|
78
|
+
@proxy_pass = proxy_pass
|
79
|
+
|
80
|
+
@default_hash = {
|
81
|
+
'AWSAccessKeyId' => @access_key,
|
82
|
+
'SignatureMethod' => 'HmacSHA256',
|
83
|
+
'SignatureVersion' => '2',
|
84
|
+
'Timestamp' => Time.now.utc.iso8601,
|
85
|
+
'Version' => AmazonPay::API_VERSION
|
86
|
+
}
|
87
|
+
|
88
|
+
@default_hash['PlatformId'] = @platform_id if @platform_id
|
89
|
+
end
|
90
|
+
|
91
|
+
# The GetServiceStatus operation returns the operational status of the AmazonPay API
|
92
|
+
# section of Amazon Marketplace Web Service (Amazon MWS). Status values are GREEN, GREEN_I, YELLOW, and RED.
|
93
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752110
|
94
|
+
def get_service_status
|
95
|
+
parameters = {
|
96
|
+
'Action' => 'GetServiceStatus'
|
97
|
+
}
|
98
|
+
|
99
|
+
operation(parameters, {})
|
100
|
+
end
|
101
|
+
|
102
|
+
# Creates an order reference for the given object
|
103
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751670
|
104
|
+
# @param id [String]
|
105
|
+
# @param id_type [String]
|
106
|
+
# @optional inherit_shipping_address [Boolean]
|
107
|
+
# @optional confirm_now [Boolean]
|
108
|
+
# @optional amount [String] (required when confirm_now is set to true)
|
109
|
+
# @optional currency_code [String]
|
110
|
+
# @optional platform_id [String]
|
111
|
+
# @optional seller_note [String]
|
112
|
+
# @optional seller_order_id [String]
|
113
|
+
# @optional store_name [String]
|
114
|
+
# @optional custom_information [String]
|
115
|
+
# @optional merchant_id [String]
|
116
|
+
# @optional mws_auth_token [String]
|
117
|
+
def create_order_reference_for_id(
|
118
|
+
id,
|
119
|
+
id_type,
|
120
|
+
inherit_shipping_address: nil,
|
121
|
+
confirm_now: nil,
|
122
|
+
amount: nil,
|
123
|
+
currency_code: @currency_code,
|
124
|
+
platform_id: nil,
|
125
|
+
seller_note: nil,
|
126
|
+
seller_order_id: nil,
|
127
|
+
store_name: nil,
|
128
|
+
custom_information: nil,
|
129
|
+
merchant_id: @merchant_id,
|
130
|
+
mws_auth_token: nil)
|
131
|
+
|
132
|
+
parameters = {
|
133
|
+
'Action' => 'CreateOrderReferenceForId',
|
134
|
+
'SellerId' => merchant_id,
|
135
|
+
'Id' => id,
|
136
|
+
'IdType' => id_type
|
137
|
+
}
|
138
|
+
|
139
|
+
optional = {
|
140
|
+
'InheritShippingAddress' => inherit_shipping_address,
|
141
|
+
'ConfirmNow' => confirm_now,
|
142
|
+
'OrderReferenceAttributes.OrderTotal.Amount' => amount,
|
143
|
+
'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code,
|
144
|
+
'OrderReferenceAttributes.PlatformId' => platform_id,
|
145
|
+
'OrderReferenceAttributes.SellerNote' => seller_note,
|
146
|
+
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
|
147
|
+
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
|
148
|
+
'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
|
149
|
+
'MWSAuthToken' => mws_auth_token
|
150
|
+
}
|
151
|
+
|
152
|
+
operation(parameters, optional)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns details about the Billing Agreement object and its current state
|
156
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751690
|
157
|
+
# @param amazon_billing_agreement_id [String]
|
158
|
+
# @optional address_consent_token [String]
|
159
|
+
# @optional merchant_id [String]
|
160
|
+
# @optional mws_auth_token [String]
|
161
|
+
def get_billing_agreement_details(
|
162
|
+
amazon_billing_agreement_id,
|
163
|
+
address_consent_token: nil,
|
164
|
+
merchant_id: @merchant_id,
|
165
|
+
mws_auth_token: nil)
|
166
|
+
|
167
|
+
parameters = {
|
168
|
+
'Action' => 'GetBillingAgreementDetails',
|
169
|
+
'SellerId' => merchant_id,
|
170
|
+
'AmazonBillingAgreementId' => amazon_billing_agreement_id
|
171
|
+
}
|
172
|
+
|
173
|
+
optional = {
|
174
|
+
'AddressConsentToken' => address_consent_token,
|
175
|
+
'MWSAuthToken' => mws_auth_token
|
176
|
+
}
|
177
|
+
|
178
|
+
operation(parameters, optional)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Sets billing agreement details such as a description of the agreement
|
182
|
+
# and other information about the seller.
|
183
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751700
|
184
|
+
# @param amazon_billing_agreement_id [String]
|
185
|
+
# @optional platform_id [String]
|
186
|
+
# @optional seller_note [String]
|
187
|
+
# @optional seller_billing_agreement_id [String]
|
188
|
+
# @optional custom_information [String]
|
189
|
+
# @optional store_name [String]
|
190
|
+
# @optional merchant_id [String]
|
191
|
+
# @optional mws_auth_token [String]
|
192
|
+
def set_billing_agreement_details(
|
193
|
+
amazon_billing_agreement_id,
|
194
|
+
platform_id: nil,
|
195
|
+
seller_note: nil,
|
196
|
+
seller_billing_agreement_id: nil,
|
197
|
+
custom_information: nil,
|
198
|
+
store_name: nil,
|
199
|
+
merchant_id: @merchant_id,
|
200
|
+
mws_auth_token: nil)
|
201
|
+
|
202
|
+
parameters = {
|
203
|
+
'Action' => 'SetBillingAgreementDetails',
|
204
|
+
'SellerId' => merchant_id,
|
205
|
+
'AmazonBillingAgreementId' => amazon_billing_agreement_id
|
206
|
+
}
|
207
|
+
|
208
|
+
optional = {
|
209
|
+
'BillingAgreementAttributes.PlatformId' => platform_id,
|
210
|
+
'BillingAgreementAttributes.SellerNote' => seller_note,
|
211
|
+
'BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId' => seller_billing_agreement_id,
|
212
|
+
'BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation' => custom_information,
|
213
|
+
'BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName' => store_name,
|
214
|
+
'MWSAuthToken' => mws_auth_token
|
215
|
+
}
|
216
|
+
|
217
|
+
operation(parameters, optional)
|
218
|
+
end
|
219
|
+
|
220
|
+
# Confirms that the billing agreement is free of constraints and all
|
221
|
+
# required information has been set on the billing agreement
|
222
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751710
|
223
|
+
# @param amazon_billing_agreement_id [String]
|
224
|
+
# @optional merchant_id [String]
|
225
|
+
# @optional mws_auth_token [String]
|
226
|
+
def confirm_billing_agreement(
|
227
|
+
amazon_billing_agreement_id,
|
228
|
+
merchant_id: @merchant_id,
|
229
|
+
mws_auth_token: nil)
|
230
|
+
|
231
|
+
parameters = {
|
232
|
+
'Action' => 'ConfirmBillingAgreement',
|
233
|
+
'SellerId' => merchant_id,
|
234
|
+
'AmazonBillingAgreementId' => amazon_billing_agreement_id
|
235
|
+
}
|
236
|
+
|
237
|
+
optional = {
|
238
|
+
'MWSAuthToken' => mws_auth_token
|
239
|
+
}
|
240
|
+
|
241
|
+
operation(parameters, optional)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Validates the status of the BillingAgreement object and the payment
|
245
|
+
# method associated with it
|
246
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751720
|
247
|
+
# @param amazon_billing_agreement_id [String]
|
248
|
+
# @optional merchant_id [String]
|
249
|
+
# @optional mws_auth_token [String]
|
250
|
+
def validate_billing_agreement(
|
251
|
+
amazon_billing_agreement_id,
|
252
|
+
merchant_id: @merchant_id,
|
253
|
+
mws_auth_token: nil)
|
254
|
+
|
255
|
+
parameters = {
|
256
|
+
'Action' => 'ValidateBillingAgreement',
|
257
|
+
'SellerId' => merchant_id,
|
258
|
+
'AmazonBillingAgreementId' => amazon_billing_agreement_id
|
259
|
+
}
|
260
|
+
|
261
|
+
optional = {
|
262
|
+
'MWSAuthToken' => mws_auth_token
|
263
|
+
}
|
264
|
+
|
265
|
+
operation(parameters, optional)
|
266
|
+
end
|
267
|
+
|
268
|
+
# Reserves a specified amount against the payment method(s) stored in the
|
269
|
+
# billing agreement
|
270
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751940
|
271
|
+
# @param amazon_billing_agreement_id [String]
|
272
|
+
# @param authorization_reference_id [String]
|
273
|
+
# @param amount [String]
|
274
|
+
# @optional currency_code [String]
|
275
|
+
# @optional seller_authorization_note [String]
|
276
|
+
# @optional transaction_timeout [Integer]
|
277
|
+
# @optional capture_now [Boolean]
|
278
|
+
# @optional soft_descriptor [String]
|
279
|
+
# @optional seller_note [String]
|
280
|
+
# @optional platform_id [String]
|
281
|
+
# @optional custom_information [String]
|
282
|
+
# @optional seller_order_id [String]
|
283
|
+
# @optional store_name [String]
|
284
|
+
# @optional inherit_shipping_address [Boolean]
|
285
|
+
# @optional merchant_id [String]
|
286
|
+
# @optional mws_auth_token [String]
|
287
|
+
def authorize_on_billing_agreement(
|
288
|
+
amazon_billing_agreement_id,
|
289
|
+
authorization_reference_id,
|
290
|
+
amount,
|
291
|
+
currency_code: @currency_code,
|
292
|
+
seller_authorization_note: nil,
|
293
|
+
transaction_timeout: nil,
|
294
|
+
capture_now: false,
|
295
|
+
soft_descriptor: nil,
|
296
|
+
seller_note: nil,
|
297
|
+
platform_id: nil,
|
298
|
+
custom_information: nil,
|
299
|
+
seller_order_id: nil,
|
300
|
+
store_name: nil,
|
301
|
+
inherit_shipping_address: nil,
|
302
|
+
merchant_id: @merchant_id,
|
303
|
+
mws_auth_token: nil)
|
304
|
+
|
305
|
+
parameters = {
|
306
|
+
'Action' => 'AuthorizeOnBillingAgreement',
|
307
|
+
'SellerId' => merchant_id,
|
308
|
+
'AmazonBillingAgreementId' => amazon_billing_agreement_id,
|
309
|
+
'AuthorizationReferenceId' => authorization_reference_id,
|
310
|
+
'AuthorizationAmount.Amount' => amount,
|
311
|
+
'AuthorizationAmount.CurrencyCode' => currency_code
|
312
|
+
}
|
313
|
+
|
314
|
+
optional = {
|
315
|
+
'SellerAuthorizationNote' => seller_authorization_note,
|
316
|
+
'TransactionTimeout' => transaction_timeout,
|
317
|
+
'CaptureNow' => capture_now,
|
318
|
+
'SoftDescriptor' => soft_descriptor,
|
319
|
+
'SellerNote' => seller_note,
|
320
|
+
'PlatformId' => platform_id,
|
321
|
+
'SellerOrderAttributes.CustomInformation' => custom_information,
|
322
|
+
'SellerOrderAttributes.SellerOrderId' => seller_order_id,
|
323
|
+
'SellerOrderAttributes.StoreName' => store_name,
|
324
|
+
'InheritShippingAddress' => inherit_shipping_address,
|
325
|
+
'MWSAuthToken' => mws_auth_token
|
326
|
+
}
|
327
|
+
|
328
|
+
operation(parameters, optional)
|
329
|
+
end
|
330
|
+
|
331
|
+
# Confirms that you want to terminate the billing agreement with the buyer
|
332
|
+
# and that you do not expect to create any new order references or
|
333
|
+
# authorizations on this billing agreement
|
334
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751950
|
335
|
+
# @param amazon_billing_agreement_id [String]
|
336
|
+
# @optional closure_reason [String]
|
337
|
+
# @optional merchant_id [String]
|
338
|
+
# @optional mws_auth_token [String]
|
339
|
+
def close_billing_agreement(
|
340
|
+
amazon_billing_agreement_id,
|
341
|
+
closure_reason: nil,
|
342
|
+
merchant_id: @merchant_id,
|
343
|
+
mws_auth_token: nil)
|
344
|
+
|
345
|
+
parameters = {
|
346
|
+
'Action' => 'CloseBillingAgreement',
|
347
|
+
'SellerId' => merchant_id,
|
348
|
+
'AmazonBillingAgreementId' => amazon_billing_agreement_id
|
349
|
+
}
|
350
|
+
|
351
|
+
optional = {
|
352
|
+
'ClosureReason' => closure_reason,
|
353
|
+
'MWSAuthToken' => mws_auth_token
|
354
|
+
}
|
355
|
+
|
356
|
+
operation(parameters, optional)
|
357
|
+
end
|
358
|
+
|
359
|
+
# Returns details about the Order Reference object and its current state
|
360
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751970
|
361
|
+
# @param amazon_order_reference_id [String]
|
362
|
+
# @optional address_consent_token [String]
|
363
|
+
# @optional merchant_id [String]
|
364
|
+
# @optional mws_auth_token [String]
|
365
|
+
def get_order_reference_details(
|
366
|
+
amazon_order_reference_id,
|
367
|
+
address_consent_token: nil,
|
368
|
+
merchant_id: @merchant_id,
|
369
|
+
mws_auth_token: nil)
|
370
|
+
|
371
|
+
parameters = {
|
372
|
+
'Action' => 'GetOrderReferenceDetails',
|
373
|
+
'SellerId' => merchant_id,
|
374
|
+
'AmazonOrderReferenceId' => amazon_order_reference_id
|
375
|
+
}
|
376
|
+
|
377
|
+
optional = {
|
378
|
+
'AddressConsentToken' => address_consent_token,
|
379
|
+
'MWSAuthToken' => mws_auth_token
|
380
|
+
}
|
381
|
+
|
382
|
+
operation(parameters, optional)
|
383
|
+
end
|
384
|
+
|
385
|
+
# Sets order reference details such as the order total and a description
|
386
|
+
# for the order
|
387
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751960
|
388
|
+
# @param amazon_order_reference_id [String]
|
389
|
+
# @param amount [String]
|
390
|
+
# @optional currency_code [String]
|
391
|
+
# @optional platform_id [String]
|
392
|
+
# @optional seller_note [String]
|
393
|
+
# @optional seller_order_id [String]
|
394
|
+
# @optional store_name [String]
|
395
|
+
# @optional custom_information [String]
|
396
|
+
# @optional merchant_id [String]
|
397
|
+
# @optional mws_auth_token [String]
|
398
|
+
def set_order_reference_details(
|
399
|
+
amazon_order_reference_id,
|
400
|
+
amount,
|
401
|
+
currency_code: @currency_code,
|
402
|
+
platform_id: nil,
|
403
|
+
seller_note: nil,
|
404
|
+
seller_order_id: nil,
|
405
|
+
store_name: nil,
|
406
|
+
custom_information: nil,
|
407
|
+
merchant_id: @merchant_id,
|
408
|
+
mws_auth_token: nil)
|
409
|
+
|
410
|
+
parameters = {
|
411
|
+
'Action' => 'SetOrderReferenceDetails',
|
412
|
+
'SellerId' => merchant_id,
|
413
|
+
'AmazonOrderReferenceId' => amazon_order_reference_id,
|
414
|
+
'OrderReferenceAttributes.OrderTotal.Amount' => amount,
|
415
|
+
'OrderReferenceAttributes.OrderTotal.CurrencyCode' => currency_code
|
416
|
+
}
|
417
|
+
|
418
|
+
optional = {
|
419
|
+
'OrderReferenceAttributes.PlatformId' => platform_id,
|
420
|
+
'OrderReferenceAttributes.SellerNote' => seller_note,
|
421
|
+
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
|
422
|
+
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
|
423
|
+
'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
|
424
|
+
'MWSAuthToken' => mws_auth_token
|
425
|
+
}
|
426
|
+
|
427
|
+
operation(parameters, optional)
|
428
|
+
end
|
429
|
+
|
430
|
+
# Confirms that the order reference is free of constraints and all required
|
431
|
+
# information has been set on the order reference
|
432
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751980
|
433
|
+
# @param amazon_order_reference_id [String]
|
434
|
+
# @optional merchant_id [String]
|
435
|
+
# @optional mws_auth_token [String]
|
436
|
+
def confirm_order_reference(
|
437
|
+
amazon_order_reference_id,
|
438
|
+
merchant_id: @merchant_id,
|
439
|
+
mws_auth_token: nil)
|
440
|
+
|
441
|
+
parameters = {
|
442
|
+
'Action' => 'ConfirmOrderReference',
|
443
|
+
'SellerId' => merchant_id,
|
444
|
+
'AmazonOrderReferenceId' => amazon_order_reference_id
|
445
|
+
}
|
446
|
+
|
447
|
+
optional = {
|
448
|
+
'MWSAuthToken' => mws_auth_token
|
449
|
+
}
|
450
|
+
|
451
|
+
operation(parameters, optional)
|
452
|
+
end
|
453
|
+
|
454
|
+
# Cancels a previously confirmed order reference
|
455
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751990
|
456
|
+
# @param amazon_order_reference_id [String]
|
457
|
+
# @optional cancelation_reason [String]
|
458
|
+
# @optional merchant_id [String]
|
459
|
+
# @optional mws_auth_token [String]
|
460
|
+
def cancel_order_reference(
|
461
|
+
amazon_order_reference_id,
|
462
|
+
cancelation_reason: nil,
|
463
|
+
merchant_id: @merchant_id,
|
464
|
+
mws_auth_token: nil)
|
465
|
+
|
466
|
+
parameters = {
|
467
|
+
'Action' => 'CancelOrderReference',
|
468
|
+
'SellerId' => merchant_id,
|
469
|
+
'AmazonOrderReferenceId' => amazon_order_reference_id
|
470
|
+
}
|
471
|
+
|
472
|
+
optional = {
|
473
|
+
'CancelationReason' => cancelation_reason,
|
474
|
+
'MWSAuthToken' => mws_auth_token
|
475
|
+
}
|
476
|
+
|
477
|
+
operation(parameters, optional)
|
478
|
+
end
|
479
|
+
|
480
|
+
# Reserves a specified amount against the payment method(s) stored in the
|
481
|
+
# order reference
|
482
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752010
|
483
|
+
# @param amazon_order_reference_id [String]
|
484
|
+
# @param authorization_reference_id [String]
|
485
|
+
# @param amount [String]
|
486
|
+
# @optional currency_code [String]
|
487
|
+
# @optional seller_authorization_note [String]
|
488
|
+
# @optional transaction_timeout [Integer]
|
489
|
+
# @optional capture_now [Boolean]
|
490
|
+
# @optional soft_descriptor [String]
|
491
|
+
# @optional provider_credit_details [Array of Hash]
|
492
|
+
# @optional merchant_id [String]
|
493
|
+
# @optional mws_auth_token [String]
|
494
|
+
def authorize(
|
495
|
+
amazon_order_reference_id,
|
496
|
+
authorization_reference_id,
|
497
|
+
amount,
|
498
|
+
currency_code: @currency_code,
|
499
|
+
seller_authorization_note: nil,
|
500
|
+
transaction_timeout: nil,
|
501
|
+
capture_now: nil,
|
502
|
+
soft_descriptor: nil,
|
503
|
+
provider_credit_details: nil,
|
504
|
+
merchant_id: @merchant_id,
|
505
|
+
mws_auth_token: nil)
|
506
|
+
|
507
|
+
parameters = {
|
508
|
+
'Action' => 'Authorize',
|
509
|
+
'SellerId' => merchant_id,
|
510
|
+
'AmazonOrderReferenceId' => amazon_order_reference_id,
|
511
|
+
'AuthorizationReferenceId' => authorization_reference_id,
|
512
|
+
'AuthorizationAmount.Amount' => amount,
|
513
|
+
'AuthorizationAmount.CurrencyCode' => currency_code
|
514
|
+
}
|
515
|
+
|
516
|
+
optional = {
|
517
|
+
'SellerAuthorizationNote' => seller_authorization_note,
|
518
|
+
'TransactionTimeout' => transaction_timeout,
|
519
|
+
'CaptureNow' => capture_now,
|
520
|
+
'SoftDescriptor' => soft_descriptor,
|
521
|
+
'MWSAuthToken' => mws_auth_token
|
522
|
+
}
|
523
|
+
|
524
|
+
optional.merge!(set_provider_credit_details(provider_credit_details)) if provider_credit_details
|
525
|
+
|
526
|
+
operation(parameters, optional)
|
527
|
+
end
|
528
|
+
|
529
|
+
# Returns the status of a particular authorization and the total amount
|
530
|
+
# captured on the authorization
|
531
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752030
|
532
|
+
# @param amazon_authorization_id [String]
|
533
|
+
# @optional merchant_id [String]
|
534
|
+
# @optional mws_auth_token [String]
|
535
|
+
def get_authorization_details(
|
536
|
+
amazon_authorization_id,
|
537
|
+
merchant_id: @merchant_id,
|
538
|
+
mws_auth_token: nil)
|
539
|
+
|
540
|
+
parameters = {
|
541
|
+
'Action' => 'GetAuthorizationDetails',
|
542
|
+
'SellerId' => merchant_id,
|
543
|
+
'AmazonAuthorizationId' => amazon_authorization_id
|
544
|
+
}
|
545
|
+
|
546
|
+
optional = {
|
547
|
+
'MWSAuthToken' => mws_auth_token
|
548
|
+
}
|
549
|
+
|
550
|
+
operation(parameters, optional)
|
551
|
+
end
|
552
|
+
|
553
|
+
# Captures funds from an authorized payment instrument.
|
554
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752040
|
555
|
+
# @param amazon_authorization_id [String]
|
556
|
+
# @param capture_reference_id [String]
|
557
|
+
# @param amount [String]
|
558
|
+
# @optional currency_code [String]
|
559
|
+
# @optional seller_capture_note [String]
|
560
|
+
# @optional soft_descriptor [String]
|
561
|
+
# @optional provider_credit_details [Array of Hash]
|
562
|
+
# @optional merchant_id [String]
|
563
|
+
# @optional mws_auth_token [String]
|
564
|
+
def capture(
|
565
|
+
amazon_authorization_id,
|
566
|
+
capture_reference_id,
|
567
|
+
amount,
|
568
|
+
currency_code: @currency_code,
|
569
|
+
seller_capture_note: nil,
|
570
|
+
soft_descriptor: nil,
|
571
|
+
provider_credit_details: nil,
|
572
|
+
merchant_id: @merchant_id,
|
573
|
+
mws_auth_token: nil)
|
574
|
+
|
575
|
+
parameters = {
|
576
|
+
'Action' => 'Capture',
|
577
|
+
'SellerId' => merchant_id,
|
578
|
+
'AmazonAuthorizationId' => amazon_authorization_id,
|
579
|
+
'CaptureReferenceId' => capture_reference_id,
|
580
|
+
'CaptureAmount.Amount' => amount,
|
581
|
+
'CaptureAmount.CurrencyCode' => currency_code
|
582
|
+
}
|
583
|
+
|
584
|
+
optional = {
|
585
|
+
'SellerCaptureNote' => seller_capture_note,
|
586
|
+
'SoftDescriptor' => soft_descriptor,
|
587
|
+
'MWSAuthToken' => mws_auth_token
|
588
|
+
}
|
589
|
+
|
590
|
+
optional.merge!(set_provider_credit_details(provider_credit_details)) if provider_credit_details
|
591
|
+
|
592
|
+
operation(parameters, optional)
|
593
|
+
end
|
594
|
+
|
595
|
+
# Returns the status of a particular capture and the total amount refunded
|
596
|
+
# on the capture
|
597
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752060
|
598
|
+
# @param amazon_capture_id [String]
|
599
|
+
# @optional merchant_id [String]
|
600
|
+
# @optional mws_auth_token [String]
|
601
|
+
def get_capture_details(
|
602
|
+
amazon_capture_id,
|
603
|
+
merchant_id: @merchant_id,
|
604
|
+
mws_auth_token: nil)
|
605
|
+
|
606
|
+
parameters = {
|
607
|
+
'Action' => 'GetCaptureDetails',
|
608
|
+
'SellerId' => merchant_id,
|
609
|
+
'AmazonCaptureId' => amazon_capture_id
|
610
|
+
}
|
611
|
+
|
612
|
+
optional = {
|
613
|
+
'MWSAuthToken' => mws_auth_token
|
614
|
+
}
|
615
|
+
|
616
|
+
operation(parameters, optional)
|
617
|
+
end
|
618
|
+
|
619
|
+
# Refunds a previously captured amount
|
620
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752080
|
621
|
+
# @param amazon_capture_id [String]
|
622
|
+
# @param refund_reference_id [String]
|
623
|
+
# @param amount [String]
|
624
|
+
# @optional currency_code [String]
|
625
|
+
# @optional seller_refund_note [String]
|
626
|
+
# @optional soft_descriptor [String]
|
627
|
+
# @optional provider_credit_reversal_details [Array of Hash]
|
628
|
+
# @optional merchant_id [String]
|
629
|
+
# @optional mws_auth_token [String]
|
630
|
+
def refund(
|
631
|
+
amazon_capture_id,
|
632
|
+
refund_reference_id,
|
633
|
+
amount,
|
634
|
+
currency_code: @currency_code,
|
635
|
+
seller_refund_note: nil,
|
636
|
+
soft_descriptor: nil,
|
637
|
+
provider_credit_reversal_details: nil,
|
638
|
+
merchant_id: @merchant_id,
|
639
|
+
mws_auth_token: nil)
|
640
|
+
|
641
|
+
parameters = {
|
642
|
+
'Action' => 'Refund',
|
643
|
+
'SellerId' => merchant_id,
|
644
|
+
'AmazonCaptureId' => amazon_capture_id,
|
645
|
+
'RefundReferenceId' => refund_reference_id,
|
646
|
+
'RefundAmount.Amount' => amount,
|
647
|
+
'RefundAmount.CurrencyCode' => currency_code
|
648
|
+
}
|
649
|
+
|
650
|
+
optional = {
|
651
|
+
'SellerRefundNote' => seller_refund_note,
|
652
|
+
'SoftDescriptor' => soft_descriptor,
|
653
|
+
'MWSAuthToken' => mws_auth_token
|
654
|
+
}
|
655
|
+
|
656
|
+
optional.merge!(set_provider_credit_reversal_details(provider_credit_reversal_details)) if provider_credit_reversal_details
|
657
|
+
|
658
|
+
operation(parameters, optional)
|
659
|
+
end
|
660
|
+
|
661
|
+
# Returns the status of a particular refund
|
662
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752100
|
663
|
+
# @param amazon_refund_id [String]
|
664
|
+
# @optional merchant_id [String]
|
665
|
+
# @optional mws_auth_token [String]
|
666
|
+
def get_refund_details(
|
667
|
+
amazon_refund_id,
|
668
|
+
merchant_id: @merchant_id,
|
669
|
+
mws_auth_token: nil)
|
670
|
+
|
671
|
+
parameters = {
|
672
|
+
'Action' => 'GetRefundDetails',
|
673
|
+
'SellerId' => merchant_id,
|
674
|
+
'AmazonRefundId' => amazon_refund_id
|
675
|
+
}
|
676
|
+
|
677
|
+
optional = {
|
678
|
+
'MWSAuthToken' => mws_auth_token
|
679
|
+
}
|
680
|
+
|
681
|
+
operation(parameters, optional)
|
682
|
+
end
|
683
|
+
|
684
|
+
# Closes an authorization
|
685
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752070
|
686
|
+
# @param amazon_authorization_id [String]
|
687
|
+
# @optional closure_reason [String]
|
688
|
+
# @optional merchant_id [String]
|
689
|
+
# @optional mws_auth_token [String]
|
690
|
+
def close_authorization(
|
691
|
+
amazon_authorization_id,
|
692
|
+
closure_reason: nil,
|
693
|
+
merchant_id: @merchant_id,
|
694
|
+
mws_auth_token: nil)
|
695
|
+
|
696
|
+
parameters = {
|
697
|
+
'Action' => 'CloseAuthorization',
|
698
|
+
'SellerId' => merchant_id,
|
699
|
+
'AmazonAuthorizationId' => amazon_authorization_id
|
700
|
+
}
|
701
|
+
|
702
|
+
optional = {
|
703
|
+
'ClosureReason' => closure_reason,
|
704
|
+
'MWSAuthToken' => mws_auth_token
|
705
|
+
}
|
706
|
+
|
707
|
+
operation(parameters, optional)
|
708
|
+
end
|
709
|
+
|
710
|
+
# Confirms that an order reference has been fulfilled (fully or partially)
|
711
|
+
# and that you do not expect to create any new authorizations on this
|
712
|
+
# order reference
|
713
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201752000
|
714
|
+
# @param amazon_order_reference_id [String]
|
715
|
+
# @optional closure_reason [String]
|
716
|
+
# @optional merchant_id [String]
|
717
|
+
# @optional mws_auth_token [String]
|
718
|
+
def close_order_reference(
|
719
|
+
amazon_order_reference_id,
|
720
|
+
closure_reason: nil,
|
721
|
+
merchant_id: @merchant_id,
|
722
|
+
mws_auth_token: nil)
|
723
|
+
|
724
|
+
parameters = {
|
725
|
+
'Action' => 'CloseOrderReference',
|
726
|
+
'SellerId' => merchant_id,
|
727
|
+
'AmazonOrderReferenceId' => amazon_order_reference_id
|
728
|
+
}
|
729
|
+
|
730
|
+
optional = {
|
731
|
+
'ClosureReason' => closure_reason,
|
732
|
+
'MWSAuthToken' => mws_auth_token
|
733
|
+
}
|
734
|
+
|
735
|
+
operation(parameters, optional)
|
736
|
+
end
|
737
|
+
|
738
|
+
# @param amazon_provider_credit_id [String]
|
739
|
+
# @optional merchant_id [String]
|
740
|
+
# @optional mws_auth_token [String]
|
741
|
+
def get_provider_credit_details(
|
742
|
+
amazon_provider_credit_id,
|
743
|
+
merchant_id: @merchant_id,
|
744
|
+
mws_auth_token: nil)
|
745
|
+
|
746
|
+
parameters = {
|
747
|
+
'Action' => 'GetProviderCreditDetails',
|
748
|
+
'SellerId' => merchant_id,
|
749
|
+
'AmazonProviderCreditId' => amazon_provider_credit_id
|
750
|
+
}
|
751
|
+
|
752
|
+
optional = {
|
753
|
+
'MWSAuthToken' => mws_auth_token
|
754
|
+
}
|
755
|
+
|
756
|
+
operation(parameters, optional)
|
757
|
+
end
|
758
|
+
|
759
|
+
# @param amazon_provider_credit_reversal_id [String]
|
760
|
+
# @optional merchant_id [String]
|
761
|
+
# @optional mws_auth_token [String]
|
762
|
+
def get_provider_credit_reversal_details(
|
763
|
+
amazon_provider_credit_reversal_id,
|
764
|
+
merchant_id: @merchant_id,
|
765
|
+
mws_auth_token: nil)
|
766
|
+
|
767
|
+
parameters = {
|
768
|
+
'Action' => 'GetProviderCreditReversalDetails',
|
769
|
+
'SellerId' => merchant_id,
|
770
|
+
'AmazonProviderCreditReversalId' => amazon_provider_credit_reversal_id
|
771
|
+
}
|
772
|
+
|
773
|
+
optional = {
|
774
|
+
'MWSAuthToken' => mws_auth_token
|
775
|
+
}
|
776
|
+
|
777
|
+
operation(parameters, optional)
|
778
|
+
end
|
779
|
+
|
780
|
+
# @param amazon_provider_credit_id [String]
|
781
|
+
# @param credit_reversal_reference_id [String]
|
782
|
+
# @param amount [String]
|
783
|
+
# @optional currency_code [String]
|
784
|
+
# @optional credit_reversal_note [String]
|
785
|
+
# @optional merchant_id [String]
|
786
|
+
# @optional mws_auth_token [String]
|
787
|
+
def reverse_provider_credit(
|
788
|
+
amazon_provider_credit_id,
|
789
|
+
credit_reversal_reference_id,
|
790
|
+
amount,
|
791
|
+
currency_code: @currency_code,
|
792
|
+
credit_reversal_note: nil,
|
793
|
+
merchant_id: @merchant_id,
|
794
|
+
mws_auth_token: nil)
|
795
|
+
|
796
|
+
parameters = {
|
797
|
+
'Action' => 'ReverseProviderCredit',
|
798
|
+
'SellerId' => merchant_id,
|
799
|
+
'AmazonProviderCreditId' => amazon_provider_credit_id,
|
800
|
+
'CreditReversalReferenceId' => credit_reversal_reference_id,
|
801
|
+
'CreditReversalAmount.Amount' => amount,
|
802
|
+
'CreditReversalAmount.CurrencyCode' => currency_code
|
803
|
+
}
|
804
|
+
|
805
|
+
optional = {
|
806
|
+
'CreditReversalNote' => credit_reversal_note,
|
807
|
+
'MWSAuthToken' => mws_auth_token
|
808
|
+
}
|
809
|
+
|
810
|
+
operation(parameters, optional)
|
811
|
+
end
|
812
|
+
|
813
|
+
private
|
814
|
+
|
815
|
+
def region_hash
|
816
|
+
{
|
817
|
+
:jp => 'mws.amazonservices.jp',
|
818
|
+
:uk => 'mws-eu.amazonservices.com',
|
819
|
+
:de => 'mws-eu.amazonservices.com',
|
820
|
+
:eu => 'mws-eu.amazonservices.com',
|
821
|
+
:us => 'mws.amazonservices.com',
|
822
|
+
:na => 'mws.amazonservices.com'
|
823
|
+
}
|
824
|
+
end
|
825
|
+
|
826
|
+
# This method builds the provider credit details hash
|
827
|
+
# that will be combined with either the authorize or capture
|
828
|
+
# API call.
|
829
|
+
def set_provider_credit_details(provider_credit_details)
|
830
|
+
member_details = {}
|
831
|
+
provider_credit_details.each_with_index { |val, index|
|
832
|
+
member = index + 1
|
833
|
+
member_details["ProviderCreditList.member.#{member}.ProviderId"] = val[:provider_id]
|
834
|
+
member_details["ProviderCreditList.member.#{member}.CreditAmount.Amount"] = val[:amount]
|
835
|
+
member_details["ProviderCreditList.member.#{member}.CreditAmount.CurrencyCode"] = val[:currency_code]
|
836
|
+
}
|
837
|
+
|
838
|
+
return member_details
|
839
|
+
end
|
840
|
+
|
841
|
+
# This method builds the provider credit reversal
|
842
|
+
# details hash that will be combined with the refund
|
843
|
+
# API call.
|
844
|
+
def set_provider_credit_reversal_details(provider_credit_reversal_details)
|
845
|
+
member_details = {}
|
846
|
+
provider_credit_reversal_details.each_with_index { |val, index|
|
847
|
+
member = index + 1
|
848
|
+
member_details["ProviderCreditReversalList.member.#{member}.ProviderId"] = val[:provider_id]
|
849
|
+
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.Amount"] = val[:amount]
|
850
|
+
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.CurrencyCode"] = val[:currency_code]
|
851
|
+
}
|
852
|
+
|
853
|
+
return member_details
|
854
|
+
end
|
855
|
+
|
856
|
+
def operation(parameters, optional)
|
857
|
+
AmazonPay::Request.new(
|
858
|
+
parameters,
|
859
|
+
optional,
|
860
|
+
@default_hash,
|
861
|
+
@mws_endpoint,
|
862
|
+
@sandbox_str,
|
863
|
+
@secret_key,
|
864
|
+
@proxy_addr,
|
865
|
+
@proxy_port,
|
866
|
+
@proxy_user,
|
867
|
+
@proxy_pass,
|
868
|
+
@throttle,
|
869
|
+
@application_name,
|
870
|
+
@application_version).send_post
|
871
|
+
end
|
872
|
+
|
873
|
+
end
|
874
|
+
|
875
|
+
end
|