Skip to content

Commit

Permalink
Adyen: Update split refund method
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang committed Aug 27, 2024
1 parent a3b747a commit 780a77d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Naranja: Update valid number check to include luhn10 [DustinHaefele] #5217
* Cybersource: Add apple_pay with discover. [DustinHaefele] #5213
* MercadoPago: Add idempotency key field [yunnydang] #5229
* Adyen: Update split refund method [yunnydang] #5218

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
11 changes: 6 additions & 5 deletions lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,17 @@ def add_splits(post, options)

splits = []
split_data.each do |split|
amount = {
value: split['amount']['value']
}
amount[:currency] = split['amount']['currency'] if split['amount']['currency']
if split['amount']
amount = {}
amount[:value] = split['amount']['value'] if split['amount']['value']
amount[:currency] = split['amount']['currency'] if split['amount']['currency']
end

split_hash = {
amount: amount,
type: split['type'],
reference: split['reference']
}
split_hash[:amount] = amount unless amount.nil?
split_hash['account'] = split['account'] if split['account']
splits.push(split_hash)
end
Expand Down
18 changes: 18 additions & 0 deletions test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,24 @@ def test_splits_sent
end.respond_with(successful_authorize_response)
end

def test_splits_sent_without_amount
split_data = [{
'type' => 'MarketPlace',
'account' => '163298747',
'reference' => 'QXhlbFN0b2x0ZW5iZXJnCg'
}, {
'type' => 'Commission',
'reference' => 'THVjYXNCbGVkc29lCg'
}]

options = @options.merge({ splits: split_data })
stub_comms do
@gateway.authorize(@amount, @credit_card, options)
end.check_request do |_endpoint, data, _headers|
assert_equal split_data, JSON.parse(data)['splits']
end.respond_with(successful_authorize_response)
end

def test_execute_threed_false_with_additional_data
stub_comms do
@gateway.authorize(@amount, @credit_card, @options.merge({ execute_threed: false, overwrite_brand: true, selected_brand: 'maestro' }))
Expand Down

0 comments on commit 780a77d

Please sign in to comment.