Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuvie/SafeCharge: Add unreferenced refund field #4831

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading