amazon_pay 2.3.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 608eb867ed536d6409ad4c5d454ad489d6c34168
4
- data.tar.gz: ade1f627a5fc56580ddc5b7922a725914ae0df6a
2
+ SHA256:
3
+ metadata.gz: fe42cd1c1161cf3ad88ccba66c243e7b816729672ab136c3a99e33ff1caceb53
4
+ data.tar.gz: 0e628bdcc508d9705e869cc30c4ed18fdd45cb32991459f181823cbb88dbf735
5
5
  SHA512:
6
- metadata.gz: 49a3d78cc72650945c2d081417b81d99a970b06d99e09a8e938b9436ba941a3210ddc980c6e7dcbb7181366d04153e5cd9dd75a92b81367d506e251b48208706
7
- data.tar.gz: bb0e83f78b3d340db12a3a86be126f9d13bc5beb2be74a1dbc20765f9b3fb68bd366a9eb11fa105355f07fb9584eb633d86a8214082ef19a8210206aa4403680
6
+ metadata.gz: fa3bebaa9bf5dcdceef3eebdf283ff48bbf335030e02db6d9f51241108a9f412eebadd18e07776cb7660f04ac31e13fd22fb14e17750cc7f2ddf4df81df133c7
7
+ data.tar.gz: 3adbe8158ad59d28a286c13e80900137ea8e86e10e9b94dd39967c156cc9db262f67f357e27e61c668419d0b2e89d7d568763c9a9cf140118c6e407142e91a03
@@ -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'
@@ -26,7 +28,6 @@ module AmazonPay
26
28
  )
27
29
 
28
30
  attr_accessor(
29
- :sandbox,
30
31
  :proxy_addr,
31
32
  :proxy_port,
32
33
  :proxy_user,
@@ -126,6 +127,7 @@ module AmazonPay
126
127
  # @optional seller_order_id [String]
127
128
  # @optional store_name [String]
128
129
  # @optional custom_information [String]
130
+ # @optional supplementary_data [String]
129
131
  # @optional merchant_id [String]
130
132
  # @optional mws_auth_token [String]
131
133
  def create_order_reference_for_id(
@@ -140,6 +142,7 @@ module AmazonPay
140
142
  seller_order_id: nil,
141
143
  store_name: nil,
142
144
  custom_information: nil,
145
+ supplementary_data: nil,
143
146
  merchant_id: @merchant_id,
144
147
  mws_auth_token: nil
145
148
  )
@@ -161,6 +164,7 @@ module AmazonPay
161
164
  'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
162
165
  'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
163
166
  'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
167
+ 'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
164
168
  'MWSAuthToken' => mws_auth_token
165
169
  }
166
170
 
@@ -174,6 +178,7 @@ module AmazonPay
174
178
  # @optional access_token [String]
175
179
  # @optional merchant_id [String]
176
180
  # @optional mws_auth_token [String]
181
+
177
182
  def get_billing_agreement_details(
178
183
  amazon_billing_agreement_id,
179
184
  address_consent_token: nil,
@@ -191,7 +196,10 @@ module AmazonPay
191
196
  optional = {
192
197
  # Preseving address_consent_token for backwards compatibility
193
198
  # AccessToken returns all data in AddressConsentToken plus new data
194
- 'AccessToken' => access_token || address_consent_token,
199
+ # You cannot pass both address_consent_token and access_token in
200
+ # the same call or you will encounter a 400/"AmbiguousToken" error
201
+ 'AccessToken' => access_token,
202
+ 'AddressConsentToken' => address_consent_token,
195
203
  'MWSAuthToken' => mws_auth_token
196
204
  }
197
205
 
@@ -209,6 +217,10 @@ module AmazonPay
209
217
  # @optional store_name [String]
210
218
  # @optional merchant_id [String]
211
219
  # @optional mws_auth_token [String]
220
+ # @optional billing_agreement_type [String] - one of CustomerInitiatedTransaction or MerchantInitiatedTransaction
221
+ # @optional subscription_amount [String]
222
+ # @optional subscription_currency_code [String]
223
+
212
224
  def set_billing_agreement_details(
213
225
  amazon_billing_agreement_id,
214
226
  platform_id: nil,
@@ -217,6 +229,9 @@ module AmazonPay
217
229
  custom_information: nil,
218
230
  store_name: nil,
219
231
  merchant_id: @merchant_id,
232
+ billing_agreement_type: nil,
233
+ subscription_amount: nil,
234
+ subscription_currency_code: @currency_code,
220
235
  mws_auth_token: nil
221
236
  )
222
237
 
@@ -232,9 +247,14 @@ module AmazonPay
232
247
  'BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId' => seller_billing_agreement_id,
233
248
  'BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation' => custom_information,
234
249
  'BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName' => store_name,
250
+ 'BillingAgreementAttributes.BillingAgreementType' => billing_agreement_type,
251
+ 'BillingAgreementAttributes.SubscriptionAmount.Amount' => subscription_amount,
252
+ 'BillingAgreementAttributes.SubscriptionAmount.CurrencyCode' => subscription_currency_code,
235
253
  'MWSAuthToken' => mws_auth_token
236
254
  }
