From 7dd6b5e3fa7f3cb382f8f3b50bcd8e50c8948dc1 Mon Sep 17 00:00:00 2001 From: Guille Carlos Date: Mon, 15 May 2023 13:57:06 -0400 Subject: [PATCH 1/4] Add logic for ApplePay This commit is not complete but it follows the same path as Google Pay. We need to see what token Apple returns in order to fill up the stub object we created for specs. --- lib/spreedly.rb | 1 + lib/spreedly/apple_pay.rb | 7 ++++++ lib/spreedly/environment.rb | 7 ++++++ .../payment_methods/payment_method.rb | 2 ++ test/unit/find_payment_method_test.rb | 12 ++++++++++ .../apple_payment_token_stubs.rb | 7 ++++++ test/unit/purchase_test.rb | 23 +++++++++++++++++++ .../find_payment_method_stubs.rb | 6 +++++ 8 files changed, 65 insertions(+) create mode 100644 lib/spreedly/apple_pay.rb create mode 100644 test/unit/payment_token_stubs/apple_payment_token_stubs.rb diff --git a/lib/spreedly.rb b/lib/spreedly.rb index ee8806c..6966c7f 100644 --- a/lib/spreedly.rb +++ b/lib/spreedly.rb @@ -10,6 +10,7 @@ require 'spreedly/payment_methods/payment_method' require 'spreedly/payment_methods/credit_card' require 'spreedly/payment_methods/google_pay' +require 'spreedly/payment_methods/apple_pay' require 'spreedly/payment_methods/paypal' require 'spreedly/payment_methods/sprel' require 'spreedly/payment_methods/bank_account' diff --git a/lib/spreedly/apple_pay.rb b/lib/spreedly/apple_pay.rb new file mode 100644 index 0000000..d80d5ac --- /dev/null +++ b/lib/spreedly/apple_pay.rb @@ -0,0 +1,7 @@ +module Spreedly + + class ApplePay < PaymentMethod + + end + +end diff --git a/lib/spreedly/environment.rb b/lib/spreedly/environment.rb index 06d4a8a..61c5ad1 100644 --- a/lib/spreedly/environment.rb +++ b/lib/spreedly/environment.rb @@ -191,6 +191,13 @@ def add_payment_token(doc, payment_method_token, options = {}) #{'4111111111111111' if options[:test_mode]} XML + elsif options[:payment_method] == :apple_pay + doc << <<~XML + + + #{'4111111111111111' if options[:test_mode]} + + XML else # if credit card doc.payment_method_token(payment_method_token) end diff --git a/lib/spreedly/payment_methods/payment_method.rb b/lib/spreedly/payment_methods/payment_method.rb index 95f150f..600d583 100644 --- a/lib/spreedly/payment_methods/payment_method.rb +++ b/lib/spreedly/payment_methods/payment_method.rb @@ -28,6 +28,8 @@ def self.new_from(xml_doc) return ThirdPartyToken.new(xml_doc) when 'google_pay' return GooglePay.new(xml_doc) + when 'apple_pay' + return ApplePay.new(xml_doc) end end diff --git a/test/unit/find_payment_method_test.rb b/test/unit/find_payment_method_test.rb index c131cdc..af93300 100644 --- a/test/unit/find_payment_method_test.rb +++ b/test/unit/find_payment_method_test.rb @@ -117,6 +117,18 @@ def test_successfully_find_google_pay assert_equal("cached", google_pay.storage_state) end + def test_successfully_find_apple_pay + apple_pay = find_using(successful_get_apple_pay_response) + + assert_kind_of(Spreedly::ApplePay, apple_pay) + assert_equal "5OHW2sAiQQMTNB06A3sOZ8UVduo", apple_pay.token + assert_equal(1682445021, apple_pay.created_at.to_i) + assert_equal(1682445021, apple_pay.updated_at.to_i) + assert_equal("", apple_pay.data) + assert_equal("apple_pay", apple_pay.payment_method_type) + assert_equal("cached", apple_pay.storage_state) + end + private def find_using(response) @environment.stubs(:raw_ssl_request).returns(response) diff --git a/test/unit/payment_token_stubs/apple_payment_token_stubs.rb b/test/unit/payment_token_stubs/apple_payment_token_stubs.rb new file mode 100644 index 0000000..2f11688 --- /dev/null +++ b/test/unit/payment_token_stubs/apple_payment_token_stubs.rb @@ -0,0 +1,7 @@ +module ApplePaymentTokenStubs + def apple_pay_token + token = <<~TEXT + {"signature":"MEUCIA6SGVRwhOyeYRkeDUUNwB/kGtyfQAlOsg7NZydT17u/AiEA48BhWGQEF1EbEU0J+m8eSK3rTfhok9QqpiFVbME+Ky0\u003d","protocolVersion":"ECv1","signedMessage":"{\"encryptedMessage\":\"3v4IcT/eovIDP2WF8iRUy4qWQnE9Cx0vQxIZ5f9i3Emv3Tzs1AzvB7cxXhxrjp9FVIzdOwsZAPAsm03gvoYq8Xdr70XvrVRd2MFwQhMC7IV/uEsthw4JsR8oCkbI5v/zqhu2B+JodFgavNliHcpKBgijy2D6bpx7jXEkM39M/L4oBObFxFrhVSLA1GjOV6A5gLAXNXt0ffkCYekihqAyJrWlk3sCBDCF5SUiAKEIOIZtzZLgusxjVp6ufZHOHm/53uhAi6JWSJ1E6G5aaYGtULYdwgURHtxN5OIzQPYlEGctaQd5tgfCsBFfGkYyN1GRNgclbaLzAfk/Jn7/6IVKuV0ol3xubTcnjGTZXwtTjiEyYDoz1yVqB9ViMmJa55L6nBtbbAkcNEgAi7dPnrbvBGEP7QWsNT9D71g8SWrlRTCYUAOyuamaQhofG4ul1IVjmltdAy2BHBWpqgJnR9kczydQyE7uDiqhSC1/0eG8GCGIqoi8XfOioGXfMyLZ1p2ZcNK9ECjzUrH/edrwgtShxgWuWMwQTM4DQlVTAA/R4DVs192YWZcc7jm5wLqZ0+XEaPuighJM1Ps1Egeccg\\u003d\\u003d\",\"ephemeralPublicKey\":\"BA2SvF9BdCX7Tl1wwRkyLzTfqhctobhZgSugC9Cz77XNUCBOBMfFyJQt506PUs89D6IJZZfOkZopy0shRF9Uph4\\u003d\",\"tag\":\"Uhin1BE7KAuuiam7eEQFimRUDd9Xn6tZc2fClTpfrXQ\\u003d\"}"} + TEXT + end +end diff --git a/test/unit/purchase_test.rb b/test/unit/purchase_test.rb index a8e32a7..33c0ec2 100644 --- a/test/unit/purchase_test.rb +++ b/test/unit/purchase_test.rb @@ -1,11 +1,13 @@ require 'test_helper' require 'unit/response_stubs/purchase_stubs' require 'unit/payment_token_stubs/google_payment_token_stubs' +require 'unit/payment_token_stubs/apple_payment_token_stubs' class PurchaseTest < Test::Unit::TestCase include PurchaseStubs include GooglePaymentTokenStubs + include ApplePaymentTokenStubs def setup @environment = Spreedly::Environment.new("key", "secret") @@ -176,6 +178,27 @@ def test_request_body_params_for_google_pay assert body.to_s.include?(google_pay_token) end + def test_request_body_params_for_apple_pay + body = get_request_body(successful_purchase_response) do + @environment.purchase_on_gateway("TheGatewayToken", apple_pay_token, 2001, all_possible_options.merge(payment_method: :apple_pay)) + end + + transaction = body.xpath('./transaction') + assert_xpaths_in transaction, + [ './amount', '2001' ], + [ './currency_code', 'EUR' ], + [ './payment_method_token', '' ], + [ './order_id', '8675' ], + [ './description', 'SuperDuper' ], + [ './ip', '183.128.100.103' ], + [ './merchant_name_descriptor', 'Real Stuff' ], + [ './merchant_location_descriptor', 'Raleigh' ], + [ './retain_on_success', 'true' ], + [ './continue_caching', 'true'] + + assert body.to_s.include?(google_pay_token) + end + private def purchase_using(response) @environment.stubs(:raw_ssl_request).returns(response) diff --git a/test/unit/response_stubs/find_payment_method_stubs.rb b/test/unit/response_stubs/find_payment_method_stubs.rb index 0df730b..5ff8c34 100644 --- a/test/unit/response_stubs/find_payment_method_stubs.rb +++ b/test/unit/response_stubs/find_payment_method_stubs.rb @@ -181,4 +181,10 @@ def successful_get_google_pay_response XML end + def successful_get_apple_pay_response + StubResponse.succeeded <<-XML + # TODO ADD APPLE RESPONSE + XML + end + end From b20642825f660ecaa394a5844615c777c2c0a64d Mon Sep 17 00:00:00 2001 From: Guille Carlos Date: Wed, 7 Jun 2023 10:04:12 -0400 Subject: [PATCH 2/4] Added apple pay token and moved file around I had placed the apple_pay payment_method file in the incorrect location. And I was missing a apple pay token sample. This commit fixes both issues. --- lib/spreedly/{ => payment_methods}/apple_pay.rb | 0 test/unit/payment_token_stubs/apple_payment_token_stubs.rb | 2 +- test/unit/purchase_test.rb | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/spreedly/{ => payment_methods}/apple_pay.rb (100%) diff --git a/lib/spreedly/apple_pay.rb b/lib/spreedly/payment_methods/apple_pay.rb similarity index 100% rename from lib/spreedly/apple_pay.rb rename to lib/spreedly/payment_methods/apple_pay.rb diff --git a/test/unit/payment_token_stubs/apple_payment_token_stubs.rb b/test/unit/payment_token_stubs/apple_payment_token_stubs.rb index 2f11688..943f5c3 100644 --- a/test/unit/payment_token_stubs/apple_payment_token_stubs.rb +++ b/test/unit/payment_token_stubs/apple_payment_token_stubs.rb @@ -1,7 +1,7 @@ module ApplePaymentTokenStubs def apple_pay_token token = <<~TEXT - {"signature":"MEUCIA6SGVRwhOyeYRkeDUUNwB/kGtyfQAlOsg7NZydT17u/AiEA48BhWGQEF1EbEU0J+m8eSK3rTfhok9QqpiFVbME+Ky0\u003d","protocolVersion":"ECv1","signedMessage":"{\"encryptedMessage\":\"3v4IcT/eovIDP2WF8iRUy4qWQnE9Cx0vQxIZ5f9i3Emv3Tzs1AzvB7cxXhxrjp9FVIzdOwsZAPAsm03gvoYq8Xdr70XvrVRd2MFwQhMC7IV/uEsthw4JsR8oCkbI5v/zqhu2B+JodFgavNliHcpKBgijy2D6bpx7jXEkM39M/L4oBObFxFrhVSLA1GjOV6A5gLAXNXt0ffkCYekihqAyJrWlk3sCBDCF5SUiAKEIOIZtzZLgusxjVp6ufZHOHm/53uhAi6JWSJ1E6G5aaYGtULYdwgURHtxN5OIzQPYlEGctaQd5tgfCsBFfGkYyN1GRNgclbaLzAfk/Jn7/6IVKuV0ol3xubTcnjGTZXwtTjiEyYDoz1yVqB9ViMmJa55L6nBtbbAkcNEgAi7dPnrbvBGEP7QWsNT9D71g8SWrlRTCYUAOyuamaQhofG4ul1IVjmltdAy2BHBWpqgJnR9kczydQyE7uDiqhSC1/0eG8GCGIqoi8XfOioGXfMyLZ1p2ZcNK9ECjzUrH/edrwgtShxgWuWMwQTM4DQlVTAA/R4DVs192YWZcc7jm5wLqZ0+XEaPuighJM1Ps1Egeccg\\u003d\\u003d\",\"ephemeralPublicKey\":\"BA2SvF9BdCX7Tl1wwRkyLzTfqhctobhZgSugC9Cz77XNUCBOBMfFyJQt506PUs89D6IJZZfOkZopy0shRF9Uph4\\u003d\",\"tag\":\"Uhin1BE7KAuuiam7eEQFimRUDd9Xn6tZc2fClTpfrXQ\\u003d\"}"} + {\"signature\":\"MEYCIQD/JoCQ2AMHS0o1bXH4BhfosEsndtXU0jBhXrlFRXqHVgIhAMbYV8JOR1ysS6rrV4vwF+S8/I0bBDytRMEdItlHkXEQ\",\"protocolVersion\":\"ECv1\",\"signedMessage\":\"{\\\"encryptedMessage\\\":\\\"tJUnNLW8HBaDS3w6Q959I0WdTbo3IE9P1TMAFb/OhAQoRhV+qaiwQ0GTOMI7Dmzl1bfaMnYBFh8yAbCw6RMnzK71AZLwwXkDknUpxwtU1QJds2k2SINjiuBrQyt4VpgBFjVAzV9SWlCW+Mm9qfqAzN4N4mFgsvNw0GDlbzgHpjHyjKev/HAH4Gk98bLjXh+cmG9pL9hk1NIooLZPJ4I5q34Ri1dChKIXoQRScBYYFXzt3tk4u8ykiqCqPydjAls3vujNceKKj0SIRaixlpJ+jRJgK04XL3OOe4EzHd476ElKSwVfg96t5Y/ScJ1lPav2FNiCIekHevyhyIIiN9Vun3OsZ6wSRkSWaIkeflsK2potCpb2MzAdAgc1qQIdqBc3x9x1aLS/jEKgPY/gA1gnAyrbb8Ol/RF8W0FCaCE/A/DqPY+YdH92sUHBuOgmarPPU4KhZkshF09cD6hFMKMZBezYgFikXQ\\\\u003d\\\\u003d\\\",\\\"ephemeralPublicKey\\\":\\\"BKX7sb9PXjbdL8GsfEzcAiVYkM+QBJXt/L2yGXHjyJM7+NO7SlyPyXe3wK6+ky16ujphhwRy10c73LPANrwPTXY\\\\u003d\\\",\\\"tag\\\":\\\"e7DeYqVtIKIEZWmXAvA5OTZ2HwPSxyfCyrAAn7XEbm4\\\\u003d\\\"}\"} TEXT end end diff --git a/test/unit/purchase_test.rb b/test/unit/purchase_test.rb index 33c0ec2..f8aad95 100644 --- a/test/unit/purchase_test.rb +++ b/test/unit/purchase_test.rb @@ -196,7 +196,7 @@ def test_request_body_params_for_apple_pay [ './retain_on_success', 'true' ], [ './continue_caching', 'true'] - assert body.to_s.include?(google_pay_token) + assert body.to_s.include?(apple_pay_token) end private From f3df09d3e174f00994067bc1b54d127bca231b1c Mon Sep 17 00:00:00 2001 From: Guille Carlos Date: Wed, 7 Jun 2023 10:38:45 -0400 Subject: [PATCH 3/4] Added apple pay stub response --- test/unit/find_payment_method_test.rb | 6 ++-- .../find_payment_method_stubs.rb | 36 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/test/unit/find_payment_method_test.rb b/test/unit/find_payment_method_test.rb index af93300..874d17b 100644 --- a/test/unit/find_payment_method_test.rb +++ b/test/unit/find_payment_method_test.rb @@ -121,9 +121,9 @@ def test_successfully_find_apple_pay apple_pay = find_using(successful_get_apple_pay_response) assert_kind_of(Spreedly::ApplePay, apple_pay) - assert_equal "5OHW2sAiQQMTNB06A3sOZ8UVduo", apple_pay.token - assert_equal(1682445021, apple_pay.created_at.to_i) - assert_equal(1682445021, apple_pay.updated_at.to_i) + assert_equal "RgGkf6vbV2QOuibYDq5F2hBjQy8", apple_pay.token + assert_equal(1501177975, apple_pay.created_at.to_i) + assert_equal(1501177975, apple_pay.updated_at.to_i) assert_equal("", apple_pay.data) assert_equal("apple_pay", apple_pay.payment_method_type) assert_equal("cached", apple_pay.storage_state) diff --git a/test/unit/response_stubs/find_payment_method_stubs.rb b/test/unit/response_stubs/find_payment_method_stubs.rb index 5ff8c34..f429156 100644 --- a/test/unit/response_stubs/find_payment_method_stubs.rb +++ b/test/unit/response_stubs/find_payment_method_stubs.rb @@ -183,7 +183,41 @@ def successful_get_google_pay_response def successful_get_apple_pay_response StubResponse.succeeded <<-XML - # TODO ADD APPLE RESPONSE + + RgGkf6vbV2QOuibYDq5F2hBjQy8 + 2017-07-27T17:52:55Z + 2017-07-27T17:52:55Z + + + cached + true + 1111 + 411111 + visa + + + 3 + 2018 + + + + + + + + + + + + + + + + + apple_pay + + + XML end From 0a56891dd08b18ac18435b84a9bf366a02c618d4 Mon Sep 17 00:00:00 2001 From: Guille Carlos Date: Wed, 7 Jun 2023 14:08:45 -0400 Subject: [PATCH 4/4] Updated the version number --- lib/spreedly/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spreedly/version.rb b/lib/spreedly/version.rb index 307a7d3..533c8da 100644 --- a/lib/spreedly/version.rb +++ b/lib/spreedly/version.rb @@ -1,3 +1,3 @@ module Spreedly - VERSION = "2.0.28" + VERSION = "2.0.29" end