amazon_pay 2.3.4 → 2.4.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 +5 -5
- data/LICENSE +0 -0
- data/NOTICE +0 -0
- data/README.md +22 -0
- data/lib/amazon_pay/client.rb +28 -4
- data/lib/amazon_pay/client_helper.rb +12 -13
- data/lib/amazon_pay/ipn_handler.rb +18 -35
- data/lib/amazon_pay/log_initializer.rb +2 -0
- data/lib/amazon_pay/login.rb +12 -16
- data/lib/amazon_pay/request.rb +6 -13
- data/lib/amazon_pay/response.rb +26 -34
- data/lib/amazon_pay/sanitize.rb +11 -8
- data/lib/amazon_pay/version.rb +3 -3
- metadata +4 -5
- data/CHANGES.txt +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac36743b074c7959cb0d4ac39035e84149acd9ab
|
4
|
+
data.tar.gz: 9753cb328838eaa172b2e79a70f2b1cb27569e03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6625d1ff7ecc32f39665f672f38be1fb0c7508f7b39f99f91c1740f736fac681c56c63a7c33f4a27c02ccf3aab933423c2f2ff2cd1d882a23f0e6421d9a32bd9
|
7
|
+
data.tar.gz: 2c0869904a6de28ab2b2729b9473903e84b6331186c6950c543216e6b6ab882a4a9aab1a50f9db6fb82a425e7307913f1911998d22b09ac98ef3fa0ea9ee30c5
|
data/LICENSE
CHANGED
File without changes
|
data/NOTICE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -155,6 +155,28 @@ response = client.list_order_reference(
|
|
155
155
|
|
156
156
|
```
|
157
157
|
|
158
|
+
Below is an example on how to GetMerchantAccountStatus
|
159
|
+
API call:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
require 'amazon_pay'
|
163
|
+
|
164
|
+
# Your Amazon Pay keys are
|
165
|
+
# available in your Seller Central account
|
166
|
+
merchant_id = 'YOUR_MERCHANT_ID'
|
167
|
+
access_key = 'YOUR_ACCESS_KEY'
|
168
|
+
secret_key = 'YOUR_SECRET_KEY'
|
169
|
+
|
170
|
+
client = AmazonPay::Client.new(
|
171
|
+
merchant_id,
|
172
|
+
access_key,
|
173
|
+
secret_key
|
174
|
+
)
|
175
|
+
|
176
|
+
response = client.client.get_merchant_account_status
|
177
|
+
|
178
|
+
```
|
179
|
+
|
158
180
|
Below is an example on how to query using the next token received
|
159
181
|
from ListOrderReference using the ListOrderReferenceByNextToken
|
160
182
|
API call:
|
data/lib/amazon_pay/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize, Metrics/ClassLength, Metrics/ParameterLists, Style/AccessorMethodName
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
require 'logger'
|
3
5
|
require 'stringio'
|
@@ -55,7 +57,7 @@ module AmazonPay
|
|
55
57
|
merchant_id,
|
56
58
|
access_key,
|
57
59
|
secret_key,
|
58
|
-
sandbox:false,
|
60
|
+
sandbox: false,
|
59
61
|
currency_code: :usd,
|
60
62
|
region: :na,
|
61
63
|
platform_id: nil,
|
@@ -66,7 +68,7 @@ module AmazonPay
|
|
66
68
|
proxy_port: nil,
|
67
69
|
proxy_user: nil,
|
68
70
|
proxy_pass: nil,
|
69
|
-
log_enabled:false,
|
71
|
+
log_enabled: false,
|
70
72
|
log_file_name: nil,
|
71
73
|
log_level: :DEBUG
|
72
74
|
)
|
@@ -125,6 +127,7 @@ module AmazonPay
|
|
125
127
|
# @optional seller_order_id [String]
|
126
128
|
# @optional store_name [String]
|
127
129
|
# @optional custom_information [String]
|
130
|
+
# @optional supplementary_data [String]
|
128
131
|
# @optional merchant_id [String]
|
129
132
|
# @optional mws_auth_token [String]
|
130
133
|
def create_order_reference_for_id(
|
@@ -139,6 +142,7 @@ module AmazonPay
|
|
139
142
|
seller_order_id: nil,
|
140
143
|
store_name: nil,
|
141
144
|
custom_information: nil,
|
145
|
+
supplementary_data: nil,
|
142
146
|
merchant_id: @merchant_id,
|
143
147
|
mws_auth_token: nil
|
144
148
|
)
|
@@ -160,6 +164,7 @@ module AmazonPay
|
|
160
164
|
'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
|
161
165
|
'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
|
162
166
|
'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
|
167
|
+
'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
|
163
168
|
'MWSAuthToken' => mws_auth_token
|
164
169
|
}
|
165
170
|
|
@@ -173,7 +178,7 @@ module AmazonPay
|
|
173
178
|
# @optional access_token [String]
|
174
179
|
# @optional merchant_id [String]
|
175
180
|
# @optional mws_auth_token [String]
|
176
|
-
|
181
|
+
|
177
182
|
def get_billing_agreement_details(
|
178
183
|
amazon_billing_agreement_id,
|
179
184
|
address_consent_token: nil,
|
@@ -308,6 +313,7 @@ module AmazonPay
|
|
308
313
|
# @optional seller_order_id [String]
|
309
314
|
# @optional store_name [String]
|
310
315
|
# @optional inherit_shipping_address [Boolean]
|
316
|
+
# @optional supplementary_data [String]
|
311
317
|
# @optional merchant_id [String]
|
312
318
|
# @optional mws_auth_token [String]
|
313
319
|
def authorize_on_billing_agreement(
|
@@ -325,6 +331,7 @@ module AmazonPay
|
|
325
331
|
seller_order_id: nil,
|
326
332
|
store_name: nil,
|
327
333
|
inherit_shipping_address: nil,
|
334
|
+
supplementary_data: nil,
|
328
335
|
merchant_id: @merchant_id,
|
329
336
|
mws_auth_token: nil
|
330
337
|
)
|
@@ -348,6 +355,7 @@ module AmazonPay
|
|
348
355
|
'SellerOrderAttributes.CustomInformation' => custom_information,
|
349
356
|
'SellerOrderAttributes.SellerOrderId' => seller_order_id,
|
350
357
|
'SellerOrderAttributes.StoreName' => store_name,
|
358
|
+
'SellerOrderAttributes.SupplementaryData' => supplementary_data,
|
351
359
|
'InheritShippingAddress' => inherit_shipping_address,
|
352
360
|
'MWSAuthToken' => mws_auth_token
|
353
361
|
}
|
@@ -583,7 +591,7 @@ module AmazonPay
|
|
583
591
|
def set_order_attributes(
|
584
592
|
amazon_order_reference_id,
|
585
593
|
amount: nil,
|
586
|
-
currency_code:
|
594
|
+
currency_code: @currency_code,
|
587
595
|
platform_id: nil,
|
588
596
|
seller_note: nil,
|
589
597
|
seller_order_id: nil,
|
@@ -619,6 +627,8 @@ module AmazonPay
|
|
619
627
|
'MWSAuthToken' => mws_auth_token
|
620
628
|
}
|
621
629
|
|
630
|
+
optional['OrderAttributes.OrderTotal.CurrencyCode'] = nil if amount.nil?
|
631
|
+
|
622
632
|
if order_item_categories
|
623
633
|
optional.merge!(
|
624
634
|
get_categories_list(
|
@@ -635,10 +645,18 @@ module AmazonPay
|
|
635
645
|
# information has been set on the order reference
|
636
646
|
# @see https://pay.amazon.com/documentation/apireference/201751630#201751980
|
637
647
|
# @param amazon_order_reference_id [String]
|
648
|
+
# @optional success_url [String]
|
649
|
+
# @optional failure_url [String]
|
650
|
+
# @optional authorization_amount [String]
|
651
|
+
# @optional currency_code [String]
|
638
652
|
# @optional merchant_id [String]
|
639
653
|
# @optional mws_auth_token [String]
|
640
654
|
def confirm_order_reference(
|
641
655
|
amazon_order_reference_id,
|
656
|
+
success_url: nil,
|
657
|
+
failure_url: nil,
|
658
|
+
authorization_amount: nil,
|
659
|
+
currency_code: @currency_code,
|
642
660
|
merchant_id: @merchant_id,
|
643
661
|
mws_auth_token: nil
|
644
662
|
)
|
@@ -650,9 +668,15 @@ module AmazonPay
|
|
650
668
|
}
|
651
669
|
|
652
670
|
optional = {
|
671
|
+
'SuccessUrl' => success_url,
|
672
|
+
'FailureUrl' => failure_url,
|
673
|
+
'AuthorizationAmount.Amount' => authorization_amount,
|
674
|
+
'AuthorizationAmount.CurrencyCode' => currency_code,
|
653
675
|
'MWSAuthToken' => mws_auth_token
|
654
676
|
}
|
655
677
|
|
678
|
+
optional['AuthorizationAmount.CurrencyCode'] = nil if authorization_amount.nil?
|
679
|
+
|
656
680
|
operation(parameters, optional)
|
657
681
|
end
|
658
682
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/ClassLength, Metrics/ParameterLists
|
2
|
+
|
1
3
|
module AmazonPay
|
2
4
|
# This will extend the client class to add additional
|
3
5
|
# helper methods that combine core API calls.
|
@@ -31,8 +33,8 @@ module AmazonPay
|
|
31
33
|
mws_auth_token: nil
|
32
34
|
)
|
33
35
|
|
34
|
-
if
|
35
|
-
|
36
|
+
if order_reference?(amazon_reference_id)
|
37
|
+
call_order_reference_api(
|
36
38
|
amazon_reference_id,
|
37
39
|
authorization_reference_id,
|
38
40
|
charge_amount,
|
@@ -46,11 +48,8 @@ module AmazonPay
|
|
46
48
|
merchant_id,
|
47
49
|
mws_auth_token
|
48
50
|
)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if is_billing_agreement?(amazon_reference_id)
|
53
|
-
response = call_billing_agreement_api(
|
51
|
+
elsif billing_agreement?(amazon_reference_id)
|
52
|
+
call_billing_agreement_api(
|
54
53
|
amazon_reference_id,
|
55
54
|
authorization_reference_id,
|
56
55
|
charge_amount,
|
@@ -64,7 +63,6 @@ module AmazonPay
|
|
64
63
|
merchant_id,
|
65
64
|
mws_auth_token
|
66
65
|
)
|
67
|
-
return response
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
@@ -94,10 +92,11 @@ module AmazonPay
|
|
94
92
|
mws_auth_token: nil
|
95
93
|
)
|
96
94
|
|
97
|
-
set_order_attributes(
|
95
|
+
set_order_attributes(
|
98
96
|
# amount:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
|
99
97
|
# currency_code:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
|
100
98
|
# platform_id:(This value can't be modified after order is confirmed so it isn't passed to set_order_attributes)
|
99
|
+
amazon_order_reference_id,
|
101
100
|
seller_note: seller_note,
|
102
101
|
seller_order_id: seller_order_id,
|
103
102
|
payment_service_provider_id: payment_service_provider_id,
|
@@ -161,7 +160,7 @@ module AmazonPay
|
|
161
160
|
)
|
162
161
|
end
|
163
162
|
end
|
164
|
-
|
163
|
+
response
|
165
164
|
end
|
166
165
|
|
167
166
|
def call_billing_agreement_api(
|
@@ -223,14 +222,14 @@ module AmazonPay
|
|
223
222
|
merchant_id: merchant_id,
|
224
223
|
mws_auth_token: mws_auth_token
|
225
224
|
)
|
226
|
-
|
225
|
+
response
|
227
226
|
end
|
228
227
|
|
229
|
-
def
|
228
|
+
def order_reference?(amazon_reference_id)
|
230
229
|
amazon_reference_id.start_with?('S', 'P')
|
231
230
|
end
|
232
231
|
|
233
|
-
def
|
232
|
+
def billing_agreement?(amazon_reference_id)
|
234
233
|
amazon_reference_id.start_with?('C', 'B')
|
235
234
|
end
|
236
235
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# rubocop:disable Metrics/MethodLength, Metrics/ClassLength, Metrics/LineLength, Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Rails/Blank
|
2
|
+
|
1
3
|
require 'base64'
|
2
4
|
require 'json'
|
3
5
|
require 'net/http'
|
@@ -18,6 +20,10 @@ module AmazonPay
|
|
18
20
|
# there are many helper methods in place to extract information received
|
19
21
|
# from the ipn notification.
|
20
22
|
class IpnHandler
|
23
|
+
MSG_HEADER = 'Error - Header does not contain x-amz-sns-message-type header'.freeze
|
24
|
+
MSG_CERTIFICATE = 'Error - Unable to verify certificate subject issued by Amazon'.freeze
|
25
|
+
MSG_KEY = 'Error - Unable to verify public key with signature and signed string'.freeze
|
26
|
+
|
21
27
|
SIGNABLE_KEYS = %w[
|
22
28
|
Message
|
23
29
|
MessageId
|
@@ -66,13 +72,7 @@ module AmazonPay
|
|
66
72
|
@proxy_pass = proxy_pass
|
67
73
|
|
68
74
|
@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
|
75
|
+
@logger = AmazonPay::LogInitializer.new(log_file_name, log_level).create_logger if @log_enabled
|
76
76
|
end
|
77
77
|
|
78
78
|
# This method will authenticate the ipn message sent from Amazon.
|
@@ -81,8 +81,8 @@ module AmazonPay
|
|
81
81
|
def authentic?
|
82
82
|
decoded_from_base64 = Base64.decode64(signature)
|
83
83
|
validate_header
|
84
|
-
validate_subject(
|
85
|
-
public_key =
|
84
|
+
validate_subject(certificate.subject)
|
85
|
+
public_key = public_key_from(certificate)
|
86
86
|
verify_public_key(public_key, decoded_from_base64, canonical_string)
|
87
87
|
|
88
88
|
return true
|
@@ -156,12 +156,12 @@ module AmazonPay
|
|
156
156
|
|
157
157
|
protected
|
158
158
|
|
159
|
-
def
|
159
|
+
def certificate
|
160
160
|
cert_pem = download_cert(signing_cert_url)
|
161
161
|
OpenSSL::X509::Certificate.new(cert_pem)
|
162
162
|
end
|
163
163
|
|
164
|
-
def
|
164
|
+
def public_key_from(certificate)
|
165
165
|
OpenSSL::PKey::RSA.new(certificate.public_key)
|
166
166
|
end
|
167
167
|
|
@@ -178,11 +178,9 @@ module AmazonPay
|
|
178
178
|
|
179
179
|
def download_cert(url)
|
180
180
|
uri = URI.parse(url)
|
181
|
-
unless
|
182
|
-
|
183
|
-
|
184
|
-
File.extname(uri.path) == '.pem'
|
185
|
-
then
|
181
|
+
unless uri.scheme == 'https' &&
|
182
|
+
uri.host.match(/^sns\.[a-zA-Z0-9\-]{3,}\.amazonaws\.com(\.cn)?$/) &&
|
183
|
+
File.extname(uri.path) == '.pem'
|
186
184
|
msg = "Error - certificate is not hosted at AWS URL (https): #{url}"
|
187
185
|
raise IpnWasNotAuthenticError, msg
|
188
186
|
end
|
@@ -191,7 +189,7 @@ module AmazonPay
|
|
191
189
|
resp = https_get(url)
|
192
190
|
if @log_enabled
|
193
191
|
data = AmazonPay::Sanitize.new(resp.body)
|
194
|
-
@logger.debug(data.sanitize_response_data)
|
192
|
+
@logger.debug(data.sanitize_response_data)
|
195
193
|
end
|
196
194
|
resp.body
|
197
195
|
rescue StandardError => error
|
@@ -213,31 +211,16 @@ module AmazonPay
|
|
213
211
|
end
|
214
212
|
|
215
213
|
def validate_header
|
216
|
-
unless
|
217
|
-
@headers['x-amz-sns-message-type'] == 'Notification'
|
218
|
-
then
|
219
|
-
msg = 'Error - Header does not contain x-amz-sns-message-type header'
|
220
|
-
raise IpnWasNotAuthenticError, msg
|
221
|
-
end
|
214
|
+
raise IpnWasNotAuthenticError, MSG_HEADER unless @headers['x-amz-sns-message-type'] == 'Notification'
|
222
215
|
end
|
223
216
|
|
224
217
|
def validate_subject(certificate_subject)
|
225
218
|
subject = certificate_subject.to_a
|
226
|
-
unless
|
227
|
-
subject.rassoc(COMMON_NAME)
|
228
|
-
then
|
229
|
-
msg = 'Error - Unable to verify certificate subject issued by Amazon'
|
230
|
-
raise IpnWasNotAuthenticError, msg
|
231
|
-
end
|
219
|
+
raise IpnWasNotAuthenticError, MSG_CERTIFICATE unless subject.rassoc(COMMON_NAME)
|
232
220
|
end
|
233
221
|
|
234
222
|
def verify_public_key(public_key, decoded_signature, signed_string)
|
235
|
-
unless
|
236
|
-
public_key.verify(OpenSSL::Digest::SHA1.new, decoded_signature, signed_string)
|
237
|
-
then
|
238
|
-
msg = 'Error - Unable to verify public key with signature and signed string'
|
239
|
-
raise IpnWasNotAuthenticError, msg
|
240
|
-
end
|
223
|
+
raise IpnWasNotAuthenticError, MSG_KEY unless public_key.verify(OpenSSL::Digest::SHA1.new, decoded_signature, signed_string)
|
241
224
|
end
|
242
225
|
end
|
243
226
|
end
|
data/lib/amazon_pay/login.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
require 'net/http'
|
3
5
|
require 'net/https'
|
@@ -5,14 +7,12 @@ require 'json'
|
|
5
7
|
require 'openssl'
|
6
8
|
|
7
9
|
module AmazonPay
|
8
|
-
|
9
10
|
# AmazonPay API
|
10
11
|
#
|
11
12
|
# This class allows you to obtain user profile
|
12
13
|
# information once a user has logged into your
|
13
14
|
# application using their Amazon credentials.
|
14
15
|
class Login
|
15
|
-
|
16
16
|
attr_reader(:region)
|
17
17
|
|
18
18
|
attr_accessor(:client_id, :sandbox)
|
@@ -25,7 +25,7 @@ module AmazonPay
|
|
25
25
|
@region = region
|
26
26
|
@endpoint = region_hash[@region]
|
27
27
|
@sandbox = sandbox
|
28
|
-
@sandbox_str = @sandbox ?
|
28
|
+
@sandbox_str = @sandbox ? 'api.sandbox' : 'api'
|
29
29
|
end
|
30
30
|
|
31
31
|
# This method will validate the access token and
|
@@ -42,34 +42,30 @@ module AmazonPay
|
|
42
42
|
response = http.request(req)
|
43
43
|
decode = JSON.parse(response.body)
|
44
44
|
|
45
|
-
if decode['aud'] != @client_id
|
46
|
-
raise "Invalid Access Token"
|
47
|
-
end
|
45
|
+
raise 'Invalid Access Token' if decode['aud'] != @client_id
|
48
46
|
|
49
47
|
uri = URI.parse("https://#{@sandbox_str}.#{@endpoint}/user/profile")
|
50
48
|
req = Net::HTTP::Get.new(uri.request_uri)
|
51
|
-
req['Authorization'] =
|
49
|
+
req['Authorization'] = 'bearer ' + decoded_access_token
|
52
50
|
http = Net::HTTP.new(uri.host, uri.port)
|
53
51
|
http.use_ssl = true
|
54
52
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
55
53
|
response = http.request(req)
|
56
54
|
decoded_login_profile = JSON.parse(response.body)
|
57
|
-
|
55
|
+
decoded_login_profile
|
58
56
|
end
|
59
57
|
|
60
58
|
private
|
61
59
|
|
62
60
|
def region_hash
|
63
61
|
{
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
62
|
+
jp: 'amazon.co.jp',
|
63
|
+
uk: 'amazon.co.uk',
|
64
|
+
de: 'amazon.de',
|
65
|
+
eu: 'amazon.co.uk',
|
66
|
+
us: 'amazon.com',
|
67
|
+
na: 'amazon.com'
|
70
68
|
}
|
71
69
|
end
|
72
|
-
|
73
70
|
end
|
74
|
-
|
75
71
|
end
|
data/lib/amazon_pay/request.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
require 'net/http'
|
3
5
|
require 'net/https'
|
@@ -46,13 +48,7 @@ module AmazonPay
|
|
46
48
|
@application_name = application_name
|
47
49
|
@application_version = application_version
|
48
50
|
|
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
|
51
|
+
@logger = AmazonPay::LogInitializer.new(log_file_name, log_level).create_logger if @log_enabled
|
56
52
|
end
|
57
53
|
|
58
54
|
# This method sends the post request.
|
@@ -68,7 +64,7 @@ module AmazonPay
|
|
68
64
|
# the post url.
|
69
65
|
def build_post_url
|
70
66
|
@optional.map { |k, v| @parameters[k] = v unless v.nil? }
|
71
|
-
@parameters['Timestamp'] = Time.now.utc.iso8601 unless @parameters.
|
67
|
+
@parameters['Timestamp'] = Time.now.utc.iso8601 unless @parameters.key?('Timestamp')
|
72
68
|
@parameters = @default_hash.merge(@parameters)
|
73
69
|
post_url = @parameters.sort.map { |k, v| "#{k}=#{custom_escape(v)}" }.join('&')
|
74
70
|
post_body = ['POST', @mws_endpoint.to_s, "/#{@sandbox_str}/#{AmazonPay::API_VERSION}", post_url].join("\n")
|
@@ -106,11 +102,8 @@ module AmazonPay
|
|
106
102
|
@logger.debug("response: #{data.sanitize_response_data}")
|
107
103
|
end
|
108
104
|
if @throttle.eql?(true)
|
109
|
-
if response.code.eql?('500')
|
110
|
-
|
111
|
-
elsif response.code.eql?('503')
|
112
|
-
raise 'ServiceUnavailable or RequestThrottled'
|
113
|
-
end
|
105
|
+
raise 'InternalServerError' if response.code.eql?('500')
|
106
|
+
raise 'ServiceUnavailable or RequestThrottled' if response.code.eql?('503')
|
114
107
|
end
|
115
108
|
AmazonPay::Response.new(response)
|
116
109
|
rescue StandardError => error
|
data/lib/amazon_pay/response.rb
CHANGED
@@ -1,43 +1,35 @@
|
|
1
1
|
require 'rexml/document'
|
2
2
|
|
3
3
|
module AmazonPay
|
4
|
-
|
5
4
|
# This class provides helpers to parse the response
|
6
5
|
class Response
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
value = element.elements[xml_element].text
|
25
|
-
end
|
26
|
-
return value
|
27
|
-
end
|
28
|
-
|
29
|
-
def code
|
30
|
-
@response.code
|
31
|
-
end
|
32
|
-
|
33
|
-
def success
|
34
|
-
if @response.code.eql? '200'
|
35
|
-
return true
|
36
|
-
else
|
37
|
-
return false
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
|
10
|
+
def body
|
11
|
+
@response.body
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_xml
|
15
|
+
REXML::Document.new(body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_element(xpath, xml_element)
|
19
|
+
xml = to_xml
|
20
|
+
value = nil
|
21
|
+
xml.elements.each(xpath) do |element|
|
22
|
+
value = element.elements[xml_element].text
|
38
23
|
end
|
39
|
-
|
24
|
+
value
|
25
|
+
end
|
40
26
|
|
41
|
-
|
27
|
+
def code
|
28
|
+
@response.code
|
29
|
+
end
|
42
30
|
|
31
|
+
def success
|
32
|
+
@response.code.eql? '200'
|
33
|
+
end
|
34
|
+
end
|
43
35
|
end
|
data/lib/amazon_pay/sanitize.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# rubocop:disable Metrics/MethodLength, Metrics/LineLength
|
2
|
+
|
1
3
|
module AmazonPay
|
4
|
+
# Removes PII and other sensitive data for the logger
|
2
5
|
class Sanitize
|
3
6
|
def initialize(input_data)
|
4
7
|
@copy = input_data ? input_data.dup : ''
|
@@ -29,14 +32,14 @@ module AmazonPay
|
|
29
32
|
# Array of item to remove
|
30
33
|
|
31
34
|
patterns = []
|
32
|
-
patterns.push(
|
33
|
-
patterns.push(
|
34
|
-
patterns.push(
|
35
|
-
patterns.push(
|
36
|
-
patterns.push(
|
37
|
-
patterns.push(
|
38
|
-
patterns.push(
|
39
|
-
patterns.push(
|
35
|
+
patterns.push(%r{(?<=<Buyer>).*(?=<\/Buyer>)}s)
|
36
|
+
patterns.push(%r{(?<=<PhysicalDestination>).*(?=<\/PhysicalDestination>)}ms)
|
37
|
+
patterns.push(%r{(?<=<BillingAddress>).*(?=<\/BillingAddress>)}s)
|
38
|
+
patterns.push(%r{(?<=<SellerNote>).*(?=<\/SellerNote>)}s)
|
39
|
+
patterns.push(%r{(?<=<AuthorizationBillingAddress>).*(?=<\/AuthorizationBillingAddress>)}s)
|
40
|
+
patterns.push(%r{(?<=<SellerAuthorizationNote>).*(?=<\/SellerAuthorizationNote>)}s)
|
41
|
+
patterns.push(%r{(?<=<SellerCaptureNote>).*(?=<\/SellerCaptureNote>)}s)
|
42
|
+
patterns.push(%r{(?<=<SellerRefundNote>).*(?=<\/SellerRefundNote>)}s)
|
40
43
|
|
41
44
|
patterns.each do |s|
|
42
45
|
@copy.gsub!(s, '*REMOVED*')
|
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.4.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: 2019-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: AmazonPay Ruby SDK
|
14
14
|
email: amazon-pay-sdk@amazon.com
|
@@ -16,7 +16,6 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- CHANGES.txt
|
20
19
|
- LICENSE
|
21
20
|
- NOTICE
|
22
21
|
- README.md
|
@@ -32,7 +31,7 @@ files:
|
|
32
31
|
- lib/amazon_pay/version.rb
|
33
32
|
homepage: https://github.com/amzn/amazon-pay-sdk-ruby
|
34
33
|
licenses:
|
35
|
-
- Apache
|
34
|
+
- Apache License, Version 2.0
|
36
35
|
metadata: {}
|
37
36
|
post_install_message:
|
38
37
|
rdoc_options: []
|
@@ -50,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
49
|
version: '0'
|
51
50
|
requirements: []
|
52
51
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.
|
52
|
+
rubygems_version: 2.6.14
|
54
53
|
signing_key:
|
55
54
|
specification_version: 4
|
56
55
|
summary: AmazonPay Ruby SDK
|
data/CHANGES.txt
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
2.3.1 May 2018
|
2
|
-
- Modify ipn_handler to work with new Cert format
|
3
|
-
- Add CHANGES file
|
4
|
-
|
5
|
-
2.3.0 April 2018
|
6
|
-
- Add GetMerchantAccountStatus
|
7
|
-
|
8
|
-
2.2.1 March 2018
|
9
|
-
- Create new Timestamp parameter on every request
|
10
|
-
|
11
|
-
2.2.0 Jan 2018
|
12
|
-
- Add ListOrderReference
|
13
|
-
- Add ListOrderReferenceByNextToken
|
14
|
-
|
15
|
-
2.1.0 Jan 2018
|
16
|
-
- Add Logging
|
17
|
-
- Add SetOrderAttribute
|
18
|
-
|
19
|
-
2.0.0 Feb 2017
|
20
|
-
- Pay with Amazon to Amazon Pay rebranding
|
21
|
-
|
22
|
-
1.x - 2015
|
23
|
-
- Update README
|
24
|
-
- Update documentation links
|
25
|
-
- Change Login with Amazon API class and method name
|
26
|
-
- Add one time transaction and subscriptions api flow
|
27
|
-
- Add marketplace api support
|
28
|
-
- Add client helper method
|
29
|
-
- Add get user info api
|
30
|
-
- Separate post request from client
|
31
|
-
- Initial release
|