237
255
 
256
+ optional['BillingAgreementAttributes.SubscriptionAmount.CurrencyCode'] = nil if subscription_amount.nil?
257
+
238
258
  operation(parameters, optional)
239
259
  end
240
260
 
@@ -244,9 +264,13 @@ module AmazonPay
244
264
  # @param amazon_billing_agreement_id [String]
245
265
  # @optional merchant_id [String]
246
266
  # @optional mws_auth_token [String]
267
+ # @optional success_url [String]
268
+ # @optional failure_url [String]
247
269
  def confirm_billing_agreement(
248
270
  amazon_billing_agreement_id,
249
271
  merchant_id: @merchant_id,
272
+ success_url: nil,
273
+ failure_url: nil,
250
274
  mws_auth_token: nil
251
275
  )
252
276
 
@@ -257,6 +281,8 @@ module AmazonPay
257
281
  }
258
282
 
259
283
  optional = {
284
+ 'SuccessUrl' => success_url,
285
+ 'FailureUrl' => failure_url,
260
286
  'MWSAuthToken' => mws_auth_token
261
287
  }
262
288
 
@@ -305,6 +331,7 @@ module AmazonPay
305
331
  # @optional seller_order_id [String]
306
332
  # @optional store_name [String]
307
333
  # @optional inherit_shipping_address [Boolean]
334
+ # @optional supplementary_data [String]
308
335
  # @optional merchant_id [String]
309
336
  # @optional mws_auth_token [String]
310
337
  def authorize_on_billing_agreement(
@@ -322,6 +349,7 @@ module AmazonPay
322
349
  seller_order_id: nil,
323
350
  store_name: nil,
324
351
  inherit_shipping_address: nil,
352
+ supplementary_data: nil,
325
353
  merchant_id: @merchant_id,
326
354
  mws_auth_token: nil
327
355
  )
@@ -345,6 +373,7 @@ module AmazonPay
345
373
  'SellerOrderAttributes.CustomInformation' => custom_information,
346
374
  'SellerOrderAttributes.SellerOrderId' => seller_order_id,
347
375
  'SellerOrderAttributes.StoreName' => store_name,
376
+ 'SellerOrderAttributes.SupplementaryData' => supplementary_data,
348
377
  'InheritShippingAddress' => inherit_shipping_address,
349
378
  'MWSAuthToken' => mws_auth_token
350
379
  }
@@ -463,7 +492,7 @@ module AmazonPay
463
492
  optional = {
464
493
  'MWSAuthToken' => mws_auth_token
465
494
  }
466
-
495
+
467
496
  operation(parameters, optional)
468
497
  end
469
498
 
@@ -511,6 +540,7 @@ module AmazonPay
511
540
  # @optional store_name [String]
512
541
  # @optional order_item_categories Array[String]
513
542
  # @optional custom_information [String]
543
+ # @optional supplementary_data [String]
514
544
  # @optional merchant_id [String]
515
545
  # @optional mws_auth_token [String]
516
546
  def set_order_reference_details(
@@ -524,6 +554,7 @@ module AmazonPay
524
554
  store_name: nil,
525
555
  order_item_categories: nil,
526
556
  custom_information: nil,
557
+ supplementary_data: nil,
527
558
  merchant_id: @merchant_id,
528
559
  mws_auth_token: nil
529
560
  )
@@ -543,6 +574,7 @@ module AmazonPay
543
574
  'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId' => seller_order_id,
544
575
  'OrderReferenceAttributes.SellerOrderAttributes.StoreName' => store_name,
545
576
  'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
577
+ 'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
546
578
  'MWSAuthToken' => mws_auth_token
547
579
  }
548
580
 
@@ -571,12 +603,13 @@ module AmazonPay
571
603
  # @optional store_name [String]
572
604
  # @optional order_item_categories Array[String]
573
605
  # @optional custom_information [String]
