gonow-activemerchant 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +690 -0
- data/CONTRIBUTORS +237 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +165 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +47 -0
- data/lib/active_merchant/billing.rb +9 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +57 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +178 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +170 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +664 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +132 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
- data/lib/active_merchant/billing/gateways/braspag.rb +188 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/epay.rb +268 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
- data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +321 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +218 -0
- data/lib/active_merchant/billing/gateways/realex.rb +311 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +212 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +25 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
- data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
- data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
- data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
- data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
- data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
- data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
- data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
- data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/helper.rb +96 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
- data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/return.rb +42 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
- data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
- data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
- data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
- data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
- data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/common.rb +14 -0
- data/lib/active_merchant/common/connection.rb +177 -0
- data/lib/active_merchant/common/country.rb +328 -0
- data/lib/active_merchant/common/error.rb +26 -0
- data/lib/active_merchant/common/post_data.rb +24 -0
- data/lib/active_merchant/common/posts_data.rb +63 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +22 -0
- data/lib/active_merchant/common/validateable.rb +81 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +276 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_merchant/billing/avs_result'
|
2
|
+
require 'active_merchant/billing/cvv_result'
|
3
|
+
require 'active_merchant/billing/credit_card_methods'
|
4
|
+
require 'active_merchant/billing/credit_card_formatting'
|
5
|
+
require 'active_merchant/billing/credit_card'
|
6
|
+
require 'active_merchant/billing/base'
|
7
|
+
require 'active_merchant/billing/check'
|
8
|
+
require 'active_merchant/billing/response'
|
9
|
+
require 'active_merchant/billing/gateways'
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#!ruby19
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module ActiveMerchant
|
5
|
+
module Billing
|
6
|
+
# Implements the Address Verification System
|
7
|
+
# https://www.wellsfargo.com/downloads/pdf/biz/merchant/visa_avs.pdf
|
8
|
+
# http://en.wikipedia.org/wiki/Address_Verification_System
|
9
|
+
# http://apps.cybersource.com/library/documentation/dev_guides/CC_Svcs_IG/html/app_avs_cvn_codes.htm#app_AVS_CVN_codes_7891_48375
|
10
|
+
# http://imgserver.skipjack.com/imgServer/5293710/AVS%20and%20CVV2.pdf
|
11
|
+
# http://www.emsecommerce.net/avs_cvv2_response_codes.htm
|
12
|
+
class AVSResult
|
13
|
+
MESSAGES = {
|
14
|
+
'A' => 'Street address matches, but 5-digit and 9-digit postal code do not match.',
|
15
|
+
'B' => 'Street address matches, but postal code not verified.',
|
16
|
+
'C' => 'Street address and postal code do not match.',
|
17
|
+
'D' => 'Street address and postal code match.',
|
18
|
+
'E' => 'AVS data is invalid or AVS is not allowed for this card type.',
|
19
|
+
'F' => 'Card member\'s name does not match, but billing postal code matches.',
|
20
|
+
'G' => 'Non-U.S. issuing bank does not support AVS.',
|
21
|
+
'H' => 'Card member\'s name does not match. Street address and postal code match.',
|
22
|
+
'I' => 'Address not verified.',
|
23
|
+
'J' => 'Card member\'s name, billing address, and postal code match. Shipping information verified and chargeback protection guaranteed through the Fraud Protection Program.',
|
24
|
+
'K' => 'Card member\'s name matches but billing address and billing postal code do not match.',
|
25
|
+
'L' => 'Card member\'s name and billing postal code match, but billing address does not match.',
|
26
|
+
'M' => 'Street address and postal code match.',
|
27
|
+
'N' => 'Street address and postal code do not match.',
|
28
|
+
'O' => 'Card member\'s name and billing address match, but billing postal code does not match.',
|
29
|
+
'P' => 'Postal code matches, but street address not verified.',
|
30
|
+
'Q' => 'Card member\'s name, billing address, and postal code match. Shipping information verified but chargeback protection not guaranteed.',
|
31
|
+
'R' => 'System unavailable.',
|
32
|
+
'S' => 'U.S.-issuing bank does not support AVS.',
|
33
|
+
'T' => 'Card member\'s name does not match, but street address matches.',
|
34
|
+
'U' => 'Address information unavailable.',
|
35
|
+
'V' => 'Card member\'s name, billing address, and billing postal code match.',
|
36
|
+
'W' => 'Street address does not match, but 9-digit postal code matches.',
|
37
|
+
'X' => 'Street address and 9-digit postal code match.',
|
38
|
+
'Y' => 'Street address and 5-digit postal code match.',
|
39
|
+
'Z' => 'Street address does not match, but 5-digit postal code matches.'
|
40
|
+
}
|
41
|
+
|
42
|
+
# Map vendor's AVS result code to a postal match code
|
43
|
+
POSTAL_MATCH_CODE = {
|
44
|
+
'Y' => %w( D H F H J L M P Q V W X Y Z ),
|
45
|
+
'N' => %w( A C K N O ),
|
46
|
+
'X' => %w( G S ),
|
47
|
+
nil => %w( B E I R T U )
|
48
|
+
}.inject({}) do |map, (type, codes)|
|
49
|
+
codes.each { |code| map[code] = type }
|
50
|
+
map
|
51
|
+
end
|
52
|
+
|
53
|
+
# Map vendor's AVS result code to a street match code
|
54
|
+
STREET_MATCH_CODE = {
|
55
|
+
'Y' => %w( A B D H J M O Q T V X Y ),
|
56
|
+
'N' => %w( C K L N W Z ),
|
57
|
+
'X' => %w( G S ),
|
58
|
+
nil => %w( E F I P R U )
|
59
|
+
}.inject({}) do |map, (type, codes)|
|
60
|
+
codes.each { |code| map[code] = type }
|
61
|
+
map
|
62
|
+
end
|
63
|
+
|
64
|
+
attr_reader :code, :message, :street_match, :postal_match
|
65
|
+
|
66
|
+
def self.messages
|
67
|
+
MESSAGES
|
68
|
+
end
|
69
|
+
|
70
|
+
def initialize(attrs)
|
71
|
+
attrs ||= {}
|
72
|
+
|
73
|
+
@code = attrs[:code].upcase unless attrs[:code].blank?
|
74
|
+
@message = self.class.messages[code]
|
75
|
+
|
76
|
+
if attrs[:street_match].blank?
|
77
|
+
@street_match = STREET_MATCH_CODE[code]
|
78
|
+
else
|
79
|
+
@street_match = attrs[:street_match].upcase
|
80
|
+
end
|
81
|
+
|
82
|
+
if attrs[:postal_match].blank?
|
83
|
+
@postal_match = POSTAL_MATCH_CODE[code]
|
84
|
+
else
|
85
|
+
@postal_match = attrs[:postal_match].upcase
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_hash
|
90
|
+
{ 'code' => code,
|
91
|
+
'message' => message,
|
92
|
+
'street_match' => street_match,
|
93
|
+
'postal_match' => postal_match
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module Base
|
4
|
+
# Set ActiveMerchant gateways in test mode.
|
5
|
+
#
|
6
|
+
# ActiveMerchant::Billing::Base.gateway_mode = :test
|
7
|
+
mattr_accessor :gateway_mode
|
8
|
+
|
9
|
+
# Set ActiveMerchant integrations in test mode.
|
10
|
+
#
|
11
|
+
# ActiveMerchant::Billing::Base.integration_mode = :test
|
12
|
+
mattr_accessor :integration_mode
|
13
|
+
|
14
|
+
# Set both the mode of both the gateways and integrations
|
15
|
+
# at once
|
16
|
+
mattr_reader :mode
|
17
|
+
|
18
|
+
def self.mode=(mode)
|
19
|
+
@@mode = mode
|
20
|
+
self.gateway_mode = mode
|
21
|
+
self.integration_mode = mode
|
22
|
+
end
|
23
|
+
|
24
|
+
self.mode = :production
|
25
|
+
|
26
|
+
# Return the matching gateway for the provider
|
27
|
+
# * <tt>bogus</tt>: BogusGateway - Does nothing (for testing)
|
28
|
+
# * <tt>moneris</tt>: MonerisGateway
|
29
|
+
# * <tt>authorize_net</tt>: AuthorizeNetGateway
|
30
|
+
# * <tt>trust_commerce</tt>: TrustCommerceGateway
|
31
|
+
#
|
32
|
+
# ActiveMerchant::Billing::Base.gateway('moneris').new
|
33
|
+
def self.gateway(name)
|
34
|
+
Billing.const_get("#{name.to_s.downcase}_gateway".camelize)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Return the matching integration module
|
39
|
+
# You can then get the notification from the module
|
40
|
+
# * <tt>bogus</tt>: Bogus - Does nothing (for testing)
|
41
|
+
# * <tt>chronopay</tt>: Chronopay - Does nothing (for testing)
|
42
|
+
# * <tt>paypal</tt>: Chronopay - Does nothing (for testing)
|
43
|
+
#
|
44
|
+
# chronopay = ActiveMerchant::Billing::Base.integration('chronopay')
|
45
|
+
# notification = chronopay.notification(raw_post)
|
46
|
+
#
|
47
|
+
def self.integration(name)
|
48
|
+
Billing::Integrations.const_get("#{name.to_s.downcase}".camelize)
|
49
|
+
end
|
50
|
+
|
51
|
+
# A check to see if we're in test mode
|
52
|
+
def self.test?
|
53
|
+
self.gateway_mode == :test
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# The Check object is a plain old Ruby object, similar to CreditCard. It supports validation
|
4
|
+
# of necessary attributes such as checkholder's name, routing and account numbers, but it is
|
5
|
+
# not backed by any database.
|
6
|
+
#
|
7
|
+
# You may use Check in place of CreditCard with any gateway that supports it. Currently, only
|
8
|
+
# +BraintreeGateway+ supports the Check object.
|
9
|
+
class Check
|
10
|
+
include Validateable
|
11
|
+
|
12
|
+
attr_accessor :first_name, :last_name, :routing_number, :account_number, :account_holder_type, :account_type, :number
|
13
|
+
|
14
|
+
# Used for Canadian bank accounts
|
15
|
+
attr_accessor :institution_number, :transit_number
|
16
|
+
|
17
|
+
def name
|
18
|
+
@name ||= "#{@first_name} #{@last_name}".strip
|
19
|
+
end
|
20
|
+
|
21
|
+
def name=(value)
|
22
|
+
return if value.blank?
|
23
|
+
|
24
|
+
@name = value
|
25
|
+
segments = value.split(' ')
|
26
|
+
@last_name = segments.pop
|
27
|
+
@first_name = segments.join(' ')
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate
|
31
|
+
[:name, :routing_number, :account_number].each do |attr|
|
32
|
+
errors.add(attr, "cannot be empty") if self.send(attr).blank?
|
33
|
+
end
|
34
|
+
|
35
|
+
errors.add(:routing_number, "is invalid") unless valid_routing_number?
|
36
|
+
|
37
|
+
errors.add(:account_holder_type, "must be personal or business") if
|
38
|
+
!account_holder_type.blank? && !%w[business personal].include?(account_holder_type.to_s)
|
39
|
+
|
40
|
+
errors.add(:account_type, "must be checking or savings") if
|
41
|
+
!account_type.blank? && !%w[checking savings].include?(account_type.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
def type
|
45
|
+
'check'
|
46
|
+
end
|
47
|
+
|
48
|
+
# Routing numbers may be validated by calculating a checksum and dividing it by 10. The
|
49
|
+
# formula is:
|
50
|
+
# (3(d1 + d4 + d7) + 7(d2 + d5 + d8) + 1(d3 + d6 + d9))mod 10 = 0
|
51
|
+
# See http://en.wikipedia.org/wiki/Routing_transit_number#Internal_checksums
|
52
|
+
def valid_routing_number?
|
53
|
+
d = routing_number.to_s.split('').map(&:to_i).select { |d| (0..9).include?(d) }
|
54
|
+
case d.size
|
55
|
+
when 9 then
|
56
|
+
checksum = ((3 * (d[0] + d[3] + d[6])) +
|
57
|
+
(7 * (d[1] + d[4] + d[7])) +
|
58
|
+
(d[2] + d[5] + d[8])) % 10
|
59
|
+
case checksum
|
60
|
+
when 0 then true
|
61
|
+
else false
|
62
|
+
end
|
63
|
+
else false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'date'
|
3
|
+
require 'active_merchant/billing/expiry_date'
|
4
|
+
|
5
|
+
module ActiveMerchant #:nodoc:
|
6
|
+
module Billing #:nodoc:
|
7
|
+
# == Description
|
8
|
+
# This credit card object can be used as a stand alone object. It acts just like an ActiveRecord object
|
9
|
+
# but doesn't support the .save method as its not backed by a database.
|
10
|
+
#
|
11
|
+
# For testing purposes, use the 'bogus' credit card type. This card skips the vast majority of
|
12
|
+
# validations. This allows you to focus on your core concerns until you're ready to be more concerned
|
13
|
+
# with the details of particular creditcards or your gateway.
|
14
|
+
#
|
15
|
+
# == Testing With CreditCard
|
16
|
+
# Often when testing we don't care about the particulars of a given card type. When using the 'test'
|
17
|
+
# mode in your Gateway, there are six different valid card numbers: 1, 2, 3, 'success', 'fail',
|
18
|
+
# and 'error'.
|
19
|
+
#
|
20
|
+
#--
|
21
|
+
# For details, see CreditCardMethods#valid_number?
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
# == Example Usage
|
25
|
+
# cc = CreditCard.new(
|
26
|
+
# :first_name => 'Steve',
|
27
|
+
# :last_name => 'Smith',
|
28
|
+
# :month => '9',
|
29
|
+
# :year => '2010',
|
30
|
+
# :type => 'visa',
|
31
|
+
# :number => '4242424242424242'
|
32
|
+
# )
|
33
|
+
#
|
34
|
+
# cc.valid? # => true
|
35
|
+
# cc.display_number # => XXXX-XXXX-XXXX-4242
|
36
|
+
#
|
37
|
+
class CreditCard
|
38
|
+
include CreditCardMethods
|
39
|
+
include Validateable
|
40
|
+
|
41
|
+
## Attributes
|
42
|
+
|
43
|
+
cattr_accessor :require_verification_value
|
44
|
+
self.require_verification_value = true
|
45
|
+
|
46
|
+
# Essential attributes for a valid, non-bogus creditcards
|
47
|
+
attr_accessor :number, :month, :year, :type, :first_name, :last_name
|
48
|
+
|
49
|
+
# Required for Switch / Solo cards
|
50
|
+
attr_accessor :start_month, :start_year, :issue_number
|
51
|
+
|
52
|
+
# Optional verification_value (CVV, CVV2 etc). Gateways will try their best to
|
53
|
+
# run validation on the passed in value if it is supplied
|
54
|
+
attr_accessor :verification_value
|
55
|
+
|
56
|
+
alias_method :brand, :type
|
57
|
+
|
58
|
+
# Provides proxy access to an expiry date object
|
59
|
+
def expiry_date
|
60
|
+
ExpiryDate.new(@month, @year)
|
61
|
+
end
|
62
|
+
|
63
|
+
def expired?
|
64
|
+
expiry_date.expired?
|
65
|
+
end
|
66
|
+
|
67
|
+
def name?
|
68
|
+
first_name? || last_name?
|
69
|
+
end
|
70
|
+
|
71
|
+
def first_name?
|
72
|
+
@first_name.present?
|
73
|
+
end
|
74
|
+
|
75
|
+
def last_name?
|
76
|
+
@last_name.present?
|
77
|
+
end
|
78
|
+
|
79
|
+
def name
|
80
|
+
[@first_name, @last_name].compact.join(' ')
|
81
|
+
end
|
82
|
+
|
83
|
+
def name=(full_name)
|
84
|
+
names = full_name.split
|
85
|
+
self.last_name = names.pop
|
86
|
+
self.first_name = names.join(" ")
|
87
|
+
end
|
88
|
+
|
89
|
+
def verification_value?
|
90
|
+
!@verification_value.blank?
|
91
|
+
end
|
92
|
+
|
93
|
+
# Show the card number, with all but last 4 numbers replace with "X". (XXXX-XXXX-XXXX-4338)
|
94
|
+
def display_number
|
95
|
+
self.class.mask(number)
|
96
|
+
end
|
97
|
+
|
98
|
+
def last_digits
|
99
|
+
self.class.last_digits(number)
|
100
|
+
end
|
101
|
+
|
102
|
+
def validate
|
103
|
+
validate_essential_attributes
|
104
|
+
|
105
|
+
# Bogus card is pretty much for testing purposes. Lets just skip these extra tests if its used
|
106
|
+
return if type == 'bogus'
|
107
|
+
|
108
|
+
validate_card_type
|
109
|
+
validate_card_number
|
110
|
+
validate_verification_value
|
111
|
+
validate_switch_or_solo_attributes
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.requires_verification_value?
|
115
|
+
require_verification_value
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def before_validate #:nodoc:
|
121
|
+
self.month = month.to_i
|
122
|
+
self.year = year.to_i
|
123
|
+
self.start_month = start_month.to_i unless start_month.nil?
|
124
|
+
self.start_year = start_year.to_i unless start_year.nil?
|
125
|
+
self.number = number.to_s.gsub(/[^\d]/, "")
|
126
|
+
self.type.downcase! if type.respond_to?(:downcase)
|
127
|
+
self.type = self.class.type?(number) if type.blank?
|
128
|
+
end
|
129
|
+
|
130
|
+
def validate_card_number #:nodoc:
|
131
|
+
if number.blank?
|
132
|
+
errors.add :number, "is required"
|
133
|
+
elsif !CreditCard.valid_number?(number)
|
134
|
+
errors.add :number, "is not a valid credit card number"
|
135
|
+
end
|
136
|
+
|
137
|
+
unless errors.on(:number) || errors.on(:type)
|
138
|
+
errors.add :type, "is not the correct card type" unless CreditCard.matching_type?(number, type)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def validate_card_type #:nodoc:
|
143
|
+
errors.add :type, "is required" if type.blank? && number.present?
|
144
|
+
errors.add :type, "is invalid" unless type.blank? || CreditCard.card_companies.keys.include?(type)
|
145
|
+
end
|
146
|
+
|
147
|
+
def validate_essential_attributes #:nodoc:
|
148
|
+
errors.add :first_name, "cannot be empty" if @first_name.blank?
|
149
|
+
errors.add :last_name, "cannot be empty" if @last_name.blank?
|
150
|
+
|
151
|
+
if @month.to_i.zero? || @year.to_i.zero?
|
152
|
+
errors.add :month, "is required" if @month.to_i.zero?
|
153
|
+
errors.add :year, "is required" if @year.to_i.zero?
|
154
|
+
else
|
155
|
+
errors.add :month, "is not a valid month" unless valid_month?(@month)
|
156
|
+
errors.add :year, "expired" if expired?
|
157
|
+
errors.add :year, "is not a valid year" unless valid_expiry_year?(@year)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def validate_switch_or_solo_attributes #:nodoc:
|
162
|
+
if %w[switch solo].include?(type)
|
163
|
+
unless valid_month?(@start_month) && valid_start_year?(@start_year) || valid_issue_number?(@issue_number)
|
164
|
+
errors.add :start_month, "is invalid" unless valid_month?(@start_month)
|
165
|
+
errors.add :start_year, "is invalid" unless valid_start_year?(@start_year)
|
166
|
+
errors.add :issue_number, "cannot be empty" unless valid_issue_number?(@issue_number)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def validate_verification_value #:nodoc:
|
172
|
+
if CreditCard.requires_verification_value?
|
173
|
+
errors.add :verification_value, "is required" unless verification_value?
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module CreditCardFormatting
|
4
|
+
|
5
|
+
# This method is used to format numerical information pertaining to credit cards.
|
6
|
+
#
|
7
|
+
# format(2005, :two_digits) # => "05"
|
8
|
+
# format(05, :four_digits) # => "0005"
|
9
|
+
def format(number, option)
|
10
|
+
return '' if number.blank?
|
11
|
+
|
12
|
+
case option
|
13
|
+
when :two_digits ; sprintf("%.2i", number)[-2..-1]
|
14
|
+
when :four_digits ; sprintf("%.4i", number)[-4..-1]
|
15
|
+
else number
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# Convenience methods that can be included into a custom Credit Card object, such as an ActiveRecord based Credit Card object.
|
4
|
+
module CreditCardMethods
|
5
|
+
CARD_COMPANIES = {
|
6
|
+
'visa' => /^4\d{12}(\d{3})?$/,
|
7
|
+
'master' => /^(5[1-5]\d{4}|677189)\d{10}$/,
|
8
|
+
'discover' => /^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/,
|
9
|
+
'american_express' => /^3[47]\d{13}$/,
|
10
|
+
'diners_club' => /^3(0[0-5]|[68]\d)\d{11}$/,
|
11
|
+
'jcb' => /^35(28|29|[3-8]\d)\d{12}$/,
|
12
|
+
'switch' => /^6759\d{12}(\d{2,3})?$/,
|
13
|
+
'solo' => /^6767\d{12}(\d{2,3})?$/,
|
14
|
+
'dankort' => /^5019\d{12}$/,
|
15
|
+
'maestro' => /^(5[06-8]|6\d)\d{10,17}$/,
|
16
|
+
'forbrugsforeningen' => /^600722\d{10}$/,
|
17
|
+
'laser' => /^(6304|6706|6771|6709)\d{8}(\d{4}|\d{6,7})?$/
|
18
|
+
}
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.extend(ClassMethods)
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_month?(month)
|
25
|
+
(1..12).include?(month.to_i)
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_expiry_year?(year)
|
29
|
+
(Time.now.year..Time.now.year + 20).include?(year.to_i)
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_start_year?(year)
|
33
|
+
year.to_s =~ /^\d{4}$/ && year.to_i > 1987
|
34
|
+
end
|
35
|
+
|
36
|
+
def valid_issue_number?(number)
|
37
|
+
number.to_s =~ /^\d{1,2}$/
|
38
|
+
end
|
39
|
+
|
40
|
+
module ClassMethods
|
41
|
+
# Returns true if it validates. Optionally, you can pass a card type as an argument and
|
42
|
+
# make sure it is of the correct type.
|
43
|
+
#
|
44
|
+
# References:
|
45
|
+
# - http://perl.about.com/compute/perl/library/nosearch/P073000.htm
|
46
|
+
# - http://www.beachnet.com/~hstiles/cardtype.html
|
47
|
+
def valid_number?(number)
|
48
|
+
valid_test_mode_card_number?(number) ||
|
49
|
+
valid_card_number_length?(number) &&
|
50
|
+
valid_checksum?(number)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Regular expressions for the known card companies.
|
54
|
+
#
|
55
|
+
# References:
|
56
|
+
# - http://en.wikipedia.org/wiki/Credit_card_number
|
57
|
+
# - http://www.barclaycardbusiness.co.uk/information_zone/processing/bin_rules.html
|
58
|
+
def card_companies
|
59
|
+
CARD_COMPANIES
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns a string containing the type of card from the list of known information below.
|
63
|
+
# Need to check the cards in a particular order, as there is some overlap of the allowable ranges
|
64
|
+
#--
|
65
|
+
# TODO Refactor this method. We basically need to tighten up the Maestro Regexp.
|
66
|
+
#
|
67
|
+
# Right now the Maestro regexp overlaps with the MasterCard regexp (IIRC). If we can tighten
|
68
|
+
# things up, we can boil this whole thing down to something like...
|
69
|
+
#
|
70
|
+
# def type?(number)
|
71
|
+
# return 'visa' if valid_test_mode_card_number?(number)
|
72
|
+
# card_companies.find([nil]) { |type, regexp| number =~ regexp }.first.dup
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
def type?(number)
|
76
|
+
return 'bogus' if valid_test_mode_card_number?(number)
|
77
|
+
|
78
|
+
card_companies.reject { |c,p| c == 'maestro' }.each do |company, pattern|
|
79
|
+
return company.dup if number =~ pattern
|
80
|
+
end
|
81
|
+
|
82
|
+
return 'maestro' if number =~ card_companies['maestro']
|
83
|
+
|
84
|
+
return nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def last_digits(number)
|
88
|
+
number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1)
|
89
|
+
end
|
90
|
+
|
91
|
+
def mask(number)
|
92
|
+
"XXXX-XXXX-XXXX-#{last_digits(number)}"
|
93
|
+
end
|
94
|
+
|
95
|
+
# Checks to see if the calculated type matches the specified type
|
96
|
+
def matching_type?(number, type)
|
97
|
+
type?(number) == type
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def valid_card_number_length?(number) #:nodoc:
|
103
|
+
number.to_s.length >= 12
|
104
|
+
end
|
105
|
+
|
106
|
+
def valid_test_mode_card_number?(number) #:nodoc:
|
107
|
+
ActiveMerchant::Billing::Base.test? &&
|
108
|
+
%w[1 2 3 success failure error].include?(number.to_s)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Checks the validity of a card number by use of the the Luhn Algorithm.
|
112
|
+
# Please see http://en.wikipedia.org/wiki/Luhn_algorithm for details.
|
113
|
+
def valid_checksum?(number) #:nodoc:
|
114
|
+
sum = 0
|
115
|
+
for i in 0..number.length
|
116
|
+
weight = number[-1 * (i + 2), 1].to_i * (2 - (i % 2))
|
117
|
+
sum += (weight < 10) ? weight : weight - 9
|
118
|
+
end
|
119
|
+
|
120
|
+
(number[-1,1].to_i == (10 - sum % 10) % 10)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|