Skip to content

Commit 20a6689

Browse files
committed
Amazon Pay Ruby SDK 2.5.0
1 parent 6321994 commit 20a6689

4 files changed

Lines changed: 172 additions & 6 deletions

File tree

CHANGES.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
Version 2.5.0 - August 2019
2+
- (EU/UK) confirm_billing_agreement API has two new optional request parameters:
3+
success_url, failure_url
4+
- (EU/UK) set_billing_agreement_details API has three new optional request parameter:
5+
billing_agreement_type, subscription_amount, subscription_currency_code
6+
- (EU/UK)For usage instructions, please consult the automatic payments
7+
Amazon Pay Strong Customer Authentication (SCA) Upgrade Integration Guide
8+
https://developer.amazon.com/docs/eu/amazon-pay-automatic/sca-upgrade.html
9+
110
Version 2.4.0 - February 2019
2-
- confirm_order_reference API has four new request parameters:
11+
- (EU/UK) confirm_order_reference API has four new request parameters:
312
success_url, failure_url, authorization_amount, and authorization_currency_code
413
For usage instructions, please consult the
514
Amazon Pay Strong Customer Authentication (SCA) Upgrade Integration Guide
15+
https://developer.amazon.com/docs/eu/amazon-pay-onetime/sca-upgrade.html
616
- Support for supplementary_data attribute added to
717
authorize_on_billing_agreement and create_order_reference_for_id
818

