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')