Skip to content

Commit

Permalink
Nuvie/SafeCharge: Add unreferenced refund field
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang committed Jul 19, 2023
1 parent 8f663b6 commit 8dd0d54
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Kushki: Add Brazil as supported country [almalee24] #4829
* Adyen: Add additional data for airline and lodging [javierpedrozaing] #4815
* MIT: Changed how the payload was sent to the gateway [alejandrofloresm] #4655
* SafeCharge: Add unreferenced_refund field [yunnydang] #4831

== Version 1.131.0 (June 21, 2023)
* Redsys: Add supported countries [jcreiff] #4811
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/safe_charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def refund(money, authorization, options = {})
add_transaction_data('Credit', post, money, options.merge!({ currency: original_currency }))
post[:sg_CreditType] = 2
post[:sg_AuthCode] = auth
post[:sg_TransactionID] = transaction_id
post[:sg_CCToken] = token
post[:sg_ExpMonth] = exp_month
post[:sg_ExpYear] = exp_year
post[:sg_TransactionID] = transaction_id unless options[:unreferenced_refund]

commit(post)
end
Expand Down
12 changes: 12 additions & 0 deletions test/remote/gateways/remote_safe_charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ def test_failed_refund
assert_equal 'Transaction must contain a Card/Token/Account', response.message
end

def test_successful_unreferenced_refund
option = {
unreferenced_refund: true
}
purchase = @gateway.purchase(@amount, @credit_card, @options)
assert_success purchase

assert refund = @gateway.refund(@amount, purchase.authorization, option)
assert_success refund
assert_equal 'Success', refund.message
end

def test_successful_credit
response = @gateway.credit(@amount, credit_card('4444436501403986'), @options)
assert_success response
Expand Down
20 changes: 20 additions & 0 deletions test/unit/gateways/safe_charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ def test_successful_refund
assert_equal 'Success', response.message
end

def test_successful_unreferenced_refund
refund = stub_comms do
@gateway.refund(@amount, 'auth|transaction_id|token|month|year|amount|currency', @options.merge(unreferenced_refund: true))
end.check_request do |_endpoint, data, _headers|
assert_equal(data.split('&').include?('sg_TransactionID=transaction_id'), false)
end.respond_with(successful_refund_response)

assert_success refund
end

def test_successful_refund_without_unreferenced_refund
refund = stub_comms do
@gateway.refund(@amount, 'auth|transaction_id|token|month|year|amount|currency', @options)
end.check_request do |_endpoint, data, _headers|
assert_equal(data.split('&').include?('sg_TransactionID=transaction_id'), true)
end.respond_with(successful_refund_response)

assert_success refund
end

def test_failed_refund
@gateway.expects(:ssl_post).returns(failed_refund_response)

Expand Down

0 comments on commit 8dd0d54

Please sign in to comment.