amazon_pay 2.0.0 → 2.1.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 +4 -4
- data/LICENSE +0 -0
- data/NOTICE +0 -0
- data/README.md +0 -0
- data/lib/amazon_pay.rb +2 -0
- data/lib/amazon_pay/client.rb +322 -195
- data/lib/amazon_pay/client_helper.rb +42 -0
- data/lib/amazon_pay/ipn_handler.rb +62 -41
- data/lib/amazon_pay/log_initializer.rb +47 -0
- data/lib/amazon_pay/login.rb +0 -0
- data/lib/amazon_pay/request.rb +46 -26
- data/lib/amazon_pay/response.rb +0 -0
- data/lib/amazon_pay/sanitize.rb +48 -0
- data/lib/amazon_pay/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7040fc32759f87f3f3f21b053831138dd4c5c04
|
4
|
+
data.tar.gz: aac1ff85663dffd1cc964b371d9f05f669150bfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c746d20fd2e12307e06318b78f669656199d0baa849c0d2cd7f8bbe6f383222fe566b8ff7d0e802cb1bdc4784f742bc1c3524b69b38ce32e3738dc3cde5e7f7
|
7
|
+
data.tar.gz: 6bee2aa81e8e8d8aa00f48ff71c5d8fbc7d3519b172bfd1154aa7ce9bd2ec282936eb6ca6b20e25954c86c0421d352e49a91b5582988fe65e2158c5a0f19bd7e
|
data/LICENSE
CHANGED
File without changes
|
data/NOTICE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/lib/amazon_pay.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'amazon_pay/client'
|
2
2
|
require 'amazon_pay/client_helper'
|
3
3
|
require 'amazon_pay/ipn_handler'
|
4
|
+
require 'amazon_pay/log_initializer'
|
4
5
|
require 'amazon_pay/login'
|
5
6
|
require 'amazon_pay/request'
|
6
7
|
require 'amazon_pay/response'
|
8
|
+
require 'amazon_pay/sanitize'
|
7
9
|
require 'amazon_pay/version'
|
data/lib/amazon_pay/client.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'time'
|
2
|
+
require 'logger'
|
3
|
+
require 'stringio'
|
2
4
|
|
3
5
|
module AmazonPay
|
4
|
-
|
5
6
|
# AmazonPay API
|
6
7
|
#
|
7
8
|
# This client allows you to make all the necessary API calls
|
8
9
|
# to integrate with AmazonPay. This client only
|
9
10
|
# uses the standard Ruby library and is not dependant on Rails.
|
10
11
|
class Client
|
11
|
-
|
12
12
|
attr_reader(
|
13
13
|
:merchant_id,
|
14
14
|
:access_key,
|
@@ -19,14 +19,19 @@ module AmazonPay
|
|
19
19
|
:platform_id,
|
20
20
|
:throttle,
|
21
21
|
:application_name,
|
22
|
-
:application_version
|
22
|
+
:application_version,
|
23
|
+
:log_enabled,
|
24
|
+
:log_file_name,
|
25
|
+
:log_level
|
26
|
+
)
|
23
27
|
|
24
28
|
attr_accessor(
|
25
29
|
:sandbox,
|
26
30
|
:proxy_addr,
|
27
31
|
:proxy_port,
|
28
32
|
:proxy_user,
|
29
|
-
:proxy_pass
|
33
|
+
:proxy_pass
|
34
|
+
)
|
30
35
|
|
31
36
|
# API keys are located at:
|
32
37
|
# @see https://sellercentral.amazon.com
|
@@ -40,26 +45,32 @@ module AmazonPay
|
|
40
45
|
# @optional throttle [Boolean] Default: true
|
41
46
|
# @optional application_name [String]
|
42
47
|
# @optional application_version [String]
|
48
|
+
# @optional log_enabled [Boolean] Default: false
|
49
|
+
# @optional log_file_name [String]
|
50
|
+
# @optional log_level [Symbol] Default: DEBUG
|
43
51
|
# @optional proxy_addr [String]
|
44
52
|
# @optional proxy_port [String]
|
45
53
|
# @optional proxy_user [String]
|
46
54
|
# @optional proxy_pass [String]
|
47
55
|
def initialize(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
merchant_id,
|
57
|
+
access_key,
|
58
|
+
secret_key,
|
59
|
+
sandbox: false,
|
60
|
+
currency_code: :usd,
|
61
|
+
region: :na,
|
62
|
+
platform_id: nil,
|
63
|
+
throttle: true,
|
64
|
+
application_name: nil,
|
65
|
+
application_version: nil,
|
66
|
+
proxy_addr: :ENV,
|
67
|
+
proxy_port: nil,
|
68
|
+
proxy_user: nil,
|
69
|
+
proxy_pass: nil,
|
70
|
+
log_enabled: false,
|
71
|
+
log_file_name: nil,
|
72
|
+
log_level: :DEBUG
|
73
|
+
)
|
63
74
|
@merchant_id = merchant_id
|
64
75
|
@access_key = access_key
|
65
76
|
@secret_key = secret_key
|
@@ -85,6 +96,10 @@ module AmazonPay
|
|
85
96
|
'Version' => AmazonPay::API_VERSION
|
86
97
|
}
|
87
98
|
|
99
|
+
@log_enabled = log_enabled
|
100
|
+
@log_level = log_level
|
101
|
+
@log_file_name = log_file_name
|
102
|
+
|
88
103
|
@default_hash['PlatformId'] = @platform_id if @platform_id
|
89
104
|
end
|
90
105
|
|
@@ -115,19 +130,20 @@ module AmazonPay
|
|
115
130
|
# @optional merchant_id [String]
|
116
131
|
# @optional mws_auth_token [String]
|
117
132
|
def create_order_reference_for_id(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
133
|
+
id,
|
134
|
+
id_type,
|
135
|
+
inherit_shipping_address: nil,
|
136
|
+
confirm_now: nil,
|
137
|
+
amount: nil,
|
138
|
+
currency_code: @currency_code,
|
139
|
+
platform_id: nil,
|
140
|
+
seller_note: nil,
|
141
|
+
seller_order_id: nil,
|
142
|
+
store_name: nil,
|
143
|
+
custom_information: nil,
|
144
|
+
merchant_id: @merchant_id,
|
145
|
+
mws_auth_token: nil
|
146
|
+
)
|
131
147
|
|
132
148
|
parameters = {
|
133
149
|
'Action' => 'CreateOrderReferenceForId',
|
@@ -159,10 +175,11 @@ module AmazonPay
|
|
159
175
|
# @optional merchant_id [String]
|
160
176
|
# @optional mws_auth_token [String]
|
161
177
|
def get_billing_agreement_details(
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
178
|
+
amazon_billing_agreement_id,
|
179
|
+
address_consent_token: nil,
|
180
|
+
merchant_id: @merchant_id,
|
181
|
+
mws_auth_token: nil
|
182
|
+
)
|
166
183
|
|
167
184
|
parameters = {
|
168
185
|
'Action' => 'GetBillingAgreementDetails',
|
@@ -190,14 +207,15 @@ module AmazonPay
|
|
190
207
|
# @optional merchant_id [String]
|
191
208
|
# @optional mws_auth_token [String]
|
192
209
|
def set_billing_agreement_details(
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
210
|
+
amazon_billing_agreement_id,
|
211
|
+
platform_id: nil,
|
212
|
+
seller_note: nil,
|
213
|
+
seller_billing_agreement_id: nil,
|
214
|
+
custom_information: nil,
|
215
|
+
store_name: nil,
|
216
|
+
merchant_id: @merchant_id,
|
217
|
+
mws_auth_token: nil
|
218
|
+
)
|
201
219
|
|
202
220
|
parameters = {
|
203
221
|
'Action' => 'SetBillingAgreementDetails',
|
@@ -224,9 +242,10 @@ module AmazonPay
|
|
224
242
|
# @optional merchant_id [String]
|
225
243
|
# @optional mws_auth_token [String]
|
226
244
|
def confirm_billing_agreement(
|
227
|
-
|
228
|
-
|
229
|
-
|
245
|
+
amazon_billing_agreement_id,
|
246
|
+
merchant_id: @merchant_id,
|
247
|
+
mws_auth_token: nil
|
248
|
+
)
|
230
249
|
|
231
250
|
parameters = {
|
232
251
|
'Action' => 'ConfirmBillingAgreement',
|
@@ -248,9 +267,10 @@ module AmazonPay
|
|
248
267
|
# @optional merchant_id [String]
|
249
268
|
# @optional mws_auth_token [String]
|
250
269
|
def validate_billing_agreement(
|
251
|
-
|
252
|
-
|
253
|
-
|
270
|
+
amazon_billing_agreement_id,
|
271
|
+
merchant_id: @merchant_id,
|
272
|
+
mws_auth_token: nil
|
273
|
+
)
|
254
274
|
|
255
275
|
parameters = {
|
256
276
|
'Action' => 'ValidateBillingAgreement',
|
@@ -285,22 +305,23 @@ module AmazonPay
|
|
285
305
|
# @optional merchant_id [String]
|
286
306
|
# @optional mws_auth_token [String]
|
287
307
|
def authorize_on_billing_agreement(
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
308
|
+
amazon_billing_agreement_id,
|
309
|
+
authorization_reference_id,
|
310
|
+
amount,
|
311
|
+
currency_code: @currency_code,
|
312
|
+
seller_authorization_note: nil,
|
313
|
+
transaction_timeout: nil,
|
314
|
+
capture_now: false,
|
315
|
+
soft_descriptor: nil,
|
316
|
+
seller_note: nil,
|
317
|
+
platform_id: nil,
|
318
|
+
custom_information: nil,
|
319
|
+
seller_order_id: nil,
|
320
|
+
store_name: nil,
|
321
|
+
inherit_shipping_address: nil,
|
322
|
+
merchant_id: @merchant_id,
|
323
|
+
mws_auth_token: nil
|
324
|
+
)
|
304
325
|
|
305
326
|
parameters = {
|
306
327
|
'Action' => 'AuthorizeOnBillingAgreement',
|
@@ -337,10 +358,11 @@ module AmazonPay
|
|
337
358
|
# @optional merchant_id [String]
|
338
359
|
# @optional mws_auth_token [String]
|
339
360
|
def close_billing_agreement(
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
361
|
+
amazon_billing_agreement_id,
|
362
|
+
closure_reason: nil,
|
363
|
+
merchant_id: @merchant_id,
|
364
|
+
mws_auth_token: nil
|
365
|
+
)
|
344
366
|
|
345
367
|
parameters = {
|
346
368
|
'Action' => 'CloseBillingAgreement',
|
@@ -363,10 +385,11 @@ module AmazonPay
|
|
363
385
|
# @optional merchant_id [String]
|
364
386
|
# @optional mws_auth_token [String]
|
365
387
|
def get_order_reference_details(
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
388
|
+
amazon_order_reference_id,
|
389
|
+
address_consent_token: nil,
|
390
|
+
merchant_id: @merchant_id,
|
391
|
+
mws_auth_token: nil
|
392
|
+
)
|
370
393
|
|
371
394
|
parameters = {
|
372
395
|
'Action' => 'GetOrderReferenceDetails',
|
@@ -391,21 +414,26 @@ module AmazonPay
|
|
391
414
|
# @optional platform_id [String]
|
392
415
|
# @optional seller_note [String]
|
393
416
|
# @optional seller_order_id [String]
|
417
|
+
# @optional request_payment_authorization [Boolean]
|
394
418
|
# @optional store_name [String]
|
419
|
+
# @optional order_item_categories Array[String]
|
395
420
|
# @optional custom_information [String]
|
396
421
|
# @optional merchant_id [String]
|
397
422
|
# @optional mws_auth_token [String]
|
398
423
|
def set_order_reference_details(
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
424
|
+
amazon_order_reference_id,
|
425
|
+
amount,
|
426
|
+
currency_code: @currency_code,
|
427
|
+
platform_id: nil,
|
428
|
+
seller_note: nil,
|
429
|
+
seller_order_id: nil,
|
430
|
+
request_payment_authorization: nil,
|
431
|
+
store_name: nil,
|
432
|
+
order_item_categories: nil,
|
433
|
+
custom_information: nil,
|
434
|
+
merchant_id: @merchant_id,
|
435
|
+
mws_auth_token: nil
|
436
|
+
)
|
409
437
|
|
410
438
|
parameters = {
|
411
439
|
'Action' => 'SetOrderReferenceDetails',
|
@@ -417,6 +445,7 @@ module AmazonPay
|
|
417
445
|
|
418
446
|
optional = {
|
419
447
|
'OrderReferenceAttributes.PlatformId' => platform_id,
|
448
|
+
'OrderReferenceAttributes.RequestPaymentAuthorization' => request_payment_authorization,
|
420
449
|
'OrderReferenceAttributes.SellerNote' => seller_note,
|
421
450
|
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
|
422
451
|
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
|
@@ -424,6 +453,79 @@ module AmazonPay
|
|
424
453
|
'MWSAuthToken' => mws_auth_token
|
425
454
|
}
|
426
455
|
|
456
|
+
if order_item_categories
|
457
|
+
optional.merge!(
|
458
|
+
get_categories_list(
|
459
|
+
'OrderReferenceAttributes',
|
460
|
+
order_item_categories
|
461
|
+
)
|
462
|
+
)
|
463
|
+
end
|
464
|
+
|
465
|
+
operation(parameters, optional)
|
466
|
+
end
|
467
|
+
|
468
|
+
# Sets order attributes such as the order total and a description
|
469
|
+
# for the order
|
470
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751960
|
471
|
+
# @param amazon_order_reference_id [String]
|
472
|
+
# @optional amount [String]
|
473
|
+
# @optional currency_code [String]
|
474
|
+
# @optional platform_id [String]
|
475
|
+
# @optional seller_note [String]
|
476
|
+
# @optional seller_order_id [String]
|
477
|
+
# @optional request_payment_authorization [Boolean]
|
478
|
+
# @optional store_name [String]
|
479
|
+
# @optional order_item_categories Array[String]
|
480
|
+
# @optional custom_information [String]
|
481
|
+
# @optional merchant_id [String]
|
482
|
+
# @optional mws_auth_token [String]
|
483
|
+
def set_order_attributes(
|
484
|
+
amazon_order_reference_id,
|
485
|
+
amount: nil,
|
486
|
+
currency_code: nil,
|
487
|
+
platform_id: nil,
|
488
|
+
seller_note: nil,
|
489
|
+
seller_order_id: nil,
|
490
|
+
payment_service_provider_id: nil,
|
491
|
+
payment_service_provider_order_id: nil,
|
492
|
+
request_payment_authorization: nil,
|
493
|
+
store_name: nil,
|
494
|
+
order_item_categories: nil,
|
495
|
+
custom_information: nil,
|
496
|
+
merchant_id: @merchant_id,
|
497
|
+
mws_auth_token: nil
|
498
|
+
)
|
499
|
+
|
500
|
+
parameters = {
|
501
|
+
'Action' => 'SetOrderAttributes',
|
502
|
+
'SellerId' => merchant_id,
|
503
|
+
'AmazonOrderReferenceId' => amazon_order_reference_id
|
504
|
+
}
|
505
|
+
|
506
|
+
optional = {
|
507
|
+
'OrderAttributes.OrderTotal.Amount' => amount,
|
508
|
+
'OrderAttributes.OrderTotal.CurrencyCode' => currency_code,
|
509
|
+
'OrderAttributes.PlatformId' => platform_id,
|
510
|
+
'OrderAttributes.SellerNote' => seller_note,
|
511
|
+
'OrderAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
|
512
|
+
'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderId' => payment_service_provider_id,
|
513
|
+
'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderOrderId' => payment_service_provider_order_id,
|
514
|
+
'OrderAttributes.RequestPaymentAuthorization' => request_payment_authorization,
|
515
|
+
'OrderAttributes.SellerOrderAttributes.StoreName' => store_name,
|
516
|
+
'OrderAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
|
517
|
+
'MWSAuthToken' => mws_auth_token
|
518
|
+
}
|
519
|
+
|
520
|
+
if order_item_categories
|
521
|
+
optional.merge!(
|
522
|
+
get_categories_list(
|
523
|
+
'OrderAttributes',
|
524
|
+
order_item_categories
|
525
|
+
)
|
526
|
+
)
|
527
|
+
end
|
528
|
+
|
427
529
|
operation(parameters, optional)
|
428
530
|
end
|
429
531
|
|
@@ -434,9 +536,10 @@ module AmazonPay
|
|
434
536
|
# @optional merchant_id [String]
|
435
537
|
# @optional mws_auth_token [String]
|
436
538
|
def confirm_order_reference(
|
437
|
-
|
438
|
-
|
439
|
-
|
539
|
+
amazon_order_reference_id,
|
540
|
+
merchant_id: @merchant_id,
|
541
|
+
mws_auth_token: nil
|
542
|
+
)
|
440
543
|
|
441
544
|
parameters = {
|
442
545
|
'Action' => 'ConfirmOrderReference',
|
@@ -458,10 +561,11 @@ module AmazonPay
|
|
458
561
|
# @optional merchant_id [String]
|
459
562
|
# @optional mws_auth_token [String]
|
460
563
|
def cancel_order_reference(
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
564
|
+
amazon_order_reference_id,
|
565
|
+
cancelation_reason: nil,
|
566
|
+
merchant_id: @merchant_id,
|
567
|
+
mws_auth_token: nil
|
568
|
+
)
|
465
569
|
|
466
570
|
parameters = {
|
467
571
|
'Action' => 'CancelOrderReference',
|
@@ -492,17 +596,18 @@ module AmazonPay
|
|
492
596
|
# @optional merchant_id [String]
|
493
597
|
# @optional mws_auth_token [String]
|
494
598
|
def authorize(
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
599
|
+
amazon_order_reference_id,
|
600
|
+
authorization_reference_id,
|
601
|
+
amount,
|
602
|
+
currency_code: @currency_code,
|
603
|
+
seller_authorization_note: nil,
|
604
|
+
transaction_timeout: nil,
|
605
|
+
capture_now: nil,
|
606
|
+
soft_descriptor: nil,
|
607
|
+
provider_credit_details: nil,
|
608
|
+
merchant_id: @merchant_id,
|
609
|
+
mws_auth_token: nil
|
610
|
+
)
|
506
611
|
|
507
612
|
parameters = {
|
508
613
|
'Action' => 'Authorize',
|
@@ -533,9 +638,10 @@ module AmazonPay
|
|
533
638
|
# @optional merchant_id [String]
|
534
639
|
# @optional mws_auth_token [String]
|
535
640
|
def get_authorization_details(
|
536
|
-
|
537
|
-
|
538
|
-
|
641
|
+
amazon_authorization_id,
|
642
|
+
merchant_id: @merchant_id,
|
643
|
+
mws_auth_token: nil
|
644
|
+
)
|
539
645
|
|
540
646
|
parameters = {
|
541
647
|
'Action' => 'GetAuthorizationDetails',
|
@@ -562,15 +668,16 @@ module AmazonPay
|
|
562
668
|
# @optional merchant_id [String]
|
563
669
|
# @optional mws_auth_token [String]
|
564
670
|
def capture(
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
671
|
+
amazon_authorization_id,
|
672
|
+
capture_reference_id,
|
673
|
+
amount,
|
674
|
+
currency_code: @currency_code,
|
675
|
+
seller_capture_note: nil,
|
676
|
+
soft_descriptor: nil,
|
677
|
+
provider_credit_details: nil,
|
678
|
+
merchant_id: @merchant_id,
|
679
|
+
mws_auth_token: nil
|
680
|
+
)
|
574
681
|
|
575
682
|
parameters = {
|
576
683
|
'Action' => 'Capture',
|
@@ -599,9 +706,10 @@ module AmazonPay
|
|
599
706
|
# @optional merchant_id [String]
|
600
707
|
# @optional mws_auth_token [String]
|
601
708
|
def get_capture_details(
|
602
|
-
|
603
|
-
|
604
|
-
|
709
|
+
amazon_capture_id,
|
710
|
+
merchant_id: @merchant_id,
|
711
|
+
mws_auth_token: nil
|
712
|
+
)
|
605
713
|
|
606
714
|
parameters = {
|
607
715
|
'Action' => 'GetCaptureDetails',
|
@@ -628,15 +736,16 @@ module AmazonPay
|
|
628
736
|
# @optional merchant_id [String]
|
629
737
|
# @optional mws_auth_token [String]
|
630
738
|
def refund(
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
739
|
+
amazon_capture_id,
|
740
|
+
refund_reference_id,
|
741
|
+
amount,
|
742
|
+
currency_code: @currency_code,
|
743
|
+
seller_refund_note: nil,
|
744
|
+
soft_descriptor: nil,
|
745
|
+
provider_credit_reversal_details: nil,
|
746
|
+
merchant_id: @merchant_id,
|
747
|
+
mws_auth_token: nil
|
748
|
+
)
|
640
749
|
|
641
750
|
parameters = {
|
642
751
|
'Action' => 'Refund',
|
@@ -664,9 +773,10 @@ module AmazonPay
|
|
664
773
|
# @optional merchant_id [String]
|
665
774
|
# @optional mws_auth_token [String]
|
666
775
|
def get_refund_details(
|
667
|
-
|
668
|
-
|
669
|
-
|
776
|
+
amazon_refund_id,
|
777
|
+
merchant_id: @merchant_id,
|
778
|
+
mws_auth_token: nil
|
779
|
+
)
|
670
780
|
|
671
781
|
parameters = {
|
672
782
|
'Action' => 'GetRefundDetails',
|
@@ -688,10 +798,11 @@ module AmazonPay
|
|
688
798
|
# @optional merchant_id [String]
|
689
799
|
# @optional mws_auth_token [String]
|
690
800
|
def close_authorization(
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
801
|
+
amazon_authorization_id,
|
802
|
+
closure_reason: nil,
|
803
|
+
merchant_id: @merchant_id,
|
804
|
+
mws_auth_token: nil
|
805
|
+
)
|
695
806
|
|
696
807
|
parameters = {
|
697
808
|
'Action' => 'CloseAuthorization',
|
@@ -716,10 +827,11 @@ module AmazonPay
|
|
716
827
|
# @optional merchant_id [String]
|
717
828
|
# @optional mws_auth_token [String]
|
718
829
|
def close_order_reference(
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
830
|
+
amazon_order_reference_id,
|
831
|
+
closure_reason: nil,
|
832
|
+
merchant_id: @merchant_id,
|
833
|
+
mws_auth_token: nil
|
834
|
+
)
|
723
835
|
|
724
836
|
parameters = {
|
725
837
|
'Action' => 'CloseOrderReference',
|
@@ -739,42 +851,44 @@ module AmazonPay
|
|
739
851
|
# @optional merchant_id [String]
|
740
852
|
# @optional mws_auth_token [String]
|
741
853
|
def get_provider_credit_details(
|
742
|
-
|
743
|
-
|
744
|
-
|
854
|
+
amazon_provider_credit_id,
|
855
|
+
merchant_id: @merchant_id,
|
856
|
+
mws_auth_token: nil
|
857
|
+
)
|
745
858
|
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
859
|
+
parameters = {
|
860
|
+
'Action' => 'GetProviderCreditDetails',
|
861
|
+
'SellerId' => merchant_id,
|
862
|
+
'AmazonProviderCreditId' => amazon_provider_credit_id
|
863
|
+
}
|
751
864
|
|
752
|
-
|
753
|
-
|
754
|
-
|
865
|
+
optional = {
|
866
|
+
'MWSAuthToken' => mws_auth_token
|
867
|
+
}
|
755
868
|
|
756
|
-
|
869
|
+
operation(parameters, optional)
|
757
870
|
end
|
758
871
|
|
759
872
|
# @param amazon_provider_credit_reversal_id [String]
|
760
873
|
# @optional merchant_id [String]
|
761
874
|
# @optional mws_auth_token [String]
|
762
875
|
def get_provider_credit_reversal_details(
|
763
|
-
|
764
|
-
|
765
|
-
|
876
|
+
amazon_provider_credit_reversal_id,
|
877
|
+
merchant_id: @merchant_id,
|
878
|
+
mws_auth_token: nil
|
879
|
+
)
|
766
880
|
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
881
|
+
parameters = {
|
882
|
+
'Action' => 'GetProviderCreditReversalDetails',
|
883
|
+
'SellerId' => merchant_id,
|
884
|
+
'AmazonProviderCreditReversalId' => amazon_provider_credit_reversal_id
|
885
|
+
}
|
772
886
|
|
773
|
-
|
774
|
-
|
775
|
-
|
887
|
+
optional = {
|
888
|
+
'MWSAuthToken' => mws_auth_token
|
889
|
+
}
|
776
890
|
|
777
|
-
|
891
|
+
operation(parameters, optional)
|
778
892
|
end
|
779
893
|
|
780
894
|
# @param amazon_provider_credit_id [String]
|
@@ -785,13 +899,14 @@ module AmazonPay
|
|
785
899
|
# @optional merchant_id [String]
|
786
900
|
# @optional mws_auth_token [String]
|
787
901
|
def reverse_provider_credit(
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
902
|
+
amazon_provider_credit_id,
|
903
|
+
credit_reversal_reference_id,
|
904
|
+
amount,
|
905
|
+
currency_code: @currency_code,
|
906
|
+
credit_reversal_note: nil,
|
907
|
+
merchant_id: @merchant_id,
|
908
|
+
mws_auth_token: nil
|
909
|
+
)
|
795
910
|
|
796
911
|
parameters = {
|
797
912
|
'Action' => 'ReverseProviderCredit',
|
@@ -814,12 +929,12 @@ module AmazonPay
|
|
814
929
|
|
815
930
|
def region_hash
|
816
931
|
{
|
817
|
-
:
|
818
|
-
:
|
819
|
-
:
|
820
|
-
:
|
821
|
-
:
|
822
|
-
:
|
932
|
+
jp: 'mws.amazonservices.jp',
|
933
|
+
uk: 'mws-eu.amazonservices.com',
|
934
|
+
de: 'mws-eu.amazonservices.com',
|
935
|
+
eu: 'mws-eu.amazonservices.com',
|
936
|
+
us: 'mws.amazonservices.com',
|
937
|
+
na: 'mws.amazonservices.com'
|
823
938
|
}
|
824
939
|
end
|
825
940
|
|
@@ -828,14 +943,14 @@ module AmazonPay
|
|
828
943
|
# API call.
|
829
944
|
def set_provider_credit_details(provider_credit_details)
|
830
945
|
member_details = {}
|
831
|
-
provider_credit_details.each_with_index
|
946
|
+
provider_credit_details.each_with_index do |val, index|
|
832
947
|
member = index + 1
|
833
948
|
member_details["ProviderCreditList.member.#{member}.ProviderId"] = val[:provider_id]
|
834
949
|
member_details["ProviderCreditList.member.#{member}.CreditAmount.Amount"] = val[:amount]
|
835
950
|
member_details["ProviderCreditList.member.#{member}.CreditAmount.CurrencyCode"] = val[:currency_code]
|
836
|
-
|
951
|
+
end
|
837
952
|
|
838
|
-
|
953
|
+
member_details
|
839
954
|
end
|
840
955
|
|
841
956
|
# This method builds the provider credit reversal
|
@@ -843,33 +958,45 @@ module AmazonPay
|
|
843
958
|
# API call.
|
844
959
|
def set_provider_credit_reversal_details(provider_credit_reversal_details)
|
845
960
|
member_details = {}
|
846
|
-
provider_credit_reversal_details.each_with_index
|
961
|
+
provider_credit_reversal_details.each_with_index do |val, index|
|
847
962
|
member = index + 1
|
848
963
|
member_details["ProviderCreditReversalList.member.#{member}.ProviderId"] = val[:provider_id]
|
849
964
|
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.Amount"] = val[:amount]
|
850
965
|
member_details["ProviderCreditReversalList.member.#{member}.CreditReversalAmount.CurrencyCode"] = val[:currency_code]
|
851
|
-
|
966
|
+
end
|
852
967
|
|
853
|
-
|
968
|
+
member_details
|
969
|
+
end
|
970
|
+
|
971
|
+
def get_categories_list(attribute_key, categories)
|
972
|
+
list = {}
|
973
|
+
|
974
|
+
categories.each_with_index do |val, index|
|
975
|
+
list.merge!({"#{attribute_key}.SellerOrderAttributes.OrderItemCategories.OrderItemCategory.#{index + 1}" => val})
|
976
|
+
end
|
977
|
+
|
978
|
+
list
|
854
979
|
end
|
855
980
|
|
856
981
|
def operation(parameters, optional)
|
857
982
|
AmazonPay::Request.new(
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
983
|
+
parameters,
|
984
|
+
optional,
|
985
|
+
@default_hash,
|
986
|
+
@mws_endpoint,
|
987
|
+
@sandbox_str,
|
988
|
+
@secret_key,
|
989
|
+
@proxy_addr,
|
990
|
+
@proxy_port,
|
991
|
+
@proxy_user,
|
992
|
+
@proxy_pass,
|
993
|
+
@throttle,
|
994
|
+
@application_name,
|
995
|
+
@application_version,
|
996
|
+
@log_enabled,
|
997
|
+
@log_file_name,
|
998
|
+
@log_level
|
999
|
+
).send_post
|
871
1000
|
end
|
872
|
-
|
873
1001
|
end
|
874
|
-
|
875
1002
|
end
|
@@ -67,6 +67,48 @@ module AmazonPay
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
# Modify order attributes such as CustomInformation
|
71
|
+
# for the order
|
72
|
+
# This is a convenience function for set_order_attributes to prevent accidentally passing
|
73
|
+
# extra variables that can't be modified ater Amazon Order Reference (ORO) is confirmed.
|
74
|
+
# @see https://pay.amazon.com/documentation/apireference/201751630#201751960
|
75
|
+
# @param amazon_order_reference_id [String]
|
76
|
+
# @optional request_payment_authorization [Boolean]
|
77
|
+
# @optional seller_note [String]
|
78
|
+
# @optional seller_order_id [String]
|
79
|
+
# @optional store_name [String]
|
80
|
+
# @optional custom_information [String]
|
81
|
+
# @optional merchant_id [String]
|
82
|
+
# @optional mws_auth_token [String]
|
83
|
+
def modify_order_attributes(
|
84
|
+
amazon_order_reference_id,
|
85
|
+
seller_note: nil,
|
86
|
+
seller_order_id: nil,
|
87
|
+
payment_service_provider_id: nil,
|
88
|
+
payment_service_provider_order_id: nil,
|
89
|
+
request_payment_authorization: nil,
|
90
|
+
store_name: nil,
|
91
|
+
custom_information: nil,
|
92
|
+
merchant_id: @merchant_id,
|
93
|
+
mws_auth_token: nil
|
94
|
+
)
|
95
|
+
|
96
|
+
set_order_attributes(amazon_order_reference_id,
|
97
|
+
# amount:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
|
98
|
+
# currency_code:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
|
99
|
+
# platform_id:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
|
100
|
+
seller_note: seller_note,
|
101
|
+
seller_order_id: seller_order_id,
|
102
|
+
payment_service_provider_id: payment_service_provider_id,
|
103
|
+
payment_service_provider_order_id: payment_service_provider_order_id,
|
104
|
+
request_payment_authorization: request_payment_authorization,
|
105
|
+
store_name: store_name,
|
106
|
+
# order_item_categories:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
|
107
|
+
custom_information: custom_information,
|
108
|
+
merchant_id: merchant_id,
|
109
|
+
mws_auth_token: mws_auth_token)
|
110
|
+
end
|
111
|
+
|
70
112
|
private
|
71
113
|
|
72
114
|
def call_order_reference_api(
|
@@ -4,9 +4,10 @@ require 'net/http'
|
|
4
4
|
require 'net/https'
|
5
5
|
require 'openssl'
|
6
6
|
require 'uri'
|
7
|
+
require 'logger'
|
8
|
+
require 'stringio'
|
7
9
|
|
8
10
|
module AmazonPay
|
9
|
-
|
10
11
|
class IpnWasNotAuthenticError < StandardError
|
11
12
|
end
|
12
13
|
|
@@ -17,19 +18,26 @@ module AmazonPay
|
|
17
18
|
# there are many helper methods in place to extract information received
|
18
19
|
# from the ipn notification.
|
19
20
|
class IpnHandler
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
'Type',
|
21
|
+
SIGNABLE_KEYS = %w[
|
22
|
+
Message
|
23
|
+
MessageId
|
24
|
+
Timestamp
|
25
|
+
TopicArn
|
26
|
+
Type
|
27
27
|
].freeze
|
28
28
|
|
29
|
-
COMMON_NAME = 'sns.amazonaws.com'
|
29
|
+
COMMON_NAME = 'sns.amazonaws.com'.freeze
|
30
30
|
|
31
|
-
attr_reader(
|
32
|
-
|
31
|
+
attr_reader(
|
32
|
+
:headers,
|
33
|
+
:body
|
34
|
+
)
|
35
|
+
attr_accessor(
|
36
|
+
:proxy_addr,
|
37
|
+
:proxy_port,
|
38
|
+
:proxy_user,
|
39
|
+
:proxy_pass
|
40
|
+
)
|
33
41
|
|
34
42
|
# @param headers [request.headers]
|
35
43
|
# @param body [request.body.read]
|
@@ -38,12 +46,16 @@ module AmazonPay
|
|
38
46
|
# @optional proxy_user [String]
|
39
47
|
# @optional proxy_pass [String]
|
40
48
|
def initialize(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
headers,
|
50
|
+
body,
|
51
|
+
proxy_addr: :ENV,
|
52
|
+
proxy_port: nil,
|
53
|
+
proxy_user: nil,
|
54
|
+
proxy_pass: nil,
|
55
|
+
log_enabled: false,
|
56
|
+
log_file_name: nil,
|
57
|
+
log_level: :DEBUG
|
58
|
+
)
|
47
59
|
|
48
60
|
@body = body
|
49
61
|
@raw = parse_from(@body)
|
@@ -52,23 +64,30 @@ module AmazonPay
|
|
52
64
|
@proxy_port = proxy_port
|
53
65
|
@proxy_user = proxy_user
|
54
66
|
@proxy_pass = proxy_pass
|
67
|
+
|
68
|
+
@log_enabled = log_enabled
|
69
|
+
if @log_enabled
|
70
|
+
log_set = AmazonPay::LogInitializer.new(
|
71
|
+
log_file_name,
|
72
|
+
log_level
|
73
|
+
)
|
74
|
+
@logger = log_set.create_logger
|
75
|
+
end
|
55
76
|
end
|
56
77
|
|
57
78
|
# This method will authenticate the ipn message sent from Amazon.
|
58
79
|
# It will return true if everything is verified. It will raise an
|
59
80
|
# error message if verification fails.
|
60
81
|
def authentic?
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
raise e.message
|
71
|
-
end
|
82
|
+
decoded_from_base64 = Base64.decode64(signature)
|
83
|
+
validate_header
|
84
|
+
validate_subject(get_certificate.subject)
|
85
|
+
public_key = get_public_key_from(get_certificate)
|
86
|
+
verify_public_key(public_key, decoded_from_base64, canonical_string)
|
87
|
+
|
88
|
+
return true
|
89
|
+
rescue IpnWasNotAuthenticError => e
|
90
|
+
raise e.message
|
72
91
|
end
|
73
92
|
|
74
93
|
def type
|
@@ -108,27 +127,27 @@ module AmazonPay
|
|
108
127
|
end
|
109
128
|
|
110
129
|
def notification_type
|
111
|
-
parse_from(@raw['Message'])[
|
130
|
+
parse_from(@raw['Message'])['NotificationType']
|
112
131
|
end
|
113
132
|
|
114
133
|
def seller_id
|
115
|
-
parse_from(@raw['Message'])[
|
134
|
+
parse_from(@raw['Message'])['SellerId']
|
116
135
|
end
|
117
136
|
|
118
137
|
def environment
|
119
|
-
parse_from(@raw['Message'])[
|
138
|
+
parse_from(@raw['Message'])['ReleaseEnvironment']
|
120
139
|
end
|
121
140
|
|
122
141
|
def version
|
123
|
-
parse_from(@raw['Message'])[
|
142
|
+
parse_from(@raw['Message'])['Version']
|
124
143
|
end
|
125
144
|
|
126
145
|
def notification_data
|
127
|
-
parse_from(@raw['Message'])[
|
146
|
+
parse_from(@raw['Message'])['NotificationData']
|
128
147
|
end
|
129
148
|
|
130
149
|
def message_timestamp
|
131
|
-
parse_from(@raw['Message'])[
|
150
|
+
parse_from(@raw['Message'])['Timestamp']
|
132
151
|
end
|
133
152
|
|
134
153
|
def parse_from(json)
|
@@ -150,7 +169,7 @@ module AmazonPay
|
|
150
169
|
text = ''
|
151
170
|
SIGNABLE_KEYS.each do |key|
|
152
171
|
value = @raw[key]
|
153
|
-
next if value.nil?
|
172
|
+
next if value.nil? || value.empty?
|
154
173
|
text << key << "\n"
|
155
174
|
text << value << "\n"
|
156
175
|
end
|
@@ -170,8 +189,12 @@ module AmazonPay
|
|
170
189
|
tries = 0
|
171
190
|
begin
|
172
191
|
resp = https_get(url)
|
192
|
+
if @log_enabled
|
193
|
+
data = AmazonPay::Sanitize.new(resp.body)
|
194
|
+
@logger.debug(data.sanitize_response_data)
|
195
|
+
end
|
173
196
|
resp.body
|
174
|
-
rescue => error
|
197
|
+
rescue StandardError => error
|
175
198
|
tries += 1
|
176
199
|
retry if tries < 3
|
177
200
|
raise error
|
@@ -193,7 +216,7 @@ module AmazonPay
|
|
193
216
|
unless
|
194
217
|
@headers['x-amz-sns-message-type'] == 'Notification'
|
195
218
|
then
|
196
|
-
msg =
|
219
|
+
msg = 'Error - Header does not contain x-amz-sns-message-type header'
|
197
220
|
raise IpnWasNotAuthenticError, msg
|
198
221
|
end
|
199
222
|
end
|
@@ -203,7 +226,7 @@ module AmazonPay
|
|
203
226
|
unless
|
204
227
|
subject[4][1] == COMMON_NAME
|
205
228
|
then
|
206
|
-
msg =
|
229
|
+
msg = 'Error - Unable to verify certificate subject issued by Amazon'
|
207
230
|
raise IpnWasNotAuthenticError, msg
|
208
231
|
end
|
209
232
|
end
|
@@ -212,11 +235,9 @@ module AmazonPay
|
|
212
235
|
unless
|
213
236
|
public_key.verify(OpenSSL::Digest::SHA1.new, decoded_signature, signed_string)
|
214
237
|
then
|
215
|
-
msg =
|
238
|
+
msg = 'Error - Unable to verify public key with signature and signed string'
|
216
239
|
raise IpnWasNotAuthenticError, msg
|
217
240
|
end
|
218
241
|
end
|
219
|
-
|
220
242
|
end
|
221
|
-
|
222
243
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module AmazonPay
|
5
|
+
# This class creates the logger to use.
|
6
|
+
class LogInitializer
|
7
|
+
def initialize(
|
8
|
+
log_file_name,
|
9
|
+
log_level
|
10
|
+
)
|
11
|
+
|
12
|
+
@log_level_set = log_hash[log_level.upcase]
|
13
|
+
@log_file_name = log_file_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_logger
|
17
|
+
@logger = if @log_file_name
|
18
|
+
Logger.new(@log_file_name)
|
19
|
+
else
|
20
|
+
Logger.new(STDOUT)
|
21
|
+
end
|
22
|
+
|
23
|
+
@logger.level = @log_level_set
|
24
|
+
# a simple formatter
|
25
|
+
@logger.datetime_format = '%Y-%m-%d %H:%M:%S'
|
26
|
+
# e.g. "2004-01-03 00:54:26"
|
27
|
+
@logger.formatter = proc do |_severity, datetime, progname, msg|
|
28
|
+
%({time: "#{datetime}\n", message: "#{msg} from #{progname}"}\n)
|
29
|
+
end
|
30
|
+
|
31
|
+
@logger
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def log_hash
|
37
|
+
{
|
38
|
+
UNKNOWN: Logger::UNKNOWN,
|
39
|
+
FATAL: Logger::FATAL,
|
40
|
+
ERROR: Logger::ERROR,
|
41
|
+
WARN: Logger::WARN,
|
42
|
+
INFO: Logger::INFO,
|
43
|
+
DEBUG: Logger::DEBUG
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/amazon_pay/login.rb
CHANGED
File without changes
|
data/lib/amazon_pay/request.rb
CHANGED
@@ -3,29 +3,33 @@ require 'net/http'
|
|
3
3
|
require 'net/https'
|
4
4
|
require 'base64'
|
5
5
|
require 'openssl'
|
6
|
+
require 'logger'
|
7
|
+
require 'stringio'
|
6
8
|
|
7
9
|
module AmazonPay
|
8
|
-
|
9
10
|
# This class creates the request to send to the
|
10
11
|
# specified MWS endpoint.
|
11
12
|
class Request
|
12
|
-
|
13
13
|
MAX_RETRIES = 3
|
14
14
|
|
15
15
|
def initialize(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
parameters,
|
17
|
+
optional,
|
18
|
+
default_hash,
|
19
|
+
mws_endpoint,
|
20
|
+
sandbox_str,
|
21
|
+
secret_key,
|
22
|
+
proxy_addr,
|
23
|
+
proxy_port,
|
24
|
+
proxy_user,
|
25
|
+
proxy_pass,
|
26
|
+
throttle,
|
27
|
+
application_name,
|
28
|
+
application_version,
|
29
|
+
log_enabled,
|
30
|
+
log_file_name,
|
31
|
+
log_level
|
32
|
+
)
|
29
33
|
|
30
34
|
@parameters = parameters
|
31
35
|
@optional = optional
|
@@ -33,6 +37,7 @@ module AmazonPay
|
|
33
37
|
@mws_endpoint = mws_endpoint
|
34
38
|
@sandbox_str = sandbox_str
|
35
39
|
@secret_key = secret_key
|
40
|
+
@log_enabled = log_enabled
|
36
41
|
@proxy_addr = proxy_addr
|
37
42
|
@proxy_port = proxy_port
|
38
43
|
@proxy_user = proxy_user
|
@@ -40,6 +45,14 @@ module AmazonPay
|
|
40
45
|
@throttle = throttle
|
41
46
|
@application_name = application_name
|
42
47
|
@application_version = application_version
|
48
|
+
|
49
|
+
if @log_enabled
|
50
|
+
log_set = AmazonPay::LogInitializer.new(
|
51
|
+
log_file_name,
|
52
|
+
log_level
|
53
|
+
)
|
54
|
+
@logger = log_set.create_logger
|
55
|
+
end
|
43
56
|
end
|
44
57
|
|
45
58
|
# This method sends the post request.
|
@@ -56,10 +69,15 @@ module AmazonPay
|
|
56
69
|
def build_post_url
|
57
70
|
@optional.map { |k, v| @parameters[k] = v unless v.nil? }
|
58
71
|
@parameters = @default_hash.merge(@parameters)
|
59
|
-
post_url = @parameters.sort.map { |k, v| "#{k}=#{
|
60
|
-
post_body = [
|
61
|
-
post_url +=
|
62
|
-
|
72
|
+
post_url = @parameters.sort.map { |k, v| "#{k}=#{custom_escape(v)}" }.join('&')
|
73
|
+
post_body = ['POST', @mws_endpoint.to_s, "/#{@sandbox_str}/#{AmazonPay::API_VERSION}", post_url].join("\n")
|
74
|
+
post_url += '&Signature=' + sign(post_body)
|
75
|
+
if @log_enabled
|
76
|
+
data = AmazonPay::Sanitize.new(post_url)
|
77
|
+
@logger.debug("request/Post: #{data.sanitize_request_data}")
|
78
|
+
end
|
79
|
+
|
80
|
+
post_url
|
63
81
|
end
|
64
82
|
|
65
83
|
# This method signs the post body that is being sent
|
@@ -76,12 +94,16 @@ module AmazonPay
|
|
76
94
|
https = Net::HTTP.new(uri.host, uri.port, @proxy_addr, @proxy_port, @proxy_user, @proxy_pass)
|
77
95
|
https.use_ssl = true
|
78
96
|
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
79
|
-
|
80
|
-
user_agent = {
|
97
|
+
|
98
|
+
user_agent = { 'User-Agent' => "#{AmazonPay::SDK_NAME}/#{AmazonPay::VERSION}; (#{@application_name + '/' if @application_name}#{@application_version.to_s + ';' if @application_version} #{RUBY_VERSION}; #{RUBY_PLATFORM})" }
|
81
99
|
|
82
100
|
tries = 0
|
83
101
|
begin
|
84
102
|
response = https.post(uri.path, post_url, user_agent)
|
103
|
+
if @log_enabled
|
104
|
+
data = AmazonPay::Sanitize.new(response.body)
|
105
|
+
@logger.debug("response: #{data.sanitize_response_data}")
|
106
|
+
end
|
85
107
|
if @throttle.eql?(true)
|
86
108
|
if response.code.eql?('500')
|
87
109
|
raise 'InternalServerError'
|
@@ -90,7 +112,7 @@ module AmazonPay
|
|
90
112
|
end
|
91
113
|
end
|
92
114
|
AmazonPay::Response.new(response)
|
93
|
-
rescue => error
|
115
|
+
rescue StandardError => error
|
94
116
|
tries += 1
|
95
117
|
sleep(get_seconds_for_try_count(tries))
|
96
118
|
retry if tries <= MAX_RETRIES
|
@@ -99,16 +121,14 @@ module AmazonPay
|
|
99
121
|
end
|
100
122
|
|
101
123
|
def get_seconds_for_try_count(try_count)
|
102
|
-
seconds = { 1=>1, 2=>4, 3=>10, 4=>0 }
|
124
|
+
seconds = { 1 => 1, 2 => 4, 3 => 10, 4 => 0 }
|
103
125
|
seconds[try_count]
|
104
126
|
end
|
105
127
|
|
106
128
|
def custom_escape(val)
|
107
129
|
val.to_s.gsub(/([^\w.~-]+)/) do
|
108
|
-
|
130
|
+
'%' + Regexp.last_match(1).unpack('H2' * Regexp.last_match(1).bytesize).join('%').upcase
|
109
131
|
end
|
110
132
|
end
|
111
|
-
|
112
133
|
end
|
113
|
-
|
114
134
|
end
|
data/lib/amazon_pay/response.rb
CHANGED
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module AmazonPay
|
2
|
+
class Sanitize
|
3
|
+
def initialize(input_data)
|
4
|
+
@copy = input_data ? input_data.dup : ''
|
5
|
+
end
|
6
|
+
|
7
|
+
def sanitize_request_data
|
8
|
+
# Array of item to remove
|
9
|
+
|
10
|
+
patterns = %w[
|
11
|
+
Buyer
|
12
|
+
PhysicalDestination
|
13
|
+
BillingAddress
|
14
|
+
AuthorizationBillingAddress
|
15
|
+
SellerNote
|
16
|
+
SellerAuthorizationNote
|
17
|
+
SellerCaptureNote
|
18
|
+
SellerRefundNote
|
19
|
+
]
|
20
|
+
|
21
|
+
patterns.each do |s|
|
22
|
+
@copy.gsub!(/([?|&]#{s}=)[^\&]+/ms, s + '=*REMOVED*')
|
23
|
+
end
|
24
|
+
|
25
|
+
@copy
|
26
|
+
end
|
27
|
+
|
28
|
+
def sanitize_response_data
|
29
|
+
# Array of item to remove
|
30
|
+
|
31
|
+
patterns = []
|
32
|
+
patterns.push(/(?<=<Buyer>).*(?=<\/Buyer>)/s)
|
33
|
+
patterns.push(/(?<=<PhysicalDestination>).*(?=<\/PhysicalDestination>)/ms)
|
34
|
+
patterns.push(/(?<=<BillingAddress>).*(?=<\/BillingAddress>)/s)
|
35
|
+
patterns.push(/(?<=<SellerNote>).*(?=<\/SellerNote>)/s)
|
36
|
+
patterns.push(/(?<=<AuthorizationBillingAddress>).*(?=<\/AuthorizationBillingAddress>)/s)
|
37
|
+
patterns.push(/(?<=<SellerAuthorizationNote>).*(?=<\/SellerAuthorizationNote>)/s)
|
38
|
+
patterns.push(/(?<=<SellerCaptureNote>).*(?=<\/SellerCaptureNote>)/s)
|
39
|
+
patterns.push(/(?<=<SellerRefundNote>).*(?=<\/SellerRefundNote>)/s)
|
40
|
+
|
41
|
+
patterns.each do |s|
|
42
|
+
@copy.gsub!(s, '*REMOVED*')
|
43
|
+
end
|
44
|
+
|
45
|
+
@copy
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/amazon_pay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon_pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AmazonPay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: AmazonPay Ruby SDK
|
14
14
|
email: amazon-pay-sdk@amazon.com
|
@@ -23,9 +23,11 @@ files:
|
|
23
23
|
- lib/amazon_pay/client.rb
|
24
24
|
- lib/amazon_pay/client_helper.rb
|
25
25
|
- lib/amazon_pay/ipn_handler.rb
|
26
|
+
- lib/amazon_pay/log_initializer.rb
|
26
27
|
- lib/amazon_pay/login.rb
|
27
28
|
- lib/amazon_pay/request.rb
|
28
29
|
- lib/amazon_pay/response.rb
|
30
|
+
- lib/amazon_pay/sanitize.rb
|
29
31
|
- lib/amazon_pay/version.rb
|
30
32
|
homepage: https://github.com/amzn/amazon-pay-sdk-ruby
|
31
33
|
licenses:
|
@@ -47,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
49
|
version: '0'
|
48
50
|
requirements: []
|
49
51
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.6.
|
52
|
+
rubygems_version: 2.6.12
|
51
53
|
signing_key:
|
52
54
|
specification_version: 4
|
53
55
|
summary: AmazonPay Ruby SDK
|