activemerchant-kiddy 1.15.0.kiddy
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +688 -0
- data/CONTRIBUTORS +233 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +164 -0
- data/gem-public_cert.pem +20 -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 +172 -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/authorize_net.rb +671 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +139 -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/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -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/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +410 -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/orbital_soft_descriptors.rb +46 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +317 -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/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.rb +253 -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/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.rb +121 -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/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.rb +146 -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/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/gateways.rb +18 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -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/bogus.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/chronopay.rb +23 -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/direc_pay.rb +41 -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/directebanking.rb +47 -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/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/helper.rb +96 -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/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +48 -0
- data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
- data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -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/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -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/paypal.rb +39 -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/quickpay.rb +21 -0
- data/lib/active_merchant/billing/integrations/return.rb +42 -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/sage_pay_form.rb +37 -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/two_checkout.rb +23 -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 +88 -0
- data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor.rb +33 -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/integrations/world_pay.rb +38 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/billing.rb +9 -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/common.rb +14 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/active_merchant.rb +50 -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 +273 -0
@@ -0,0 +1,172 @@
|
|
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 verification_value?
|
84
|
+
!@verification_value.blank?
|
85
|
+
end
|
86
|
+
|
87
|
+
# Show the card number, with all but last 4 numbers replace with "X". (XXXX-XXXX-XXXX-4338)
|
88
|
+
def display_number
|
89
|
+
self.class.mask(number)
|
90
|
+
end
|
91
|
+
|
92
|
+
def last_digits
|
93
|
+
self.class.last_digits(number)
|
94
|
+
end
|
95
|
+
|
96
|
+
def validate
|
97
|
+
validate_essential_attributes
|
98
|
+
|
99
|
+
# Bogus card is pretty much for testing purposes. Lets just skip these extra tests if its used
|
100
|
+
return if type == 'bogus'
|
101
|
+
|
102
|
+
validate_card_type
|
103
|
+
validate_card_number
|
104
|
+
validate_verification_value
|
105
|
+
validate_switch_or_solo_attributes
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.requires_verification_value?
|
109
|
+
require_verification_value
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def before_validate #:nodoc:
|
115
|
+
self.month = month.to_i
|
116
|
+
self.year = year.to_i
|
117
|
+
self.start_month = start_month.to_i unless start_month.nil?
|
118
|
+
self.start_year = start_year.to_i unless start_year.nil?
|
119
|
+
self.number = number.to_s.gsub(/[^\d]/, "")
|
120
|
+
self.type.downcase! if type.respond_to?(:downcase)
|
121
|
+
self.type = self.class.type?(number) if type.blank?
|
122
|
+
end
|
123
|
+
|
124
|
+
def validate_card_number #:nodoc:
|
125
|
+
if number.blank?
|
126
|
+
errors.add :number, "is required"
|
127
|
+
elsif !CreditCard.valid_number?(number)
|
128
|
+
errors.add :number, "is not a valid credit card number"
|
129
|
+
end
|
130
|
+
|
131
|
+
unless errors.on(:number) || errors.on(:type)
|
132
|
+
errors.add :type, "is not the correct card type" unless CreditCard.matching_type?(number, type)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def validate_card_type #:nodoc:
|
137
|
+
errors.add :type, "is required" if type.blank? && number.present?
|
138
|
+
errors.add :type, "is invalid" unless type.blank? || CreditCard.card_companies.keys.include?(type)
|
139
|
+
end
|
140
|
+
|
141
|
+
def validate_essential_attributes #:nodoc:
|
142
|
+
errors.add :first_name, "cannot be empty" if @first_name.blank?
|
143
|
+
errors.add :last_name, "cannot be empty" if @last_name.blank?
|
144
|
+
|
145
|
+
if @month.to_i.zero? || @year.to_i.zero?
|
146
|
+
errors.add :month, "is required" if @month.to_i.zero?
|
147
|
+
errors.add :year, "is required" if @year.to_i.zero?
|
148
|
+
else
|
149
|
+
errors.add :month, "is not a valid month" unless valid_month?(@month)
|
150
|
+
errors.add :year, "expired" if expired?
|
151
|
+
errors.add :year, "is not a valid year" unless valid_expiry_year?(@year)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def validate_switch_or_solo_attributes #:nodoc:
|
156
|
+
if %w[switch solo].include?(type)
|
157
|
+
unless valid_month?(@start_month) && valid_start_year?(@start_year) || valid_issue_number?(@issue_number)
|
158
|
+
errors.add :start_month, "is invalid" unless valid_month?(@start_month)
|
159
|
+
errors.add :start_year, "is invalid" unless valid_start_year?(@start_year)
|
160
|
+
errors.add :issue_number, "cannot be empty" unless valid_issue_number?(@issue_number)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def validate_verification_value #:nodoc:
|
166
|
+
if CreditCard.requires_verification_value?
|
167
|
+
errors.add :verification_value, "is required" unless verification_value?
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveMerchant
|
2
|
+
module Billing
|
3
|
+
# Result of the Card Verification Value check
|
4
|
+
# http://www.bbbonline.org/eExport/doc/MerchantGuide_cvv2.pdf
|
5
|
+
# Check additional codes from cybersource website
|
6
|
+
class CVVResult
|
7
|
+
|
8
|
+
MESSAGES = {
|
9
|
+
'D' => 'Suspicious transaction',
|
10
|
+
'I' => 'Failed data validation check',
|
11
|
+
'M' => 'Match',
|
12
|
+
'N' => 'No Match',
|
13
|
+
'P' => 'Not Processed',
|
14
|
+
'S' => 'Should have been present',
|
15
|
+
'U' => 'Issuer unable to process request',
|
16
|
+
'X' => 'Card does not support verification'
|
17
|
+
}
|
18
|
+
|
19
|
+
def self.messages
|
20
|
+
MESSAGES
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :code, :message
|
24
|
+
|
25
|
+
def initialize(code)
|
26
|
+
@code = code.upcase unless code.blank?
|
27
|
+
@message = MESSAGES[@code]
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_hash
|
31
|
+
{
|
32
|
+
'code' => code,
|
33
|
+
'message' => message
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module ActiveMerchant
|
4
|
+
module Billing
|
5
|
+
class CreditCard
|
6
|
+
class ExpiryDate #:nodoc:
|
7
|
+
attr_reader :month, :year
|
8
|
+
def initialize(month, year)
|
9
|
+
@month = month.to_i
|
10
|
+
@year = year.to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
def expired? #:nodoc:
|
14
|
+
Time.now.utc > expiration
|
15
|
+
end
|
16
|
+
|
17
|
+
def expiration #:nodoc:
|
18
|
+
begin
|
19
|
+
Time.utc(year, month, month_days, 23, 59, 59)
|
20
|
+
rescue ArgumentError
|
21
|
+
Time.at(0).utc
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def month_days
|
27
|
+
mdays = [nil,31,28,31,30,31,30,31,31,30,31,30,31]
|
28
|
+
mdays[2] = 29 if Date.leap?(year)
|
29
|
+
mdays[month]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'active_merchant/billing/response'
|
4
|
+
|
5
|
+
module ActiveMerchant #:nodoc:
|
6
|
+
module Billing #:nodoc:
|
7
|
+
#
|
8
|
+
# == Description
|
9
|
+
# The Gateway class is the base class for all ActiveMerchant gateway implementations.
|
10
|
+
#
|
11
|
+
# The standard list of gateway functions that most concrete gateway subclasses implement is:
|
12
|
+
#
|
13
|
+
# * <tt>purchase(money, creditcard, options = {})</tt>
|
14
|
+
# * <tt>authorize(money, creditcard, options = {})</tt>
|
15
|
+
# * <tt>capture(money, authorization, options = {})</tt>
|
16
|
+
# * <tt>void(identification, options = {})</tt>
|
17
|
+
# * <tt>credit(money, identification, options = {})</tt>
|
18
|
+
#
|
19
|
+
# Some gateways include features for recurring billing
|
20
|
+
#
|
21
|
+
# * <tt>recurring(money, creditcard, options = {})</tt>
|
22
|
+
#
|
23
|
+
# Some gateways also support features for storing credit cards:
|
24
|
+
#
|
25
|
+
# * <tt>store(creditcard, options = {})</tt>
|
26
|
+
# * <tt>unstore(identification, options = {})</tt>
|
27
|
+
#
|
28
|
+
# === Gateway Options
|
29
|
+
# The options hash consists of the following options:
|
30
|
+
#
|
31
|
+
# * <tt>:order_id</tt> - The order number
|
32
|
+
# * <tt>:ip</tt> - The IP address of the customer making the purchase
|
33
|
+
# * <tt>:customer</tt> - The name, customer number, or other information that identifies the customer
|
34
|
+
# * <tt>:invoice</tt> - The invoice number
|
35
|
+
# * <tt>:merchant</tt> - The name or description of the merchant offering the product
|
36
|
+
# * <tt>:description</tt> - A description of the transaction
|
37
|
+
# * <tt>:email</tt> - The email address of the customer
|
38
|
+
# * <tt>:currency</tt> - The currency of the transaction. Only important when you are using a currency that is not the default with a gateway that supports multiple currencies.
|
39
|
+
# * <tt>:billing_address</tt> - A hash containing the billing address of the customer.
|
40
|
+
# * <tt>:shipping_address</tt> - A hash containing the shipping address of the customer.
|
41
|
+
#
|
42
|
+
# The <tt>:billing_address</tt>, and <tt>:shipping_address</tt> hashes can have the following keys:
|
43
|
+
#
|
44
|
+
# * <tt>:name</tt> - The full name of the customer.
|
45
|
+
# * <tt>:company</tt> - The company name of the customer.
|
46
|
+
# * <tt>:address1</tt> - The primary street address of the customer.
|
47
|
+
# * <tt>:address2</tt> - Additional line of address information.
|
48
|
+
# * <tt>:city</tt> - The city of the customer.
|
49
|
+
# * <tt>:state</tt> - The state of the customer. The 2 digit code for US and Canadian addresses. The full name of the state or province for foreign addresses.
|
50
|
+
# * <tt>:country</tt> - The [ISO 3166-1-alpha-2 code](http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm) for the customer.
|
51
|
+
# * <tt>:zip</tt> - The zip or postal code of the customer.
|
52
|
+
# * <tt>:phone</tt> - The phone number of the customer.
|
53
|
+
#
|
54
|
+
# == Implmenting new gateways
|
55
|
+
#
|
56
|
+
# See the {ActiveMerchant Guide to Contributing}[http://code.google.com/p/activemerchant/wiki/Contributing]
|
57
|
+
#
|
58
|
+
class Gateway
|
59
|
+
include PostsData
|
60
|
+
include RequiresParameters
|
61
|
+
include CreditCardFormatting
|
62
|
+
include Utils
|
63
|
+
|
64
|
+
DEBIT_CARDS = [ :switch, :solo ]
|
65
|
+
CURRENCIES_WITHOUT_FRACTIONS = [ 'JPY' ]
|
66
|
+
CREDIT_DEPRECATION_MESSAGE = "Support for using credit to refund existing transactions is deprecated and will be removed from a future release of ActiveMerchant. Please use the refund method instead."
|
67
|
+
|
68
|
+
cattr_reader :implementations
|
69
|
+
@@implementations = []
|
70
|
+
|
71
|
+
def self.inherited(subclass)
|
72
|
+
super
|
73
|
+
@@implementations << subclass
|
74
|
+
end
|
75
|
+
|
76
|
+
# The format of the amounts used by the gateway
|
77
|
+
# :dollars => '12.50'
|
78
|
+
# :cents => '1250'
|
79
|
+
class_attribute :money_format
|
80
|
+
self.money_format = :dollars
|
81
|
+
|
82
|
+
# The default currency for the transactions if no currency is provided
|
83
|
+
class_attribute :default_currency
|
84
|
+
|
85
|
+
# The countries of merchants the gateway supports
|
86
|
+
class_attribute :supported_countries
|
87
|
+
self.supported_countries = []
|
88
|
+
|
89
|
+
# The supported card types for the gateway
|
90
|
+
class_attribute :supported_cardtypes
|
91
|
+
self.supported_cardtypes = []
|
92
|
+
|
93
|
+
class_attribute :homepage_url
|
94
|
+
class_attribute :display_name
|
95
|
+
|
96
|
+
# The application making the calls to the gateway
|
97
|
+
# Useful for things like the PayPal build notation (BN) id fields
|
98
|
+
superclass_delegating_accessor :application_id
|
99
|
+
self.application_id = 'ActiveMerchant'
|
100
|
+
|
101
|
+
attr_reader :options
|
102
|
+
|
103
|
+
# Use this method to check if your gateway of interest supports a credit card of some type
|
104
|
+
def self.supports?(card_type)
|
105
|
+
supported_cardtypes.include?(card_type.to_sym)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.card_brand(source)
|
109
|
+
result = source.respond_to?(:brand) ? source.brand : source.type
|
110
|
+
result.to_s.downcase
|
111
|
+
end
|
112
|
+
|
113
|
+
def card_brand(source)
|
114
|
+
self.class.card_brand(source)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Initialize a new gateway.
|
118
|
+
#
|
119
|
+
# See the documentation for the gateway you will be using to make sure there are no other
|
120
|
+
# required options.
|
121
|
+
def initialize(options = {})
|
122
|
+
end
|
123
|
+
|
124
|
+
# Are we running in test mode?
|
125
|
+
def test?
|
126
|
+
Base.gateway_mode == :test
|
127
|
+
end
|
128
|
+
|
129
|
+
private # :nodoc: all
|
130
|
+
|
131
|
+
def name
|
132
|
+
self.class.name.scan(/\:\:(\w+)Gateway/).flatten.first
|
133
|
+
end
|
134
|
+
|
135
|
+
def amount(money)
|
136
|
+
return nil if money.nil?
|
137
|
+
cents = if money.respond_to?(:cents)
|
138
|
+
deprecated "Support for Money objects is deprecated and will be removed from a future release of ActiveMerchant. Please use an Integer value in cents"
|
139
|
+
money.cents
|
140
|
+
else
|
141
|
+
money
|
142
|
+
end
|
143
|
+
|
144
|
+
if money.is_a?(String)
|
145
|
+
raise ArgumentError, 'money amount must be a positive Integer in cents.'
|
146
|
+
end
|
147
|
+
|
148
|
+
if self.money_format == :cents
|
149
|
+
cents.to_s
|
150
|
+
else
|
151
|
+
sprintf("%.2f", cents.to_f / 100)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def localized_amount(money, currency)
|
156
|
+
amount = amount(money)
|
157
|
+
CURRENCIES_WITHOUT_FRACTIONS.include?(currency.to_s) ? amount.split('.').first : amount
|
158
|
+
end
|
159
|
+
|
160
|
+
def currency(money)
|
161
|
+
money.respond_to?(:currency) ? money.currency : self.default_currency
|
162
|
+
end
|
163
|
+
|
164
|
+
def requires_start_date_or_issue_number?(credit_card)
|
165
|
+
return false if card_brand(credit_card).blank?
|
166
|
+
DEBIT_CARDS.include?(card_brand(credit_card).to_sym)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|