606
+ # @optional supplementary_data [String]
574
607
  # @optional merchant_id [String]
575
608
  # @optional mws_auth_token [String]
576
609
  def set_order_attributes(
577
610
  amazon_order_reference_id,
578
611
  amount: nil,
579
- currency_code: nil,
612
+ currency_code: @currency_code,
580
613
  platform_id: nil,
581
614
  seller_note: nil,
582
615
  seller_order_id: nil,
@@ -586,6 +619,7 @@ module AmazonPay
586
619
  store_name: nil,
587
620
  order_item_categories: nil,
588
621
  custom_information: nil,
622
+ supplementary_data: nil,
589
623
  merchant_id: @merchant_id,
590
624
  mws_auth_token: nil
591
625
  )
@@ -607,9 +641,12 @@ module AmazonPay
607
641
  'OrderAttributes.RequestPaymentAuthorization' => request_payment_authorization,
608
642
  'OrderAttributes.SellerOrderAttributes.StoreName' => store_name,
609
643
  'OrderAttributes.SellerOrderAttributes.CustomInformation' => custom_information,
644
+ 'OrderAttributes.SellerOrderAttributes.SupplementaryData' => supplementary_data,
610
645
  'MWSAuthToken' => mws_auth_token
611
646
  }
612
647
 
648
+ optional['OrderAttributes.OrderTotal.CurrencyCode'] = nil if amount.nil?
649
+
613
650
  if order_item_categories
