From 29e42a227c2d00e59c9aa73910a7a4332db5721e Mon Sep 17 00:00:00 2001 From: Johan Manuel herrera Date: Tue, 13 Jun 2023 08:58:35 -0500 Subject: [PATCH] Shift4: Enable general credit feature. (#4790) Summary:------------------------------ Enabling general credit feature Remote Test: ------------------------------ Finished in 171.436961 seconds. 28 tests, 63 assertions, 2 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 92.8571% passed failing test not related to PR changes Unit Tests: ------------------------------ 26 tests, 163 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed RuboCop: ------------------------------ 760 files inspected, no offenses detected Co-authored-by: Nick Ashton --- CHANGELOG | 1 + lib/active_merchant/billing/gateways/shift4.rb | 7 +++++-- test/remote/gateways/remote_shift4_test.rb | 12 ++++++++++++ test/unit/gateways/shift4_test.rb | 12 ++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c07c19b468a..0c7e5085f4b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,7 @@ * Add BIN for Maestro [jcreiff] #4799 * D_Local: Add save field on card object [yunnydang] #4805 * PayPal Express: Adds support for MsgSubID property on DoReferenceTransaction and DoExpressCheckoutPayment [wikiti] #4798 +* Shift4: Enable general credit feature [jherreraa] #4790 == Version 1.129.0 (May 3rd, 2023) * Adyen: Update selectedBrand mapping for Google Pay [jcreiff] #4763 diff --git a/lib/active_merchant/billing/gateways/shift4.rb b/lib/active_merchant/billing/gateways/shift4.rb index 6877f8e499a..ca6feaa5eaf 100644 --- a/lib/active_merchant/billing/gateways/shift4.rb +++ b/lib/active_merchant/billing/gateways/shift4.rb @@ -91,7 +91,7 @@ def capture(money, authorization, options = {}) commit(action, post, options) end - def refund(money, authorization, options = {}) + def refund(money, payment_method, options = {}) post = {} action = 'refund' @@ -99,12 +99,15 @@ def refund(money, authorization, options = {}) add_invoice(post, money, options) add_clerk(post, options) add_transaction(post, options) - add_card(action, post, get_card_token(authorization), options) + card_token = payment_method.is_a?(CreditCard) ? get_card_token(payment_method) : payment_method + add_card(action, post, card_token, options) add_card_present(post, options) commit(action, post, options) end + alias credit refund + def void(authorization, options = {}) options[:invoice] = get_invoice(authorization) commit('invoice', {}, options) diff --git a/test/remote/gateways/remote_shift4_test.rb b/test/remote/gateways/remote_shift4_test.rb index 0b4f3a0ef52..4403868aa71 100644 --- a/test/remote/gateways/remote_shift4_test.rb +++ b/test/remote/gateways/remote_shift4_test.rb @@ -215,6 +215,18 @@ def test_failed_refund assert_include response.message, 'record not posted' end + def test_successful_credit + response = @gateway.credit(@amount, @credit_card, @options) + assert_success response + assert_equal response.message, 'Transaction successful' + end + + def test_failed_credit + response = @gateway.credit(@amount, @declined_card, @options) + assert_failure response + assert_include response.message, 'Card type not recognized' + end + def test_successful_refund res = @gateway.purchase(@amount, @credit_card, @options) assert_success res diff --git a/test/unit/gateways/shift4_test.rb b/test/unit/gateways/shift4_test.rb index bf187782c3e..267de4254c9 100644 --- a/test/unit/gateways/shift4_test.rb +++ b/test/unit/gateways/shift4_test.rb @@ -223,6 +223,18 @@ def test_successful_refund assert_equal response.message, 'Transaction successful' end + def test_successful_credit + stub_comms do + @gateway.refund(@amount, @credit_card, @options.merge!(invoice: '4666309473', expiration_date: '1235')) + end.check_request do |_endpoint, data, _headers| + request = JSON.parse(data) + assert_equal request['card']['present'], 'N' + assert_equal request['card']['expirationDate'], '0924' + assert_nil request['card']['entryMode'] + assert_nil request['customer'] + end.respond_with(successful_refund_response) + end + def test_successful_void @gateway.expects(:ssl_request).returns(successful_void_response) response = @gateway.void('123')