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

CyberSource: Add option to target 0 verify #4313

Closed
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: 7 additions & 2 deletions lib/active_merchant/billing/gateways/cyber_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def adjust(money, authorization, options = {})
end

def verify(payment, options = {})
amount = eligible_for_zero_auth?(payment, options) ? 0 : 100
MultiResponse.run(:use_first_response) do |r|
r.process { authorize(100, payment, options) }
r.process(:ignore_result) { void(r.authorization, options) }
r.process { authorize(amount, payment, options) }
r.process(:ignore_result) { void(r.authorization, options) } unless amount == 0
end
end

Expand Down Expand Up @@ -1079,6 +1080,10 @@ def message_from(response)
response[:message]
end
end

def eligible_for_zero_auth?(payment_method, options = {})
payment_method.is_a?(CreditCard) && options[:zero_amount_auth]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the switcheroo, but I just remembered an issue we've had recently with a similar field name being confusing for users, since this flag is specifically used for verify rather than authorize, and the suggestion was to keep the name as specific as possible.

Suggested change
payment_method.is_a?(CreditCard) && options[:zero_amount_auth]
payment_method.is_a?(CreditCard) && options[:zero_amount_verify]

Copy link
Contributor

@curiousepic curiousepic Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But no worries - I can make this change as part of the merge.

end
end
end
end
28 changes: 28 additions & 0 deletions test/remote/gateways/remote_cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def setup

@credit_card = credit_card('4111111111111111', verification_value: '987')
@declined_card = credit_card('801111111111111')
@master_credit_card = credit_card('5555555555554444',
verification_value: '321',
month: '12',
year: (Time.now.year + 2).to_s,
brand: :master)
@pinless_debit_card = credit_card('4002269999999999')
@elo_credit_card = credit_card('5067310000000010',
verification_value: '321',
Expand Down Expand Up @@ -1009,6 +1014,29 @@ def test_verify_credentials
assert !gateway.verify_credentials
end

def test_successful_verify
response = @gateway.verify(@credit_card, @options)
assert_success response
assert_match '1.00', response.params['amount']
assert_equal 'Successful transaction', response.message
end

def test_successful_verify_zero_amount_visa
@options[:zero_amount_auth] = true
response = @gateway.verify(@credit_card, @options)
assert_success response
assert_match '0.00', response.params['amount']
assert_equal 'Successful transaction', response.message
end

def test_successful_verify_zero_amount_master
@options[:zero_amount_auth] = true
response = @gateway.verify(@master_credit_card, @options)
assert_success response
assert_match '0.00', response.params['amount']
assert_equal 'Successful transaction', response.message
end

private

def assert_successful_response(response)
Expand Down
17 changes: 17 additions & 0 deletions test/unit/gateways/cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,23 @@ def test_successful_verify
assert_success response
end

def test_successful_verify_zero_amount_request
@options[:zero_amount_auth] = true
stub_comms(@gateway, :ssl_post) do
@gateway.verify(@credit_card, @options)
end.check_request(skip_response: true) do |_endpoint, data|
assert_match %r(<grandTotalAmount>0.00<\/grandTotalAmount>), data
end
end

def test_successful_verify_request
stub_comms(@gateway, :ssl_post) do
@gateway.verify(@credit_card, @options)
end.check_request(skip_response: true) do |_endpoint, data|
assert_match %r(<grandTotalAmount>1.00<\/grandTotalAmount>), data
end
end

def test_successful_verify_with_elo
response = stub_comms(@gateway, :ssl_request) do
@gateway.verify(@elo_credit_card, @options)
Expand Down