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/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/apple_pay.rb b/lib/spreedly/payment_methods/apple_pay.rb new file mode 100644 index 0000000..d80d5ac --- /dev/null +++ b/lib/spreedly/payment_methods/apple_pay.rb @@ -0,0 +1,7 @@ +module Spreedly + + class ApplePay < PaymentMethod + + end + +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/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 diff --git a/test/unit/find_payment_method_test.rb b/test/unit/find_payment_method_test.rb index c131cdc..874d17b 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 "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) + 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..943f5c3 --- /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\":\"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 a8e32a7..f8aad95 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?(apple_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..f429156 100644 --- a/test/unit/response_stubs/find_payment_method_stubs.rb +++ b/test/unit/response_stubs/find_payment_method_stubs.rb @@ -181,4 +181,44 @@ def successful_get_google_pay_response XML end + def successful_get_apple_pay_response + StubResponse.succeeded <<-XML + + RgGkf6vbV2QOuibYDq5F2hBjQy8 + 2017-07-27T17:52:55Z + 2017-07-27T17:52:55Z + + + cached + true + 1111 + 411111 + visa + + + 3 + 2018 + + + + + + + + + + + + + + + + + apple_pay + + + + XML + end + end