From 7d653f4eadfd6682eb5bbf3f315f8147fe710e69 Mon Sep 17 00:00:00 2001 From: Huda Date: Wed, 8 Mar 2023 09:42:27 +1030 Subject: [PATCH] Pin: Add new 3DS params mentioned in Pin Payments docs --- CHANGELOG | 1 + lib/active_merchant/billing/gateways/pin.rb | 21 +++++++++++++++++---- test/remote/gateways/remote_pin_test.rb | 20 +++++++++++++++++++- test/unit/gateways/pin_test.rb | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 27f7b4205e4..1ede1679da4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -69,6 +69,7 @@ * WorldPay: Accept GooglePay pan only [almalee24] #4943 * Braintree: Correct issue in v2 stored credentials [aenand] #4967 * Stripe Payment Intents: Add the card brand field [yunnydang] #4964 +* Pin Payments: Add new 3DS params mentioned in Pin Payments docs [hudakh] #4720 == Version 1.135.0 (August 24, 2023) * PaymentExpress: Correct endpoints [steveh] #4827 diff --git a/lib/active_merchant/billing/gateways/pin.rb b/lib/active_merchant/billing/gateways/pin.rb index b054ed3b7a6..a9cc344753a 100644 --- a/lib/active_merchant/billing/gateways/pin.rb +++ b/lib/active_merchant/billing/gateways/pin.rb @@ -81,6 +81,11 @@ def void(token, options = {}) commit(:put, "charges/#{CGI.escape(token)}/void", {}, options) end + # Verify a previously authorized charge. + def verify_3ds(session_token, options = {}) + commit(:get, "/charges/verify?session_token=#{session_token}", nil, options) + end + # Updates the credit card for the customer. def update(token, creditcard, options = {}) post = {} @@ -178,10 +183,16 @@ def add_metadata(post, options) def add_3ds(post, options) if options[:three_d_secure] post[:three_d_secure] = {} - post[:three_d_secure][:version] = options[:three_d_secure][:version] if options[:three_d_secure][:version] - post[:three_d_secure][:eci] = options[:three_d_secure][:eci] if options[:three_d_secure][:eci] - post[:three_d_secure][:cavv] = options[:three_d_secure][:cavv] if options[:three_d_secure][:cavv] - post[:three_d_secure][:transaction_id] = options[:three_d_secure][:ds_transaction_id] || options[:three_d_secure][:xid] + if options[:three_d_secure][:enabled] + post[:three_d_secure][:enabled] = true + post[:three_d_secure][:fallback_ok] = options[:three_d_secure][:fallback_ok] unless options[:three_d_secure][:fallback_ok].nil? + post[:three_d_secure][:callback_url] = options[:three_d_secure][:callback_url] if options[:three_d_secure][:callback_url] + else + post[:three_d_secure][:version] = options[:three_d_secure][:version] if options[:three_d_secure][:version] + post[:three_d_secure][:eci] = options[:three_d_secure][:eci] if options[:three_d_secure][:eci] + post[:three_d_secure][:cavv] = options[:three_d_secure][:cavv] if options[:three_d_secure][:cavv] + post[:three_d_secure][:transaction_id] = options[:three_d_secure][:ds_transaction_id] || options[:three_d_secure][:xid] + end end end @@ -266,6 +277,8 @@ def parse(body) end def post_data(parameters = {}) + return nil unless parameters + parameters.to_json end end diff --git a/test/remote/gateways/remote_pin_test.rb b/test/remote/gateways/remote_pin_test.rb index 003b2729601..eb1b10bbad7 100644 --- a/test/remote/gateways/remote_pin_test.rb +++ b/test/remote/gateways/remote_pin_test.rb @@ -17,7 +17,7 @@ def setup description: "Store Purchase #{DateTime.now.to_i}" } - @additional_options_3ds = @options.merge( + @additional_options_3ds_passthrough = @options.merge( three_d_secure: { version: '1.0.2', eci: '06', @@ -25,6 +25,14 @@ def setup xid: 'MDAwMDAwMDAwMDAwMDAwMzIyNzY=' } ) + + @additional_options_3ds = @options.merge( + three_d_secure: { + enabled: true, + fallback_ok: true, + callback_url: 'https://yoursite.com/authentication_complete' + } + ) end def test_successful_purchase @@ -63,6 +71,16 @@ def test_successful_authorize_and_capture end def test_successful_authorize_and_capture_with_passthrough_3ds + authorization = @gateway.authorize(@amount, @credit_card, @additional_options_3ds_passthrough) + assert_success authorization + assert_equal false, authorization.params['response']['captured'] + + response = @gateway.capture(@amount, authorization.authorization, @options) + assert_success response + assert_equal true, response.params['response']['captured'] + end + + def test_successful_authorize_and_capture_with_3ds authorization = @gateway.authorize(@amount, @credit_card, @additional_options_3ds) assert_success authorization assert_equal false, authorization.params['response']['captured'] diff --git a/test/unit/gateways/pin_test.rb b/test/unit/gateways/pin_test.rb index bb3bb0b60c3..7889ac2b04d 100644 --- a/test/unit/gateways/pin_test.rb +++ b/test/unit/gateways/pin_test.rb @@ -14,6 +14,12 @@ def setup ip: '127.0.0.1' } + @three_d_secure = { + enabled: true, + fallback_ok: true, + callback_url: 'https://yoursite.com/authentication_complete' + } + @three_d_secure_v1 = { version: '1.0.2', eci: '05', @@ -353,6 +359,14 @@ def test_add_creditcard_with_customer_token assert_false post.has_key?(:card) end + def test_add_3ds + post = {} + @gateway.send(:add_3ds, post, @options.merge(three_d_secure: @three_d_secure)) + assert_equal true, post[:three_d_secure][:enabled] + assert_equal true, post[:three_d_secure][:fallback_ok] + assert_equal 'https://yoursite.com/authentication_complete', post[:three_d_secure][:callback_url] + end + def test_add_3ds_v1 post = {} @gateway.send(:add_3ds, post, @options.merge(three_d_secure: @three_d_secure_v1))