Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into try_update_from_o…
Browse files Browse the repository at this point in the history
…riginal
  • Loading branch information
Ligator committed Oct 16, 2023
2 parents 927278c + f2e44d3 commit e19e7c4
Show file tree
Hide file tree
Showing 341 changed files with 35,725 additions and 2,754 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ruby-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
strategy:
matrix:
version:
- 2.5
- 2.6
- 2.7
gemfile:
- gemfiles/Gemfile.rails50
Expand All @@ -42,3 +40,5 @@ jobs:

- name: Test
run: bundle exec rake test
- name: Linter
run: bundle exec rubocop
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AllCops:
- "lib/active_merchant/billing/gateways/paypal_express.rb"
- "vendor/**/*"
ExtraDetails: false
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7

# Active Merchant gateways are not amenable to length restrictions
Metrics/ClassLength:
Expand All @@ -33,7 +33,7 @@ Layout/DotPosition:
Layout/CaseIndentation:
EnforcedStyle: end

Layout/IndentHash:
Layout/IndentFirstHashElement:
EnforcedStyle: consistent

Naming/PredicateName:
Expand Down
345 changes: 345 additions & 0 deletions CHANGELOG

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ source 'https://rubygems.org'
gemspec

gem 'jruby-openssl', platforms: :jruby
gem 'rubocop', '~> 0.62.0', require: false
gem 'rubocop', '~> 0.72.0', require: false

group :test, :remote_test do
# gateway-specific dependencies, keeping these gems out of the gemspec
gem 'braintree', '>= 3.0.0', '<= 3.0.1'
gem 'braintree', '>= 4.14.0'
gem 'jose', '~> 1.1.3'
gem 'jwe'
gem 'mechanize'
gem 'timecop'
end
3 changes: 2 additions & 1 deletion activemerchant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.email = '[email protected]'
s.homepage = 'http://activemerchant.org/'

s.required_ruby_version = '>= 2.5'
s.required_ruby_version = '>= 2.7'

s.files = Dir['CHANGELOG', 'README.md', 'MIT-LICENSE', 'CONTRIBUTORS', 'lib/**/*', 'vendor/**/*']
s.require_path = 'lib'
Expand All @@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_dependency('builder', '>= 2.1.2', '< 4.0.0')
s.add_dependency('i18n', '>= 0.6.9')
s.add_dependency('nokogiri', '~> 1.4')
s.add_dependency('rexml', '~> 3.2.5')

s.add_development_dependency('mocha', '~> 1')
s.add_development_dependency('pry')
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
ruby:
version: '2.5.0'
version: '2.7.0'

dependencies:
cache_directories:
Expand Down
52 changes: 42 additions & 10 deletions lib/active_merchant/billing/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Billing #:nodoc:
# You may use Check in place of CreditCard with any gateway that supports it.
class Check < Model
attr_accessor :first_name, :last_name,
:bank_name, :routing_number, :account_number,
:account_holder_type, :account_type, :number
:bank_name, :routing_number, :account_number,
:account_holder_type, :account_type, :number

# Used for Canadian bank accounts
attr_accessor :institution_number, :transit_number
Expand All @@ -20,7 +20,7 @@ class Check < Model
309 310 315 320 338 340 509 540 608 614 623 809 815 819 828 829 837 839
865 879 889 899 241 242 248 250 265 275 277 290 294 301 303 307 311 314
321 323 327 328 330 332 334 335 342 343 346 352 355 361 362 366 370 372
376 378 807 853 890
376 378 807 853 890 618 842
)

def name
Expand Down Expand Up @@ -60,20 +60,52 @@ def credit_card?
false
end

def valid_routing_number?
digits = routing_number.to_s.split('').map(&:to_i).select { |d| (0..9).cover?(d) }
case digits.size
when 9
return checksum(digits) == 0 || CAN_INSTITUTION_NUMBERS.include?(routing_number[1..3])
when 8
return CAN_INSTITUTION_NUMBERS.include?(routing_number[5..7])
end

false
end

# Routing numbers may be validated by calculating a checksum and dividing it by 10. The
# formula is:
# (3(d1 + d4 + d7) + 7(d2 + d5 + d8) + 1(d3 + d6 + d9))mod 10 = 0
# See http://en.wikipedia.org/wiki/Routing_transit_number#Internal_checksums
def valid_routing_number?
def checksum(digits)
((3 * (digits[0] + digits[3] + digits[6])) +
(7 * (digits[1] + digits[4] + digits[7])) +
(digits[2] + digits[5] + digits[8])) % 10
end

# Always return MICR-formatted routing number for Canadian routing numbers, US routing numbers unchanged
def micr_format_routing_number
digits = routing_number.to_s.split('').map(&:to_i).select { |d| (0..9).cover?(d) }
if digits.size == 9
checksum = ((3 * (digits[0] + digits[3] + digits[6])) +
(7 * (digits[1] + digits[4] + digits[7])) +
(digits[2] + digits[5] + digits[8])) % 10
case digits.size
when 9
if checksum(digits) == 0
return routing_number
else
return routing_number[4..8] + routing_number[1..3]
end
when 8
return routing_number
end
end

return checksum == 0 || CAN_INSTITUTION_NUMBERS.include?(routing_number[1..3])
# Always return electronic-formatted routing number for Canadian routing numbers, US routing numbers unchanged
def electronic_format_routing_number
digits = routing_number.to_s.split('').map(&:to_i).select { |d| (0..9).cover?(d) }
case digits.size
when 9
return routing_number
when 8
return '0' + routing_number[5..7] + routing_number[0..4]
end
false
end
end
end
Expand Down
33 changes: 32 additions & 1 deletion lib/active_merchant/billing/credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ module Billing #:nodoc:
# * Olimpica
# * Creditel
# * Confiable
# * Mada
# * BpPlus
# * Passcard
# * Edenred
# * 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 @@ -61,6 +69,8 @@ module Billing #:nodoc:
class CreditCard < Model
include CreditCardMethods

BRANDS_WITH_SPACES_IN_NUMBER = %w(bp_plus)

class << self
# Inherited, but can be overridden w/o changing parent's value
attr_accessor :require_verification_value
Expand All @@ -76,7 +86,7 @@ class << self
attr_reader :number

def number=(value)
@number = (empty?(value) ? value : value.to_s.gsub(/[^\d]/, ''))
@number = (empty?(value) ? value : filter_number(value))
end

# Returns or sets the expiry month for the card.
Expand Down Expand Up @@ -116,6 +126,14 @@ def number=(value)
# * +'olimpica'+
# * +'creditel'+
# * +'confiable'+
# * +'mada'+
# * +'bp_plus'+
# * +'passcard'+
# * +'edenred'+
# * +'anda'+
# * +'tarjeta-d'+
# * +'panal'+
# * +'verve'+
#
# Or, if you wish to test your implementation, +'bogus'+.
#
Expand Down Expand Up @@ -337,8 +355,21 @@ def emv?
icc_data.present?
end

def allow_spaces_in_card?(number = nil)
BRANDS_WITH_SPACES_IN_NUMBER.include?(self.class.brand?(self.number || number))
end

private

def filter_number(value)
regex = if allow_spaces_in_card?(value)
/[^\d ]/
else
/[^\d]/
end
value.to_s.gsub(regex, '')
end

def validate_essential_attributes #:nodoc:
errors = []

Expand Down
Loading

0 comments on commit e19e7c4

Please sign in to comment.