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

SER-625

Unit Test

Finished in 0.019977 seconds.
------------------------------------------------------------------------------------------------------
17 tests, 109 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
------------------------------------------------------------------------------------------------------

Remote Test

Finished in 77.484256 seconds.
------------------------------------------------------------------------------------------------------
22 tests, 67 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
------------------------------------------------------------------------------------------------------
  • Loading branch information
jherreraa committed Jul 19, 2023
1 parent 8dd0d54 commit a2ec3ae
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 4 deletions.
38 changes: 34 additions & 4 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 @@ -204,6 +206,34 @@ 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.present?

post[:threeDomainSecure] = {
eci: three_d_secure[:eci],
specificationVersion: three_d_secure[:version]
}

if payment_method.brand == 'mastercard'
post[:threeDomainSecure][:acceptRisk] = three_d_secure[:eci] == '00'
post[:threeDomainSecure][:ucaf] = three_d_secure[:cavv]
post[:threeDomainSecure][:directoryServerTransactionID] = three_d_secure[:ds_transaction_id]
case three_d_secure[:eci]
when '07'
post[:threeDomainSecure][:collectionIndicator] = '0'
when '06'
post[:threeDomainSecure][:collectionIndicator] = '1'
else
post[:threeDomainSecure][:collectionIndicator] = '2'
end
else
post[:threeDomainSecure][:acceptRisk] = three_d_secure[:eci] == '07'
post[:threeDomainSecure][:cavv] = three_d_secure[:cavv]
post[:threeDomainSecure][:xid] = three_d_secure[:xid]
end
end

ENDPOINT = {
'tokenize' => 'tokens',
'charge' => 'charges',
Expand Down
81 changes: 81 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,87 @@ 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_with_visa_card
options = {
currency: 'PEN',
three_d_secure: {
version: '2.2.0',
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_authorize_with_master_card
options = {
currency: 'PEN',
three_d_secure: {
version: '2.2.0',
cavv: 'AAABBoVBaZKAR3BkdkFpELpWIiE=',
eci: '00',
ds_transaction_id: 'b23e0264-1209-41L6-Jca4-b82143c1a782'
}
}

credit_card = credit_card('5223450000000007', brand: 'mastercard', verification_value: '777')
response = @gateway.authorize(@amount, credit_card, options)
assert_success response
assert_equal 'Succeeded', response.message
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_failed_3ds2_authorize
options = {
currency: 'PEN',
three_d_secure: {
version: '2.2.0',
authentication_response_status: 'Y',
cavv: 'AAABBoVBaZKAR3BkdkFpELpWIiE=',
xid: 'NEpab1F1MEdtaWJ2bEY3ckYxQzE='
}
}
response = @gateway.authorize(@amount, @credit_card, options)
assert_failure response
assert_equal 'K001', response.responses.last.error_code
end

def test_failed_3ds2_authorize_with_different_card
options = {
currency: 'PEN',
three_d_secure: {
version: '2.2.0',
cavv: 'AAABBoVBaZKAR3BkdkFpELpWIiE=',
xid: 'NEpab1F1MEdtaWJ2bEY3ckYxQzE='
}
}

credit_card = credit_card('6011111111111117', brand: 'discover', verification_value: '777')
response = @gateway.authorize(@amount, credit_card, options)
assert_failure response
assert_equal 'K001', response.responses.last.error_code
end

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

0 comments on commit a2ec3ae

Please sign in to comment.