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

Worldpay: check payment_method responds to payment_cryptogram and eci #4812

Merged
merged 1 commit into from
Jun 21, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
== HEAD
* Redsys: Add supported countries [jcreiff] #4811
* Authorize.net: Truncate nameOnAccount for bank refunds [jcreiff] #4808
* Worldpay: check payment_method responds to payment_cryptogram and eci [bbraschi] #4812

== Version 1.130.0 (June 13th, 2023)
* Payu Latam - Update error code method to surface network code [yunnydang] #4773
Expand Down
8 changes: 7 additions & 1 deletion lib/active_merchant/billing/gateways/worldpay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,18 @@ def payment_details(payment_method)
when String
token_type_and_details(payment_method)
else
type = payment_method.respond_to?(:source) ? :network_token : :credit
type = network_token?(payment_method) ? :network_token : :credit
m-ocana marked this conversation as resolved.
Show resolved Hide resolved

{ payment_type: type }
end
end

def network_token?(payment_method)
payment_method.respond_to?(:source) &&
payment_method.respond_to?(:payment_cryptogram) &&
payment_method.respond_to?(:eci)
end

def token_type_and_details(token)
token_details = token_details_from_authorization(token)
token_details[:payment_type] = token_details.has_key?(:token_id) ? :token : :pay_as_order
Expand Down
28 changes: 28 additions & 0 deletions test/unit/gateways/worldpay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ def test_payment_type_for_network_card
assert_equal payment, :network_token
end

def test_payment_type_returns_network_token_if_the_payment_method_responds_to_source_payment_cryptogram_and_eci
payment_method = mock
payment_method.stubs(source: nil, payment_cryptogram: nil, eci: nil)
result = @gateway.send(:payment_details, payment_method)
assert_equal({ payment_type: :network_token }, result)
end

def test_payment_type_returns_credit_if_the_payment_method_does_not_responds_to_source
payment_method = mock
payment_method.stubs(payment_cryptogram: nil, eci: nil)
result = @gateway.send(:payment_details, payment_method)
assert_equal({ payment_type: :credit }, result)
end

def test_payment_type_returns_credit_if_the_payment_method_does_not_responds_to_payment_cryptogram
payment_method = mock
payment_method.stubs(source: nil, eci: nil)
result = @gateway.send(:payment_details, payment_method)
assert_equal({ payment_type: :credit }, result)
end

def test_payment_type_returns_credit_if_the_payment_method_does_not_responds_to_eci
payment_method = mock
payment_method.stubs(source: nil, payment_cryptogram: nil)
result = @gateway.send(:payment_details, payment_method)
assert_equal({ payment_type: :credit }, result)
end

def test_payment_type_for_credit_card
payment = @gateway.send(:payment_details, @credit_card)[:payment_type]
assert_equal payment, :credit
Expand Down