lib/amazon_pay/client.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def get_billing_agreement_details(
217217
# @optional store_name [String]
218218
# @optional merchant_id [String]
219219
# @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+
220224
def set_billing_agreement_details(
221225
amazon_billing_agreement_id,
222226
platform_id: nil,
@@ -225,6 +229,9 @@ def set_billing_agreement_details(
225229
custom_information: nil,
226230
store_name: nil,
227231
merchant_id: @merchant_id,
232+
billing_agreement_type: nil,
233+
subscription_amount: nil,
234+
subscription_currency_code: @currency_code,
228235
mws_auth_token: nil
229236
)
230237

@@ -240,9 +247,14 @@ def set_billing_agreement_details(
240247
'BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId' => seller_billing_agreement_id,
241248
'BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation' => custom_information,
242249
'BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName' => store_name,
250+
'BillingAgreementAttributes.BillingAgreementType' => billing_agreement_type,
251+
'BillingAgreementAttributes.SubscriptionAmount.Amount' => subscription_amount,
252+
'BillingAgreementAttributes.SubscriptionAmount.CurrencyCode' => subscription_currency_code,
243253
'MWSAuthToken' => mws_auth_token
244254
}
245255

256+
optional['BillingAgreementAttributes.SubscriptionAmount.CurrencyCode'] = nil if subscription_amount.nil?
257+
246258
operation(parameters, optional)
247259
end
248260

@@ -252,9 +264,13 @@ def set_billing_agreement_details(
252264
# @param amazon_billing_agreement_id [String]
253265
# @optional merchant_id [String]
254266
# @optional mws_auth_token [String]
267+
# @optional success_url [String]
268+
# @optional failure_url [String]
255269
def confirm_billing_agreement(
256270
amazon_billing_agreement_id,
257271
merchant_id: @merchant_id,
272+
success_url: nil,
273+
failure_url: nil,
258274
mws_auth_token: nil
259275
)
260276

@@ -265,6 +281,8 @@ def confirm_billing_agreement(
265281
}
266282

267283
optional = {
284+
'SuccessUrl' => success_url,
285+
'FailureUrl' => failure_url,
268286
'MWSAuthToken' => mws_auth_token
269287
}
270288

lib/amazon_pay/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module AmazonPay
2-
VERSION = '2.4.0'.freeze
2+
VERSION = '2.5.0'.freeze
33
SDK_NAME = 'amazon-pay-sdk-ruby'.freeze
44
API_VERSION = '2013-01-01'.freeze
55
end

test/amazon_pay_unit_test.rb

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,121 @@ def test_set_billing_agreement_details
842842
assert_equal(true, res.success)
843843
end
844844

845+
def test_set_billing_agreement_details_sca_with_amount_overriden_currency
846+
seller_note = 'seller_note'
847+
store_name = 'store_name'
848+
custom_information = 'custom_information'
849+
seller_billing_agreement_id = 'seller_billing_agreement_id'
850+
billing_agreement_type = 'MerchantInitiatedTransaction'
851+
subscription_amount = '1.23'
852+
subscription_currency_code = 'GBP'
853+
854+
post_url = "AWSAccessKeyId=#{ACCESS_KEY}"\
855+
"&Action=SetBillingAgreementDetails&AmazonBillingAgreementId=#{AMAZON_BILLING_AGREEMENT_ID}"\
856+
"&BillingAgreementAttributes.BillingAgreementType=#{billing_agreement_type}"\
857+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation=#{custom_information}"\
858+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId=#{seller_billing_agreement_id}"\
859+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName=#{store_name}"\
860+
"&BillingAgreementAttributes.SellerNote=seller_note"\
861+
"&BillingAgreementAttributes.SubscriptionAmount.Amount=#{subscription_amount}"\
862+
"&BillingAgreementAttributes.SubscriptionAmount.CurrencyCode=#{subscription_currency_code}"\
863+
"&SellerId=#{MERCHANT_ID}"\
864+
"&SignatureMethod=HmacSHA256"\
865+
"&SignatureVersion=2"\
866+
"&Timestamp=#{@operation.send :custom_escape, Time.now.utc.iso8601}&Version=2013-01-01"
867+
post_body = ["POST", "mws.amazonservices.com", "/OffAmazonPayments_Sandbox/2013-01-01", post_url].join("\n")
868+
869+
stub_request(:post, "https://mws.amazonservices.com/OffAmazonPayments_Sandbox/2013-01-01").with(:body => "#{post_url}"\
870+
"&Signature=#{@operation.send :sign, post_body}",
871+
:headers => HEADERS).to_return(:status => 200)
872+
873+
res = @client.set_billing_agreement_details(
874+
AMAZON_BILLING_AGREEMENT_ID,
875+
store_name: store_name,
876+
seller_billing_agreement_id: seller_billing_agreement_id,
877+
custom_information: custom_information,
878+
seller_note: seller_note,
879+
billing_agreement_type: billing_agreement_type,
880+
subscription_amount: subscription_amount,
881+
subscription_currency_code: subscription_currency_code
882+
)
883+
assert_equal(true, res.success)
884+
end
885+
886+
def test_set_billing_agreement_details_sca_with_amount_default_currency
887+
seller_note = 'seller_note'
888+
store_name = 'store_name'
889+
custom_information = 'custom_information'
890+
seller_billing_agreement_id = 'seller_billing_agreement_id'
891+
billing_agreement_type = 'MerchantInitiatedTransaction'
892+
subscription_amount = '1.23'
893+
894+
post_url = "AWSAccessKeyId=#{ACCESS_KEY}"\
895+
"&Action=SetBillingAgreementDetails&AmazonBillingAgreementId=#{AMAZON_BILLING_AGREEMENT_ID}"\
896+
"&BillingAgreementAttributes.BillingAgreementType=#{billing_agreement_type}"\
897+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation=#{custom_information}"\
898+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId=#{seller_billing_agreement_id}"\
899+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName=#{store_name}"\
900+
"&BillingAgreementAttributes.SellerNote=seller_note"\
901+
"&BillingAgreementAttributes.SubscriptionAmount.Amount=#{subscription_amount}"\
902+
"&BillingAgreementAttributes.SubscriptionAmount.CurrencyCode=USD"\
903+
"&SellerId=#{MERCHANT_ID}"\
904+
"&SignatureMethod=HmacSHA256"\
905+
"&SignatureVersion=2"\
906+
"&Timestamp=#{@operation.send :custom_escape, Time.now.utc.iso8601}&Version=2013-01-01"
907+
post_body = ["POST", "mws.amazonservices.com", "/OffAmazonPayments_Sandbox/2013-01-01", post_url].join("\n")
908+
909+
stub_request(:post, "https://mws.amazonservices.com/OffAmazonPayments_Sandbox/2013-01-01").with(:body => "#{post_url}"\
910+
"&Signature=#{@operation.send :sign, post_body}",
911+
:headers => HEADERS).to_return(:status => 200)
912+
913+
res = @client.set_billing_agreement_details(
914+
AMAZON_BILLING_AGREEMENT_ID,
915+
store_name: store_name,
916+
seller_billing_agreement_id: seller_billing_agreement_id,
917+
custom_information: custom_information,
918+
seller_note: seller_note,
919+
billing_agreement_type: billing_agreement_type,
920+
subscription_amount: subscription_amount
921+
)
922+
assert_equal(true, res.success)
923+
end
924+
925+
def test_set_billing_agreement_details_sca_without_amount
926+
seller_note = 'seller_note'
927+
store_name = 'store_name'
928+
custom_information = 'custom_information'
929+
seller_billing_agreement_id = 'seller_billing_agreement_id'
930+
billing_agreement_type = 'CustomerInitiatedTransaction'
931+
932+
post_url = "AWSAccessKeyId=#{ACCESS_KEY}"\
933+
"&Action=SetBillingAgreementDetails&AmazonBillingAgreementId=#{AMAZON_BILLING_AGREEMENT_ID}"\
934+
"&BillingAgreementAttributes.BillingAgreementType=#{billing_agreement_type}"\
935+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation=#{custom_information}"\
936+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId=#{seller_billing_agreement_id}"\
937+
"&BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName=#{store_name}"\
938+
"&BillingAgreementAttributes.SellerNote=seller_note"\
939+
"&SellerId=#{MERCHANT_ID}"\
940+
"&SignatureMethod=HmacSHA256"\
941+
"&SignatureVersion=2"\
942+
"&Timestamp=#{@operation.send :custom_escape, Time.now.utc.iso8601}&Version=2013-01-01"
943+
post_body = ["POST", "mws.amazonservices.com", "/OffAmazonPayments_Sandbox/2013-01-01", post_url].join("\n")
944+
945+
stub_request(:post, "https://mws.amazonservices.com/OffAmazonPayments_Sandbox/2013-01-01").with(:body => "#{post_url}"\
946+
"&Signature=#{@operation.send :sign, post_body}",
947+
:headers => HEADERS).to_return(:status => 200)
948+
949+
res = @client.set_billing_agreement_details(
950+
AMAZON_BILLING_AGREEMENT_ID,
951+
store_name: store_name,
952+
seller_billing_agreement_id: seller_billing_agreement_id,
953+
custom_information: custom_information,
954+
seller_note: seller_note,
955+
billing_agreement_type: billing_agreement_type
956+
)
957+
assert_equal(true, res.success)
958+
end
959+
845960
def test_confirm_billing_agreement
846961
post_url = "AWSAccessKeyId=#{ACCESS_KEY}"\
847962
"&Action=ConfirmBillingAgreement&AmazonBillingAgreementId=#{AMAZON_BILLING_AGREEMENT_ID}"\
@@ -859,6 +974,29 @@ def test_confirm_billing_agreement
859974
assert_equal(true, res.success)
860975
end
861976

977+
def test_confirm_billing_agreement_sca
978+
post_url = "AWSAccessKeyId=#{ACCESS_KEY}"\
979+
"&Action=ConfirmBillingAgreement&AmazonBillingAgreementId=#{AMAZON_BILLING_AGREEMENT_ID}"\
980+
"&FailureUrl=#{FAILURE_URL_ENCODED}"\
981+
"&SellerId=#{MERCHANT_ID}"\
982+
"&SignatureMethod=HmacSHA256"\
983+
"&SignatureVersion=2"\
984+
"&SuccessUrl=#{SUCCESS_URL_ENCODED}"\
985+
"&Timestamp=#{@operation.send :custom_escape, Time.now.utc.iso8601}&Version=2013-01-01"
986+
post_body = ["POST", "mws.amazonservices.com", "/OffAmazonPayments_Sandbox/2013-01-01", post_url].join("\n")
987+
988+
stub_request(:post, "https://mws.amazonservices.com/OffAmazonPayments_Sandbox/2013-01-01").with(:body => "#{post_url}"\
989+
"&Signature=#{@operation.send :sign, post_body}",
990+
:headers => HEADERS).to_return(:status => 200)
991+
992+
res = @client.confirm_billing_agreement(
993+
AMAZON_BILLING_AGREEMENT_ID,
994+
success_url: SUCCESS_URL,
995+
failure_url: FAILURE_URL
996+
)
997+
assert_equal(true, res.success)
998+
end
999+
8621000
def test_validate_billing_agreement
8631001
post_url = "AWSAccessKeyId=#{ACCESS_KEY}"\
8641002
"&Action=ValidateBillingAgreement&AmazonBillingAgreementId=#{AMAZON_BILLING_AGREEMENT_ID}"\
@@ -897,10 +1035,10 @@ def test_authorize_on_billing_agreement
8971035
:headers => HEADERS).to_return(:status => 200)
8981036

8991037
res = @client.authorize_on_billing_agreement(
900-
AMAZON_BILLING_AGREEMENT_ID,
901-
AUTHORIZATION_REFERENCE_ID,
902-
AMOUNT,
903-
capture_now: "capture_now",
1038+
AMAZON_BILLING_AGREEMENT_ID,
1039+
AUTHORIZATION_REFERENCE_ID,
1040+
AMOUNT,
1041+
capture_now: "capture_now",
9041042
transaction_timeout: "transaction_timeout",
9051043
supplementary_data: '{"AirlineMetaData" : {"version": 1.0}}'
9061044
)

0 commit comments

Comments
 (0)