Skip to content

Commit

Permalink
[Realex] Add 3DS support through external MPI (#3284)
Browse files Browse the repository at this point in the history
* [Realex] Add 3DS support through external MPI

A few sample request we got from Realex contacts

```
<mpi>
  <cavv>AAACBllleHchZTBWIGV4AAAAAAA=</cavv>
  <xid>crqAeMwkEL9r4POdxpByWJ1/wYg=</xid>
  <eci>5</eci>
  <message_version>1</message_version>
</mpi>
```

And

```
<mpi>
  <eci>5</eci>
  <ds_trans_id>c272b04f-6e7b-43a2-bb78-90f4fb94aa25</ds_trans_id>
  <authentication_value>ODQzNjgwNjU0ZjM3N2JmYTg0NTM=</authentication_value>
  <message_version>2.1.0</message_version>
</mpi>
```

* Prefer single quotes

* Adding fixtures for 3DS
  • Loading branch information
filipebarcos authored Jul 24, 2019
1 parent d810c75 commit c0c0e8e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 28 deletions.
16 changes: 11 additions & 5 deletions lib/active_merchant/billing/gateways/realex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,18 @@ def add_network_tokenization_card(xml, payment)
end

def add_three_d_secure(xml, options)
if options[:three_d_secure]
xml.tag! 'mpi' do
xml.tag! 'cavv', options[:three_d_secure][:cavv]
xml.tag! 'eci', options[:three_d_secure][:eci]
xml.tag! 'xid', options[:three_d_secure][:xid]
return unless three_d_secure = options[:three_d_secure]
version = three_d_secure.fetch(:version, '')
xml.tag! 'mpi' do
if version =~ /^2/
xml.tag! 'authentication_value', three_d_secure[:cavv]
xml.tag! 'ds_trans_id', three_d_secure[:ds_transaction_id]
else
xml.tag! 'cavv', three_d_secure[:cavv]
xml.tag! 'xid', three_d_secure[:xid]
end
xml.tag! 'eci', three_d_secure[:eci]
xml.tag! 'message_version', version
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,12 @@ realex_visa:
year: '2020'
verification_value: '123'

realex_visa_3ds_enrolled:
number: '4012001037141112'
month: '9'
year: '2021'
verification_value: '123'

realex_visa_coms_error:
number: '4009830000001985'
month: '6'
Expand Down
41 changes: 31 additions & 10 deletions test/remote/gateways/remote_realex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
class RemoteRealexTest < Test::Unit::TestCase

def setup
@gateway = RealexGateway.new(fixtures(:realex))
@gateway = RealexGateway.new(fixtures(:realex_with_account))

# Replace the card numbers with the test account numbers from Realex
@visa = card_fixtures(:realex_visa)
@visa_declined = card_fixtures(:realex_visa_declined)
@visa_referral_b = card_fixtures(:realex_visa_referral_b)
@visa_referral_a = card_fixtures(:realex_visa_referral_a)
@visa_coms_error = card_fixtures(:realex_visa_coms_error)
@visa = card_fixtures(:realex_visa)
@visa_declined = card_fixtures(:realex_visa_declined)
@visa_referral_b = card_fixtures(:realex_visa_referral_b)
@visa_referral_a = card_fixtures(:realex_visa_referral_a)
@visa_coms_error = card_fixtures(:realex_visa_coms_error)
@visa_3ds_enrolled = card_fixtures(:realex_visa_3ds_enrolled)

@mastercard = card_fixtures(:realex_mastercard)
@mastercard_declined = card_fixtures(:realex_mastercard_declined)
Expand Down Expand Up @@ -115,12 +116,33 @@ def test_realex_purchase_with_apple_pay_declined
assert_match %r{DECLINED}i, response.message
end

def test_realex_purchase_with_three_d_secure
def test_realex_purchase_with_three_d_secure_1
response = @gateway.purchase(
1000,
@visa,
@visa_3ds_enrolled,
three_d_secure: {
eci: '05', xid: '05', cavv: '05'
eci: '05',
cavv: 'AgAAAAAAAIR8CQrXcIhbQAAAAAA',
xid: 'MDAwMDAwMDAwMDAwMDAwMzIyNzY=',
version: '1.0.2',
},
:order_id => generate_unique_id,
:description => 'Test Realex with 3DS'
)
assert_success response
assert response.test?
assert_equal 'Successful', response.message
end

def test_realex_purchase_with_three_d_secure_2
response = @gateway.purchase(
1000,
@visa_3ds_enrolled,
three_d_secure: {
eci: '05',
cavv: 'AgAAAAAAAIR8CQrXcIhbQAAAAAA',
ds_transaction_id: 'bDE9Aa1A-C5Ac-AD3a-4bBC-aC918ab1de3E',
version: '2.1.0',
},
:order_id => generate_unique_id,
:description => 'Test Realex with 3DS'
Expand Down Expand Up @@ -163,7 +185,6 @@ def test_realex_purchase_coms_error
:order_id => generate_unique_id,
:description => 'Test Realex coms error'
)

assert_not_nil response
assert_failure response

Expand Down
73 changes: 60 additions & 13 deletions test/unit/gateways/realex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,29 +339,31 @@ def test_transcript_scrubbing
assert_equal scrubbed_transcript, @gateway.scrub(transcript)
end

def test_three_d_secure
def test_three_d_secure_1
@gateway.expects(:ssl_post).returns(successful_purchase_response)

options = {
:order_id => '1',
:three_d_secure => {
:cavv => '1234',
:eci => '1234',
:xid => '1234'
order_id: '1',
three_d_secure: {
cavv: '1234',
eci: '1234',
xid: '1234',
version: '1.0.2',
}
}

response = @gateway.authorize(@amount, @credit_card, options)
assert_equal 'M', response.cvv_result['code']
end

def test_auth_xml_with_three_d_secure
def test_auth_xml_with_three_d_secure_1
options = {
:order_id => '1',
:three_d_secure => {
:cavv => '1234',
:eci => '1234',
:xid => '1234'
order_id: '1',
three_d_secure: {
cavv: '1234',
eci: '1234',
xid: '1234',
version: '1.0.2',
}
}

Expand All @@ -388,8 +390,53 @@ def test_auth_xml_with_three_d_secure
<sha1hash>3499d7bc8dbacdcfba2286bd74916d026bae630f</sha1hash>
<mpi>
<cavv>1234</cavv>
<eci>1234</eci>
<xid>1234</xid>
<eci>1234</eci>
<message_version>1.0.2</message_version>
</mpi>
</request>
SRC

assert_xml_equal valid_auth_request_xml, @gateway.build_purchase_or_authorization_request(:authorization, @amount, @credit_card, options)
end

def test_auth_xml_with_three_d_secure_2
options = {
order_id: '1',
three_d_secure: {
cavv: '1234',
eci: '1234',
ds_transaction_id: '1234',
version: '2.1.0',
}
}

@gateway.expects(:new_timestamp).returns('20090824160201')

valid_auth_request_xml = <<-SRC
<request timestamp="20090824160201" type="auth">
<merchantid>your_merchant_id</merchantid>
<account>your_account</account>
<orderid>1</orderid>
<amount currency=\"EUR\">100</amount>
<card>
<number>4263971921001307</number>
<expdate>0808</expdate>
<chname>Longbob Longsen</chname>
<type>VISA</type>
<issueno></issueno>
<cvn>
<number></number>
<presind></presind>
</cvn>
</card>
<autosettle flag="0"/>
<sha1hash>3499d7bc8dbacdcfba2286bd74916d026bae630f</sha1hash>
<mpi>
<authentication_value>1234</authentication_value>
<ds_trans_id>1234</ds_trans_id>
<eci>1234</eci>
<message_version>2.1.0</message_version>
</mpi>
</request>
SRC
Expand Down

0 comments on commit c0c0e8e

Please sign in to comment.