Skip to content

Commit

Permalink
DLocal: add the description field for refund
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang committed Oct 8, 2024
1 parent 2070627 commit b317b8c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* Paysafe: Add support for `external_initial_transaction_id` [rachelkirk] #5291
* Worldpay: Add customStringFields [jcreiff] #5284
* Airwallex: truncate descriptor field to 32 characters [jcreiff] #5292
* DLocal: Add the description field for refund [yunnydang] #5296

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
7 changes: 6 additions & 1 deletion lib/active_merchant/billing/gateways/d_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def capture(money, authorization, options = {})

def refund(money, authorization, options = {})
post = {}
add_description(post, options)
post[:payment_id] = authorization
post[:notification_url] = options[:notification_url]
add_invoice(post, money, options) if money
Expand Down Expand Up @@ -90,16 +91,20 @@ def add_auth_purchase_params(post, money, card, action, options)
add_payer(post, card, options)
add_card(post, card, action, options)
add_additional_data(post, options)
add_description(post, options)
post[:order_id] = options[:order_id] || generate_unique_id
post[:original_order_id] = options[:original_order_id] if options[:original_order_id]
post[:description] = options[:description] if options[:description]
end

def add_invoice(post, money, options)
post[:amount] = amount(money)
post[:currency] = (options[:currency] || currency(money))
end

def add_description(post, options)
post[:description] = options[:description] if options[:description]
end

def add_additional_data(post, options)
post[:additional_risk_data] = options[:additional_data]
end
Expand Down
10 changes: 10 additions & 0 deletions test/remote/gateways/remote_d_local_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ def test_failed_refund
assert_match 'Amount exceeded', response.message
end

def test_successful_refund_with_description
purchase = @gateway.purchase(@amount, @credit_card, @options)
assert_success purchase

assert refund = @gateway.refund(@amount, purchase.authorization, @options.merge(notification_url: 'http://example.com', description: 'test'))
assert_success refund
assert_match 'The refund was paid', refund.message
assert_match 'test', refund.params['description']
end

def test_successful_void
auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
Expand Down
8 changes: 8 additions & 0 deletions test/unit/gateways/d_local_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ def test_failed_refund
assert_equal '5007', response.error_code
end

def test_successful_refund_with_description
stub_comms(@gateway, :ssl_request) do
@gateway.refund(@amount, @credit_card, @options.merge(description: 'test'))
end.check_request do |_method, _endpoint, data, _headers|
assert_match(/"description\":\"test\"/, data)
end.respond_with(successful_refund_response)
end

def test_successful_void
@gateway.expects(:ssl_post).returns(successful_void_response)

Expand Down

0 comments on commit b317b8c

Please sign in to comment.