Skip to content

Commit

Permalink
Shift4: Enable general credit feature. (#4790)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jherreraa and naashton authored Jun 13, 2023
1 parent 8236186 commit 29e42a2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/active_merchant/billing/gateways/shift4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,23 @@ def capture(money, authorization, options = {})
commit(action, post, options)
end

def refund(money, authorization, options = {})
def refund(money, payment_method, options = {})
post = {}
action = 'refund'

add_datetime(post, 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)
Expand Down
12 changes: 12 additions & 0 deletions test/remote/gateways/remote_shift4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/unit/gateways/shift4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 29e42a2

Please sign in to comment.