Skip to content

Commit

Permalink
SER-728 Create Verve Card Type. This change new credit card brands ve…
Browse files Browse the repository at this point in the history
…rve and tests related to it. (#4875)

Co-authored-by: Nick Ashton <nashton@gmail.com>
  • Loading branch information
jherreraa and naashton committed Sep 6, 2023
1 parent 587795e commit 2eeb3ab
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
* TNS: Use the specified order_id in request if available [yunnydang] #4880
* Cybersource: Support recurring apple pay [aenand] #4874
* Verve BIN ranges and add card type to Rapyd gateway [jherreraa] #4875

== Version 1.135.0 (August 24, 2023)
* PaymentExpress: Correct endpoints [steveh] #4827
Expand Down
2 changes: 2 additions & 0 deletions lib/active_merchant/billing/credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Billing #:nodoc:
# * Anda
# * Creditos directos (Tarjeta D)
# * Panal
# * Verve
#
# For testing purposes, use the 'bogus' credit card brand. This skips the vast majority of
# validations, allowing you to focus on your core concerns until you're ready to be more concerned
Expand Down Expand Up @@ -132,6 +133,7 @@ def number=(value)
# * +'anda'+
# * +'tarjeta-d'+
# * +'panal'+
# * +'verve'+
#
# Or, if you wish to test your implementation, +'bogus'+.
#
Expand Down
40 changes: 39 additions & 1 deletion lib/active_merchant/billing/credit_card_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module CreditCardMethods
'anda' => ->(num) { num =~ /^603199\d{10}$/ },
'tarjeta-d' => ->(num) { num =~ /^601828\d{10}$/ },
'hipercard' => ->(num) { num&.size == 16 && in_bin_range?(num.slice(0, 6), HIPERCARD_RANGES) },
'panal' => ->(num) { num&.size == 16 && in_bin_range?(num.slice(0, 6), PANAL_RANGES) }
'panal' => ->(num) { num&.size == 16 && in_bin_range?(num.slice(0, 6), PANAL_RANGES) },
'verve' => ->(num) { (16..19).cover?(num&.size) && in_bin_range?(num.slice(0, 6), VERVE_RANGES) }
}

SODEXO_NO_LUHN = ->(num) { num =~ /^(505864|505865)\d{10}$/ }
Expand Down Expand Up @@ -251,6 +252,43 @@ module CreditCardMethods

PANAL_RANGES = [[602049]]

VERVE_RANGES = [
[506099],
[506101],
[506103],
(506111..506114),
[506116],
[506118],
[506124],
[506127],
[506130],
(506132..506139),
[506141],
[506144],
(506146..506152),
(506154..506161),
(506163..506164),
[506167],
(506169..506198),
(507865..507866),
(507868..507872),
(507874..507899),
(507901..507909),
(507911..507919),
[507921],
(507923..507925),
(507927..507962),
[507964],
[627309],
[627903],
[628051],
[636625],
[637058],
[637634],
[639245],
[639383]
]

def self.included(base)
base.extend(ClassMethods)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/rapyd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RapydGateway < Gateway

self.supported_countries = %w(CA CL CO DO SV PE PT VI AU HK IN ID JP MY NZ PH SG KR TW TH VN AD AT BE BA BG HR CY CZ DK EE FI FR GE DE GI GR GL HU IS IE IL IT LV LI LT LU MK MT MD MC ME NL GB NO PL RO RU SM SK SI ZA ES SE CH TR VA)
self.default_currency = 'USD'
self.supported_cardtypes = %i[visa master american_express discover]
self.supported_cardtypes = %i[visa master american_express discover verve]

self.homepage_url = 'https://www.rapyd.net/'
self.display_name = 'Rapyd Gateway'
Expand Down
33 changes: 33 additions & 0 deletions test/unit/credit_card_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,39 @@ def test_should_detect_panal_card
assert_equal 'panal', CreditCard.brand?('6020490000000000')
end

def test_detecting_full_range_of_verve_card_numbers
verve = '506099000000000'

assert_equal 15, verve.length
assert_not_equal 'verve', CreditCard.brand?(verve)

4.times do
verve << '0'
assert_equal 'verve', CreditCard.brand?(verve), "Failed for bin #{verve}"
end

assert_equal 19, verve.length

verve << '0'
assert_not_equal 'verve', CreditCard.brand?(verve)
end

def test_should_detect_verve
credit_cards = %w[5060990000000000
506112100000000000
5061351000000000000
5061591000000000
506175100000000000
5078801000000000000
5079381000000000
637058100000000000
5079400000000000000
507879000000000000
5061930000000000
506136000000000000]
credit_cards.all? { |cc| CreditCard.brand?(cc) == 'verve' }
end

def test_credit_card?
assert credit_card.credit_card?
end
Expand Down

0 comments on commit 2eeb3ab

Please sign in to comment.