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

Amount allocation Object #22

Open
wants to merge 1 commit into
base: feature/2024-09-sync-upstream
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions lib/active_merchant/billing/gateways/checkout_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def build_auth_or_purchase(post, amount, payment_method, options)
add_3ds(post, options)
add_metadata(post, options, payment_method)
add_processing_channel(post, options)
add_amount_allocations_data(post, options)
add_marketplace_data(post, options)
add_recipient_data(post, options)
add_processing_data(post, options)
Expand Down Expand Up @@ -503,6 +504,14 @@ def add_marketplace_data(post, options)
end
end

def add_amount_allocations_data(post, options)
return unless options[:amount_allocations]&.is_a?(Array)

post[:amount_allocations] = options[:amount_allocations].select do |v|
v[:id].present? && v[:amount].present?
end
end

def access_token_header
{
'Authorization' => "Basic #{Base64.encode64("#{@options[:client_id]}:#{@options[:client_secret]}").delete("\n")}",
Expand Down
14 changes: 11 additions & 3 deletions test/remote/gateways/remote_checkout_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def setup
email: '[email protected]',
processing_channel_id: 'pc_lxgl7aqahkzubkundd2l546hdm'
}
@options_for_verify = @options.merge({
amount_allocations: [
{
id: 'ent_123',
amount: 0
}
]
})
@additional_options = @options.merge(
card_on_file: true,
transaction_indicator: 2,
Expand Down Expand Up @@ -1130,21 +1138,21 @@ def test_failed_void_via_oauth
end

def test_successful_verify
response = @gateway.verify(@credit_card, @options)
response = @gateway.verify(@credit_card, @options_for_verify)
assert_success response
assert_match %r{Succeeded}, response.message
end

def test_successful_verify_via_oauth
response = @gateway_oauth.verify(@credit_card, @options)
response = @gateway_oauth.verify(@credit_card, @options_for_verify)
assert_success response
assert_match %r{Succeeded}, response.message
assert_not_nil response.responses.first.params['access_token']
assert_not_nil response.responses.first.params['expires']
end

def test_failed_verify
response = @gateway.verify(@declined_card, @options)
response = @gateway.verify(@declined_card, @options_for_verify)
assert_failure response
assert_match %r{request_invalid: card_number_invalid}, response.message
end
Expand Down
40 changes: 40 additions & 0 deletions test/unit/gateways/checkout_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,46 @@ def test_successful_authorize_and_capture_with_additional_options
assert_success capture
end

def test_successful_authorize_and_capture_with_additional_options_ammount_allocation
response = stub_comms(@gateway, :ssl_request) do
options = {
card_on_file: true,
transaction_indicator: 2,
previous_charge_id: 'pay_123',
processing_channel_id: 'pc_123',
amount_allocations: [
{
id: 'ent_123',
amount: 49
},
{
id: 'ent_456',
amount: 51
},
{
id: 'ent_789'
}
]
}
@gateway.authorize(@amount, @credit_card, options)
end.check_request do |_method, _endpoint, data, _headers|
assert_match(%r{"stored":"true"}, data)
assert_match(%r{"payment_type":"Recurring"}, data)
assert_match(%r{"previous_payment_id":"pay_123"}, data)
assert_match(%r{"processing_channel_id":"pc_123"}, data)
assert_match(/"amount_allocations\":\[{\"id\":\"ent_123\",\"amount\":49},{\"id\":\"ent_456\",\"amount\":51}\]/, data)
end.respond_with(successful_authorize_response)

assert_success response
assert_equal 'pay_fj3xswqe3emuxckocjx6td73ni', response.authorization

capture = stub_comms(@gateway, :ssl_request) do
@gateway.capture(@amount, response.authorization)
end.respond_with(successful_capture_response)

assert_success capture
end

def test_successful_purchase_with_stored_credentials
initial_response = stub_comms(@gateway, :ssl_request) do
initial_options = {
Expand Down
Loading