Skip to content

Commit

Permalink
Checkout V2: add support for risk data fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang committed Jun 21, 2024
1 parent b636002 commit d31c20c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Plexo: Add support to NetworkToken payments [euribe09] #5130
* Braintree: Update card verfification payload if billing address fields are not present [yunnydang] #5142
* DLocal: Update the phone and ip fields [yunnydang] #5143
* CheckoutV2: Add support for risk data fields [yunnydang] #5147

== Version 1.136.0 (June 3, 2024)
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
Expand Down
15 changes: 15 additions & 0 deletions lib/active_merchant/billing/gateways/checkout_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def build_auth_or_purchase(post, amount, payment_method, options)
add_recipient_data(post, options)
add_processing_data(post, options)
add_payment_sender_data(post, options)
add_risk_data(post, options)
end

def add_invoice(post, money, options)
Expand Down Expand Up @@ -191,6 +192,20 @@ def add_processing_data(post, options)
post[:processing] = options[:processing]
end

def add_risk_data(post, options)
return unless options[:risk].is_a?(Hash)

risk = options[:risk]
post[:risk] = {} unless risk.empty?

if risk[:enabled].to_s == 'true'
post[:risk][:enabled] = true
post[:risk][:device_session_id] = risk[:device_session_id] if risk[:device_session_id]
elsif risk[:enabled].to_s == 'false'
post[:risk][:enabled] = false
end
end

def add_payment_sender_data(post, options)
return unless options[:sender].is_a?(Hash)

Expand Down
32 changes: 32 additions & 0 deletions test/remote/gateways/remote_checkout_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,38 @@ def test_successful_purchase_with_sender_data
assert_equal 'Succeeded', response.message
end

def test_successful_purchase_with_risk_data_true
options = @options.merge(
risk: {
enabled: 'true',
device_session_id: '12345-abcd'
}
)
response = @gateway.purchase(@amount, @credit_card, options)
assert_success response
assert_equal 'Succeeded', response.message
end

def test_successful_purchase_with_risk_data_false
options = @options.merge(
risk: {
enabled: 'false'
}
)
response = @gateway.purchase(@amount, @credit_card, options)
assert_success response
assert_equal 'Succeeded', response.message
end

def test_successful_purchase_with_empty_risk_data
options = @options.merge(
risk: {}
)
response = @gateway.purchase(@amount, @credit_card, options)
assert_success response
assert_equal 'Succeeded', response.message
end

def test_successful_purchase_with_metadata_via_oauth
options = @options.merge(
metadata: {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/gateways/checkout_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ def test_successful_passing_processing_channel_id
end.respond_with(successful_purchase_response)
end

def test_successful_passing_risk_data
stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, @credit_card, {
risk: {
enabled: 'true',
device_session_id: '12345-abcd'
}
})
end.check_request do |_method, _endpoint, data, _headers|
request = JSON.parse(data)['risk']
assert_equal request['enabled'], true
assert_equal request['device_session_id'], '12345-abcd'
end.respond_with(successful_purchase_response)
end

def test_successful_passing_incremental_authorization
response = stub_comms(@gateway, :ssl_request) do
@gateway.authorize(@amount, @credit_card, { incremental_authorization: 'abcd1234' })
Expand Down

0 comments on commit d31c20c

Please sign in to comment.