614
651
  optional.merge!(
615
652
  get_categories_list(
@@ -626,12 +663,22 @@ module AmazonPay
626
663
  # information has been set on the order reference
627
664
  # @see https://pay.amazon.com/documentation/apireference/201751630#201751980
628
665
  # @param amazon_order_reference_id [String]
666
+ # @optional success_url [String]
667
+ # @optional failure_url [String]
668
+ # @optional authorization_amount [String]
669
+ # @optional currency_code [String]
629
670
  # @optional merchant_id [String]
630
671
  # @optional mws_auth_token [String]
672
+ # @optional expect_immediate_authorization [Boolean]
631
673
  def confirm_order_reference(
632
674
  amazon_order_reference_id,
675
+ success_url: nil,
676
+ failure_url: nil,
677
+ authorization_amount: nil,
678
+ currency_code: @currency_code,
633
679
  merchant_id: @merchant_id,
634
- mws_auth_token: nil
680
+ mws_auth_token: nil,
681
+ expect_immediate_authorization: nil
635
682
  )
636
683
 
637
684
  parameters = {
@@ -641,9 +688,16 @@ module AmazonPay
641
688
  }
642
689
 
643
690
  optional = {
644
- 'MWSAuthToken' => mws_auth_token
691
+ 'SuccessUrl' => success_url,
692
+ 'FailureUrl' => failure_url,
693
+ 'AuthorizationAmount.Amount' => authorization_amount,
694
+ 'AuthorizationAmount.CurrencyCode' => currency_code,
695
+ 'MWSAuthToken' => mws_auth_token,
696
+ 'ExpectImmediateAuthorization' => expect_immediate_authorization
645
697
  }
646
698
 
699
+ optional['AuthorizationAmount.CurrencyCode'] = nil if authorization_amount.nil?
700
+
647
701
  operation(parameters, optional)
648
702
  end
649
703
 
@@ -1076,8 +1130,8 @@ module AmazonPay
1076
1130
  list = {}
1077
1131
 
1078
1132
  categories.each_with_index do |val, index|
1079
- list.merge!({"#{attribute_key}.SellerOrderAttributes.OrderItemCategories.OrderItemCategory.#{index + 1}" => val})
1080
- end
1133
+ list.merge!("#{attribute_key}.SellerOrderAttributes.OrderItemCategories.OrderItemCategory.#{index + 1}" => val)
1134
+ end
1081
1135
 
1082
1136
  list
1083
1137
  end
@@ -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 is_order_reference?(amazon_reference_id)
35
- response = call_order_reference_api(
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
- return response
50
- end
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(amazon_order_reference_id,
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
- return response
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
- return response
225
+ response
227
226
  end
228
227
 
229
- def is_order_reference?(amazon_reference_id)
228
+ def order_reference?(amazon_reference_id)
230
229
  amazon_reference_id.start_with?('S', 'P')
231
230
  end
232
231
 
233
- def is_billing_agreement?(amazon_reference_id)
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(get_certificate.subject)
85
- public_key = get_public_key_from(get_certificate)
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 get_certificate
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 get_public_key_from(certificate)
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
- uri.scheme == 'https' &&
183
- uri.host.match(/^sns\.[a-zA-Z0-9\-]{3,}\.amazonaws\.com(\.cn)?$/) &&
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
@@ -1,3 +1,5 @@
1
+ # rubocop:disable Metrics/MethodLength
2
+
1
3
  require 'logger'
2
4
  require 'stringio'
3
5
 
@@ -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 ? "api.sandbox" : "api"
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'] = "bearer " + decoded_access_token
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
- return decoded_login_profile
55
+ decoded_login_profile
58
56
  end
59
57
 
60
58
  private
61
59
 
62
60
  def region_hash
63
61
  {
64
- :jp => 'amazon.co.jp',
65
- :uk => 'amazon.co.uk',
66
- :de => 'amazon.de',
67
- :eu => 'amazon.co.uk',
68
- :us => 'amazon.com',
69
- :na => 'amazon.com'
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
@@ -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.has_key?('Timestamp')
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
- raise 'InternalServerError'
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
@@ -1,42 +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
- def initialize(response)
9
- @response = response
10
- end
11
-
12
- def body
13
- @response.body
14
- end
15
-
16
- def to_xml
17
- REXML::Document.new(body)
18
- end
19
-
20
- def get_element(xpath, xml_element)
21
- xml = self.to_xml
22
- xml.elements.each(xpath) do |element|
23
- @value = element.elements[xml_element].text
24
- end
25
- return @value
26
- end
27
-
28
- def code
29
- @response.code
30
- end
31
-
32
- def success
33
- if @response.code.eql? '200'
34
- return true
35
- else
36
- 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
37
23
  end
38
- end
24
+ value
25
+ end
39
26
 
40
- end
27
+ def code
28
+ @response.code
29
+ end
41
30
 
31
+ def success
32
+ @response.code.eql? '200'
33
+ end
34
+ end
42
35
  end
@@ -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(/(?<=<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)
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*')
@@ -1,5 +1,5 @@
1
1
  module AmazonPay
2
- VERSION = "2.3.2"
3
- SDK_NAME = "amazon-pay-sdk-ruby"
4
- API_VERSION = "2013-01-01"
2
+ VERSION = '2.6.0'.freeze
3
+ SDK_NAME = 'amazon-pay-sdk-ruby'.freeze
4
+ API_VERSION = '2013-01-01'.freeze
5
5
  end
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.3.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AmazonPay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: AmazonPay Ruby SDK
14
14
  email: amazon-pay-sdk@amazon.com
@@ -19,7 +19,6 @@ files:
19
19
  - LICENSE
20
20
  - NOTICE
21
21
  - README.md
22
- - lib/CHANGES.txt
23
22
  - lib/amazon_pay.rb
24
23
  - lib/amazon_pay/client.rb
25
24
  - lib/amazon_pay/client_helper.rb
@@ -37,7 +36,7 @@ metadata: {}
37
36
  post_install_message:
38
37
  rdoc_options: []
39
38
  require_paths:
40
- - - lib
39
+ - lib
41
40
  required_ruby_version: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ">="
@@ -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.2.5
52
+ rubygems_version: 2.7.6.2
54
53
  signing_key:
55
54
  specification_version: 4
56
55
  summary: AmazonPay Ruby SDK
data/lib/CHANGES.txt DELETED
@@ -1,35 +0,0 @@
1
- 2.3.2 May 2018
2
- - Modify get_order_reference_details and get_billing_agreement_details
3
- to take access_token parameter
4
-
5
- 2.3.1 May 2018
6
- - Modify ipn_handler to work with new Cert format
7
- - Add CHANGES file
8
-
9
- 2.3.0 April 2018
10
- - Add GetMerchantAccountStatus
11
-
12
- 2.2.1 March 2018
13
- - Create new Timestamp parameter on every request
14
-
15
- 2.2.0 Jan 2018
16
- - Add ListOrderReference
17
- - Add ListOrderReferenceByNextToken
18
-
19
- 2.1.0 Jan 2018
20
- - Add Logging
21
- - Add SetOrderAttribute
22
-
23
- 2.0.0 Feb 2017
24
- - Pay with Amazon to Amazon Pay rebranding
25
-
26
- 1.x - 2015
27
- - Update README
28
- - Update documentation links
29
- - Change Login with Amazon API class and method name
30
- - Add one time transaction and subscriptions api flow
31
- - Add marketplace api support
32
- - Add client helper method
33
- - Add get user info api
34
- - Separate post request from client
35
- - Initial release