Skip to content

Commit

Permalink
Kushki: Enable 3ds2
Browse files Browse the repository at this point in the history
Summary:

Enable 3ds version 2 on the gateway above
  • Loading branch information
jherreraa committed Jul 18, 2023
1 parent 97f2037 commit 55af594
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
38 changes: 33 additions & 5 deletions lib/active_merchant/billing/gateways/kushki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def initialize(options = {})
def purchase(amount, payment_method, options = {})
MultiResponse.run() do |r|
r.process { tokenize(amount, payment_method, options) }
r.process { charge(amount, r.authorization, options) }
r.process { charge(amount, r.authorization, options, payment_method) }
end
end

def authorize(amount, payment_method, options = {})
MultiResponse.run() do |r|
r.process { tokenize(amount, payment_method, options) }
r.process { preauthorize(amount, r.authorization, options) }
r.process { preauthorize(amount, r.authorization, options, payment_method) }
end
end

Expand Down Expand Up @@ -89,7 +89,7 @@ def tokenize(amount, payment_method, options)
commit(action, post)
end

def charge(amount, authorization, options)
def charge(amount, authorization, options, payment_method = {})
action = 'charge'

post = {}
Expand All @@ -100,11 +100,12 @@ def charge(amount, authorization, options)
add_metadata(post, options)
add_months(post, options)
add_deferred(post, options)
add_three_d_secure(post, payment_method, options)

commit(action, post)
end

def preauthorize(amount, authorization, options)
def preauthorize(amount, authorization, options, payment_method = {})
action = 'preAuthorization'

post = {}
Expand All @@ -114,6 +115,7 @@ def preauthorize(amount, authorization, options)
add_metadata(post, options)
add_months(post, options)
add_deferred(post, options)
add_three_d_secure(post, payment_method, options)

commit(action, post)
end
Expand Down Expand Up @@ -183,7 +185,8 @@ def add_contact_details(post, contact_details_options)
end

def add_full_response(post, options)
post[:fullResponse] = options[:full_response].to_s.casecmp('true').zero? if options[:full_response]
#post[:fullResponse] = options[:full_response].to_s.casecmp('true').zero? if options[:full_response]
post[:fullResponse] = 'v2'
end

def add_metadata(post, options)
Expand All @@ -204,6 +207,31 @@ def add_deferred(post, options)
}
end

def add_three_d_secure(post, payment_method, options)
three_d_secure = options[:three_d_secure]
return unless three_d_secure

if payment_method.brand == 'mastercard'
collection_indicator = 2
ucaf = three_d_secure[:cavv]
three_d_secure[:cavv] = nil
else
collection_indicator = nil
ucaf = nil
end

post[:threeDomainSecure] = {
specificationVersion: three_d_secure[:version],
acceptRisk: true,
eci: three_d_secure[:eci],
cavv: three_d_secure[:cavv],
xid: three_d_secure[:xid],
directoryServerTransactionID: three_d_secure[:ds_transaction_id],
collectionIndicator: collection_indicator,
ucaf: ucaf
}.compact
end

ENDPOINT = {
'tokenize' => 'tokens',
'charge' => 'charges',
Expand Down
32 changes: 32 additions & 0 deletions test/remote/gateways/remote_kushki_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,38 @@ def test_failed_authorize
assert_equal 'Monto de la transacción es diferente al monto de la venta inicial', response.message
end

def test_successful_3ds2_authorize
options = {
currency: 'PEN',
three_d_secure: {
version: '2.2.0',
authentication_response_status: 'Y',
cavv: 'AAABBoVBaZKAR3BkdkFpELpWIiE= ',
xid: 'NEpab1F1MEdtaWJ2bEY3ckYxQzE=',
eci: '07'
}
}
response = @gateway.authorize(@amount, @credit_card, options)
assert_success response
assert_equal 'Succeeded', response.message
assert_match %r(^\d+$), response.authorization
end

def test_successful_3ds2_purchase
options = {
three_d_secure: {
version: '2.2.0',
cavv: 'AAABBoVBaZKAR3BkdkFpELpWIiE= ',
xid: 'NEpab1F1MEdtaWJ2bEY3ckYxQzE=',
eci: '07'
}
}
response = @gateway.purchase(@amount, @credit_card, options)
assert_success response
assert_equal 'Succeeded', response.message
assert_match %r(^\d+$), response.authorization
end

def test_successful_capture
auth = @gateway.authorize(@amount, @credit_card)
assert_success auth
Expand Down

0 comments on commit 55af594

Please sign in to comment.