Skip to content

Commit 41be5e9

Browse files
authored
Merge pull request #60 from maxmind/nlogan/8-digit-iin-2-digit-lastdigits
Add support for 8 digit IINs and 2 digit last_digits
2 parents 8d5a4b9 + 2968ec5 commit 41be5e9

File tree

4 files changed

+76
-11
lines changed

4 files changed

+76
-11
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44

55
* Adds the following new processor to `Minfraud::Components::Payment`:
66
* `:windcave`
7+
* The `last_4_digits` input to `Minfraud::Components::CreditCard` has been
8+
deprecated in favor of `last_digits` and will be removed in a future
9+
release. `last_digits`/`last_4_digits` also now supports two digit values
10+
in addition to the previous four digit values.
11+
* Eight digit `issuer_id_number` inputs are now supported by
12+
`Minfraud::Components::CreditCard` in addition to the previously accepted
13+
six digit `issuer_id_number`. In most cases, you should send the last four
14+
digits for `last_digits`. If you send an `issuer_id_number` that contains
15+
an eight digit IIN, and if the credit card brand is not one of the
16+
following, you should send the last two digits for `last_digits`:
17+
* `Discover`
18+
* `JCB`
19+
* `Mastercard`
20+
* `UnionPay`
21+
* `Visa`
722

823
## v2.0.0 (2021-12-06)
924

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ assessment = Minfraud::Assessments.new(
123123
},
124124
credit_card: {
125125
issuer_id_number: '411111',
126-
last_4_digits: '7643',
126+
last_digits: '7643',
127127
bank_name: 'Bank of No Hope',
128128
bank_phone_country_code: '1',
129129
bank_phone_number: '123-456-1234',

lib/minfraud/components/credit_card.rb

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ module Components
88
class CreditCard < Base
99
include Minfraud::Validates
1010

11-
# The issuer ID number for the credit card. This is the first 6 digits of
12-
# the credit card number. It identifies the issuing bank.
11+
# The issuer ID number for the credit card. This is the first 6 or 8
12+
# digits of the credit card number. It identifies the issuing bank.
1313
#
1414
# @return [String, nil]
1515
attr_accessor :issuer_id_number
1616

17-
# The last four digits of the credit card number.
17+
# The last two or four digits of the credit card number.
18+
#
19+
# @see https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--credit-card__last_digits
1820
#
1921
# @return [String, nil]
20-
attr_accessor :last_4_digits
22+
attr_accessor :last_digits
2123

2224
# The name of the issuing bank as provided by the end user.
2325
#
@@ -72,12 +74,30 @@ class CreditCard < Base
7274
# @return [Boolean, nil]
7375
attr_accessor :was_3d_secure_successful
7476

77+
# Get the last digits of the credit card number.
78+
#
79+
# @deprecated Use {::last_digits} instead.
80+
#
81+
# @return [String, nil]
82+
def last_4_digits
83+
@last_digits
84+
end
85+
86+
# Set the last digits of the credit card number.
87+
#
88+
# @deprecated Use {::last_digits} instead.
89+
#
90+
# @return [String, nil]
91+
def last_4_digits=(last4)
92+
@last_digits = last4
93+
end
94+
7595
# @param params [Hash] Hash of parameters. Each key/value should
7696
# correspond to one of the available attributes.
7797
def initialize(params = {})
7898
@bank_phone_country_code = params[:bank_phone_country_code]
7999
@issuer_id_number = params[:issuer_id_number]
80-
@last_4_digits = params[:last_4_digits]
100+
@last_digits = params[:last_digits] || params[:last_4_digits]
81101
@bank_name = params[:bank_name]
82102
@bank_phone_number = params[:bank_phone_number]
83103
@avs_result = params[:avs_result]
@@ -94,8 +114,8 @@ def validate
94114
return if !Minfraud.enable_validation
95115

96116
validate_telephone_country_code('bank_phone_country_code', @bank_phone_country_code)
97-
validate_regex('issuer_id_number', /\A[0-9]{6}\z/, @issuer_id_number)
98-
validate_regex('last_4_digits', /\A[0-9]{4}\z/, @last_4_digits)
117+
validate_regex('issuer_id_number', /\A(?:[0-9]{6}|[0-9]{8})\z/, @issuer_id_number)
118+
validate_regex('last_digits', /\A(?:[0-9]{2}|[0-9]{4})\z/, @last_digits)
99119
validate_string('bank_name', 255, @bank_name)
100120
validate_string('bank_phone_number', 255, @bank_phone_number)
101121
validate_string('avs_result', 1, @avs_result)

spec/components/credit_card_spec.rb

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
end.to raise_exception(Minfraud::InvalidInputError)
1717
end
1818

19+
it 'raises an exception for an invalid last_digits' do
20+
expect do
21+
Minfraud::Components::CreditCard.new(
22+
last_digits: '6',
23+
)
24+
end.to raise_exception(Minfraud::InvalidInputError)
25+
end
26+
1927
it 'raises an exception for an invalid last_4_digits' do
2028
expect do
2129
Minfraud::Components::CreditCard.new(
@@ -40,19 +48,41 @@
4048
end.to raise_exception(Minfraud::InvalidInputError)
4149
end
4250

43-
it 'does not raise an exception for valid values' do
44-
Minfraud::Components::CreditCard.new(
51+
it 'does not raise an exception for valid values (deprecated last_4_digits)' do
52+
@cc = Minfraud::Components::CreditCard.new(
4553
issuer_id_number: '123456',
4654
last_4_digits: '1234',
4755
token: 'abcd',
4856
was_3d_secure_successful: true,
4957
)
58+
expect(@cc.last_digits).to be(@cc.last_4_digits)
59+
expect(@cc.last_digits).to be('1234')
60+
end
61+
62+
it 'does not raise an exception for valid values (eight digit issuer_id_number)' do
63+
Minfraud::Components::CreditCard.new(
64+
issuer_id_number: '12345678',
65+
last_4_digits: '1234',
66+
token: 'abcd',
67+
was_3d_secure_successful: true,
68+
)
69+
end
70+
71+
it 'does not raise an exception for valid values (two digit last_digits)' do
72+
@cc = Minfraud::Components::CreditCard.new(
73+
issuer_id_number: '12345678',
74+
last_digits: '34',
75+
token: 'abcd',
76+
was_3d_secure_successful: true,
77+
)
78+
expect(@cc.last_digits).to be(@cc.last_4_digits)
79+
expect(@cc.last_digits).to be('34')
5080
end
5181

5282
it 'does not raise an exception for valid values (token is all digits)' do
5383
Minfraud::Components::CreditCard.new(
5484
issuer_id_number: '123456',
55-
last_4_digits: '1234',
85+
last_digits: '1234',
5686
token: '1' * 20,
5787
was_3d_secure_successful: true,
5888
)

0 commit comments

Comments
 (0)