Skip to content

Commit

Permalink
Worldpay: check payment_method responds to payment_cryptogram and eci (
Browse files Browse the repository at this point in the history
  • Loading branch information
bbraschi authored Jun 21, 2023
1 parent 66ba752 commit e72fe66
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
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

{ 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

0 comments on commit e72fe66

Please sign in to comment.