activemerchant 1.2.1 → 1.3.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.tar.gz.sig +0 -0
- data/CHANGELOG +310 -294
- data/CONTRIBUTERS +13 -0
- data/README +55 -31
- data/Rakefile +21 -13
- data/lib/active_merchant.rb +7 -0
- data/lib/active_merchant/billing/avs_result.rb +95 -0
- data/lib/active_merchant/billing/base.rb +8 -3
- data/lib/active_merchant/billing/check.rb +61 -0
- data/lib/active_merchant/billing/credit_card.rb +104 -80
- data/lib/active_merchant/billing/credit_card_formatting.rb +11 -8
- data/lib/active_merchant/billing/credit_card_methods.rb +76 -32
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +28 -0
- data/lib/active_merchant/billing/gateway.rb +47 -111
- data/lib/active_merchant/billing/gateways/authorize_net.rb +508 -121
- data/lib/active_merchant/billing/gateways/bogus.rb +26 -32
- data/lib/active_merchant/billing/gateways/brain_tree.rb +82 -70
- data/lib/active_merchant/billing/gateways/card_stream.rb +43 -15
- data/lib/active_merchant/billing/gateways/cyber_source.rb +9 -29
- data/lib/active_merchant/billing/gateways/data_cash.rb +18 -38
- data/lib/active_merchant/billing/gateways/efsnet.rb +23 -50
- data/lib/active_merchant/billing/gateways/eway.rb +8 -19
- data/lib/active_merchant/billing/gateways/exact.rb +17 -25
- data/lib/active_merchant/billing/gateways/linkpoint.rb +18 -25
- data/lib/active_merchant/billing/gateways/moneris.rb +9 -39
- data/lib/active_merchant/billing/gateways/net_registry.rb +113 -182
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +52 -73
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +13 -14
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +55 -37
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +4 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +2 -4
- data/lib/active_merchant/billing/gateways/payment_express.rb +11 -30
- data/lib/active_merchant/billing/gateways/paypal.rb +3 -14
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +36 -16
- data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -2
- data/lib/active_merchant/billing/gateways/plugnpay.rb +7 -15
- data/lib/active_merchant/billing/gateways/protx.rb +24 -25
- data/lib/active_merchant/billing/gateways/psigate.rb +34 -71
- data/lib/active_merchant/billing/gateways/psl_card.rb +24 -19
- data/lib/active_merchant/billing/gateways/quickpay.rb +10 -24
- data/lib/active_merchant/billing/gateways/realex.rb +7 -19
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +437 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +5 -14
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +100 -39
- data/lib/active_merchant/billing/gateways/usa_epay.rb +60 -55
- data/lib/active_merchant/billing/gateways/verifi.rb +32 -39
- data/lib/active_merchant/billing/gateways/viaklix.rb +31 -37
- data/lib/active_merchant/billing/integrations.rb +2 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +5 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +5 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +5 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +57 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +5 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +5 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/return.rb +35 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +5 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/response.rb +12 -8
- data/lib/active_merchant/lib/posts_data.rb +39 -7
- data/lib/active_merchant/lib/requires_parameters.rb +2 -3
- data/lib/active_merchant/lib/utils.rb +18 -0
- data/lib/active_merchant/lib/validateable.rb +3 -3
- data/lib/support/gateway_support.rb +22 -9
- data/script/destroy +14 -0
- data/script/generate +7 -7
- data/test/fixtures.yml +25 -3
- data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
- data/test/remote/gateways/remote_brain_tree_test.rb +118 -0
- data/test/{remote_tests → remote/gateways}/remote_card_stream_test.rb +56 -68
- data/test/{remote_tests → remote/gateways}/remote_cyber_source_test.rb +21 -32
- data/test/{remote_tests → remote/gateways}/remote_data_cash_test.rb +2 -2
- data/test/{remote_tests → remote/gateways}/remote_efsnet_test.rb +22 -34
- data/test/{remote_tests → remote/gateways}/remote_eway_test.rb +18 -15
- data/test/{remote_tests → remote/gateways}/remote_exact_test.rb +20 -19
- data/test/{remote_tests → remote/gateways}/remote_linkpoint_test.rb +31 -63
- data/test/remote/gateways/remote_moneris_test.rb +82 -0
- data/test/{remote_tests → remote/gateways}/remote_net_registry_test.rb +19 -54
- data/test/remote/gateways/remote_netbilling_test.rb +70 -0
- data/test/{remote_tests → remote/gateways}/remote_pay_junction_test.rb +41 -60
- data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
- data/test/{remote_tests → remote/gateways}/remote_payflow_express_test.rb +2 -2
- data/test/{remote_tests → remote/gateways}/remote_payflow_test.rb +34 -38
- data/test/{remote_tests → remote/gateways}/remote_payflow_uk_test.rb +13 -12
- data/test/{remote_tests → remote/gateways}/remote_payment_express_test.rb +26 -36
- data/test/{remote_tests → remote/gateways}/remote_paypal_express_test.rb +3 -3
- data/test/{remote_tests → remote/gateways}/remote_paypal_test.rb +25 -21
- data/test/{remote_tests → remote/gateways}/remote_plugnpay_test.rb +18 -16
- data/test/{remote_tests → remote/gateways}/remote_protx_test.rb +33 -33
- data/test/remote/gateways/remote_psigate_test.rb +50 -0
- data/test/{remote_tests → remote/gateways}/remote_psl_card_test.rb +27 -26
- data/test/{remote_tests → remote/gateways}/remote_quickpay_test.rb +48 -48
- data/test/{remote_tests → remote/gateways}/remote_realex_test.rb +30 -33
- data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
- data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
- data/test/remote/gateways/remote_skipjack_test.rb +105 -0
- data/test/{remote_tests → remote/gateways}/remote_trans_first_test.rb +7 -10
- data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
- data/test/{remote_tests → remote/gateways}/remote_usa_epay_test.rb +11 -22
- data/test/{remote_tests → remote/gateways}/remote_verifi_test.rb +27 -27
- data/test/{remote_tests → remote/gateways}/remote_viaklix_test.rb +8 -18
- data/test/{remote_tests → remote/integrations}/remote_gestpay_integration_test.rb +1 -1
- data/test/{remote_tests → remote/integrations}/remote_paypal_integration_test.rb +1 -1
- data/test/test_helper.rb +102 -61
- data/test/unit/avs_result_test.rb +59 -0
- data/test/unit/base_test.rb +33 -39
- data/test/unit/check_test.rb +76 -0
- data/test/unit/credit_card_formatting_test.rb +10 -15
- data/test/unit/credit_card_methods_test.rb +132 -17
- data/test/unit/credit_card_test.rb +157 -228
- data/test/unit/cvv_result_test.rb +33 -0
- data/test/unit/expiry_date_test.rb +21 -0
- data/test/unit/gateways/authorize_net_test.rb +180 -40
- data/test/unit/gateways/bogus_test.rb +2 -3
- data/test/unit/gateways/brain_tree_test.rb +63 -29
- data/test/unit/gateways/card_stream_test.rb +59 -6
- data/test/unit/gateways/cyber_source_test.rb +59 -40
- data/test/unit/gateways/data_cash_test.rb +82 -1
- data/test/unit/gateways/efsnet_test.rb +97 -44
- data/test/unit/gateways/eway_test.rb +55 -42
- data/test/unit/gateways/exact_test.rb +93 -55
- data/test/unit/gateways/gateway_test.rb +7 -0
- data/test/unit/gateways/linkpoint_test.rb +60 -58
- data/test/unit/gateways/moneris_test.rb +67 -76
- data/test/unit/gateways/net_registry_test.rb +351 -419
- data/test/unit/gateways/netbilling_test.rb +54 -0
- data/test/unit/gateways/pay_junction_test.rb +108 -46
- data/test/unit/gateways/pay_secure_test.rb +71 -0
- data/test/unit/gateways/payflow_express_test.rb +0 -8
- data/test/unit/gateways/payflow_test.rb +136 -65
- data/test/unit/gateways/payflow_uk_test.rb +0 -38
- data/test/unit/gateways/payment_express_test.rb +31 -51
- data/test/unit/gateways/paypal_express_test.rb +8 -2
- data/test/unit/gateways/paypal_test.rb +213 -54
- data/test/unit/gateways/plugnpay_test.rb +39 -32
- data/test/unit/gateways/protx_test.rb +45 -33
- data/test/unit/gateways/psigate_test.rb +146 -87
- data/test/unit/gateways/psl_card_test.rb +37 -24
- data/test/unit/gateways/quickpay_test.rb +33 -46
- data/test/unit/gateways/realex_test.rb +32 -31
- data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
- data/test/unit/gateways/secure_pay_test.rb +35 -26
- data/test/unit/gateways/skip_jack_test.rb +125 -0
- data/test/unit/gateways/trans_first_test.rb +24 -37
- data/test/unit/gateways/trust_commerce_test.rb +47 -26
- data/test/unit/gateways/usa_epay_test.rb +52 -41
- data/test/unit/gateways/verifi_test.rb +41 -35
- data/test/unit/gateways/viaklix_test.rb +38 -32
- data/test/unit/generators/test_gateway_generator.rb +46 -0
- data/test/unit/generators/test_generator_helper.rb +20 -0
- data/test/unit/generators/test_integration_generator.rb +53 -0
- data/test/unit/integrations/action_view_helper_test.rb +7 -14
- data/test/unit/integrations/bogus_module_test.rb +4 -0
- data/test/unit/integrations/chronopay_module_test.rb +4 -0
- data/test/unit/integrations/gestpay_module_test.rb +4 -0
- data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
- data/test/unit/integrations/hi_trust_module_test.rb +13 -0
- data/test/unit/integrations/nochex_module_test.rb +4 -0
- data/test/unit/integrations/notifications/hi_trust_notification_test.rb +38 -0
- data/test/unit/integrations/paypal_module_test.rb +4 -0
- data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
- data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
- data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
- data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
- data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
- data/test/unit/integrations/returns/return_test.rb +11 -0
- data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
- data/test/unit/integrations/two_checkout_module_test.rb +4 -0
- data/test/unit/posts_data_test.rb +86 -0
- data/test/unit/response_test.rb +15 -1
- data/test/unit/utils_test.rb +7 -0
- data/test/unit/validateable_test.rb +10 -6
- metadata +180 -142
- metadata.gz.sig +0 -0
- data/lib/active_merchant/billing/gateways/paypal/api_cert_chain.crt +0 -35
- data/script/generator/base.rb +0 -45
- data/script/generator/generator.rb +0 -24
- data/script/generator/generators/gateway/gateway_generator.rb +0 -14
- data/script/generator/generators/gateway/templates/gateway.rb +0 -73
- data/script/generator/generators/gateway/templates/gateway_test.rb +0 -41
- data/script/generator/generators/gateway/templates/remote_gateway_test.rb +0 -56
- data/script/generator/generators/integration/integration_generator.rb +0 -25
- data/script/generator/generators/integration/templates/helper.rb +0 -34
- data/script/generator/generators/integration/templates/helper_test.rb +0 -54
- data/script/generator/generators/integration/templates/integration.rb +0 -18
- data/script/generator/generators/integration/templates/module_test.rb +0 -9
- data/script/generator/generators/integration/templates/notification.rb +0 -100
- data/script/generator/generators/integration/templates/notification_test.rb +0 -41
- data/script/generator/manifest.rb +0 -20
- data/test/remote_tests/remote_authorize_net_test.rb +0 -113
- data/test/remote_tests/remote_brain_tree_test.rb +0 -78
- data/test/remote_tests/remote_moneris_test.rb +0 -110
- data/test/remote_tests/remote_psigate_test.rb +0 -87
- data/test/remote_tests/remote_secure_pay_test.rb +0 -36
- data/test/remote_tests/remote_trust_commerce_test.rb +0 -136
|
@@ -3,35 +3,150 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
|
3
3
|
class CreditCardMethodsTest < Test::Unit::TestCase
|
|
4
4
|
include ActiveMerchant::Billing::CreditCardMethods
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
1.upto(12){ |m| assert valid_month?(m) }
|
|
9
|
-
assert !valid_month?(13)
|
|
6
|
+
class CreditCard
|
|
7
|
+
include ActiveMerchant::Billing::CreditCardMethods
|
|
10
8
|
end
|
|
11
|
-
|
|
12
|
-
def
|
|
13
|
-
|
|
9
|
+
|
|
10
|
+
def maestro_card_numbers
|
|
11
|
+
%w[
|
|
12
|
+
5000000000000000 5099999999999999 5600000000000000
|
|
13
|
+
5899999999999999 6000000000000000 6999999999999999
|
|
14
|
+
]
|
|
14
15
|
end
|
|
15
|
-
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
def non_maestro_card_numbers
|
|
18
|
+
%w[
|
|
19
|
+
4999999999999999 5100000000000000 5599999999999999
|
|
20
|
+
5900000000000000 5999999999999999 7000000000000000
|
|
21
|
+
]
|
|
19
22
|
end
|
|
20
23
|
|
|
21
|
-
def
|
|
22
|
-
|
|
24
|
+
def test_should_be_able_to_identify_valid_expiry_months
|
|
25
|
+
assert_false valid_month?(-1)
|
|
26
|
+
assert_false valid_month?(13)
|
|
27
|
+
assert_false valid_month?(nil)
|
|
28
|
+
assert_false valid_month?('')
|
|
29
|
+
|
|
30
|
+
1.upto(12) { |m| assert valid_month?(m) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_should_be_able_to_identify_valid_expiry_years
|
|
34
|
+
assert_false valid_expiry_year?(-1)
|
|
35
|
+
assert_false valid_expiry_year?(Time.now.year + 21)
|
|
36
|
+
|
|
37
|
+
0.upto(20) { |n| assert valid_expiry_year?(Time.now.year + n) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_should_be_able_to_identify_valid_start_years
|
|
23
41
|
assert valid_start_year?(1988)
|
|
24
42
|
assert valid_start_year?(2007)
|
|
25
43
|
assert valid_start_year?(3000)
|
|
44
|
+
|
|
45
|
+
assert_false valid_start_year?(1987)
|
|
26
46
|
end
|
|
27
47
|
|
|
28
|
-
def
|
|
48
|
+
def test_should_be_able_to_identify_valid_issue_numbers
|
|
29
49
|
assert valid_issue_number?(1)
|
|
30
|
-
assert !valid_issue_number?(-1)
|
|
31
50
|
assert valid_issue_number?(10)
|
|
32
51
|
assert valid_issue_number?('12')
|
|
33
52
|
assert valid_issue_number?(0)
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
|
|
54
|
+
assert_false valid_issue_number?(-1)
|
|
55
|
+
assert_false valid_issue_number?(123)
|
|
56
|
+
assert_false valid_issue_number?('CAT')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_should_ensure_type_from_credit_card_class_is_not_frozen
|
|
60
|
+
assert_false CreditCard.type?('4242424242424242').frozen?
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_should_be_dankort_card_type
|
|
64
|
+
assert_equal 'dankort', CreditCard.type?('5019717010103742')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_should_detect_visa_dankort_as_visa
|
|
68
|
+
assert_equal 'visa', CreditCard.type?('4571100000000000')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_should_detect_electron_dk_as_visa
|
|
72
|
+
assert_equal 'visa', CreditCard.type?('4175001000000000')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_should_detect_diners_club
|
|
76
|
+
assert_equal 'diners_club', CreditCard.type?('36148010000000')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_should_detect_diners_club_dk
|
|
80
|
+
assert_equal 'diners_club', CreditCard.type?('30401000000000')
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_should_detect_maestro_dk_as_maestro
|
|
84
|
+
assert_equal 'maestro', CreditCard.type?('6769271000000000')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_should_detect_maestro_cards
|
|
88
|
+
assert_equal 'maestro', CreditCard.type?('5020100000000000')
|
|
89
|
+
|
|
90
|
+
maestro_card_numbers.each { |number| assert_equal 'maestro', CreditCard.type?(number) }
|
|
91
|
+
non_maestro_card_numbers.each { |number| assert_not_equal 'maestro', CreditCard.type?(number) }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_should_detect_mastercard
|
|
95
|
+
assert_equal 'master', CreditCard.type?('6771890000000000')
|
|
96
|
+
assert_equal 'master', CreditCard.type?('5413031000000000')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_should_detect_forbrugsforeningen
|
|
100
|
+
assert_equal 'forbrugsforeningen', CreditCard.type?('6007221000000000')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_should_detect_laser_card
|
|
104
|
+
# 16 digits
|
|
105
|
+
assert_equal 'laser', CreditCard.type?('6304985028090561')
|
|
106
|
+
|
|
107
|
+
# 18 digits
|
|
108
|
+
assert_equal 'laser', CreditCard.type?('630498502809056151')
|
|
109
|
+
|
|
110
|
+
# 19 digits
|
|
111
|
+
assert_equal 'laser', CreditCard.type?('6304985028090561515')
|
|
112
|
+
|
|
113
|
+
# 17 digits
|
|
114
|
+
assert_not_equal 'laser', CreditCard.type?('63049850280905615')
|
|
115
|
+
|
|
116
|
+
# 15 digits
|
|
117
|
+
assert_not_equal 'laser', CreditCard.type?('630498502809056')
|
|
118
|
+
|
|
119
|
+
# Alternate format
|
|
120
|
+
assert_equal 'laser', CreditCard.type?('6706950000000000000')
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_should_detect_when_an_argument_type_does_not_match_calculated_type
|
|
124
|
+
assert CreditCard.matching_type?('4175001000000000', 'visa')
|
|
125
|
+
assert_false CreditCard.matching_type?('4175001000000000', 'master')
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_detecting_full_range_of_maestro_card_numbers
|
|
129
|
+
maestro = '50000000000'
|
|
130
|
+
|
|
131
|
+
assert_equal 11, maestro.length
|
|
132
|
+
assert_not_equal 'maestro', CreditCard.type?(maestro)
|
|
133
|
+
|
|
134
|
+
while maestro.length < 19
|
|
135
|
+
maestro << '0'
|
|
136
|
+
assert_equal 'maestro', CreditCard.type?(maestro)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
assert_equal 19, maestro.length
|
|
140
|
+
|
|
141
|
+
maestro << '0'
|
|
142
|
+
assert_not_equal 'maestro', CreditCard.type?(maestro)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_matching_discover_card
|
|
146
|
+
assert CreditCard.matching_type?('6011000000000000', 'discover')
|
|
147
|
+
assert CreditCard.matching_type?('6500000000000000', 'discover')
|
|
148
|
+
|
|
149
|
+
assert_false CreditCard.matching_type?('6010000000000000', 'discover')
|
|
150
|
+
assert_false CreditCard.matching_type?('6600000000000000', 'discover')
|
|
36
151
|
end
|
|
37
152
|
end
|
|
@@ -1,284 +1,253 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
2
|
|
|
3
3
|
class CreditCardTest < Test::Unit::TestCase
|
|
4
|
-
MAESTRO_CARDS = [ '5000000000000000', '5099999999999999', '5600000000000000',
|
|
5
|
-
'5899999999999999', '6000000000000000', '6999999999999999']
|
|
6
|
-
|
|
7
|
-
NON_MAESTRO_CARDS = [ '4999999999999999', '5100000000000000', '5599999999999999',
|
|
8
|
-
'5900000000000000', '5999999999999999', '7000000000000000' ]
|
|
9
|
-
|
|
10
4
|
def setup
|
|
11
5
|
CreditCard.require_verification_value = false
|
|
12
|
-
|
|
13
|
-
@
|
|
14
|
-
:type => "visa"
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
@solo = credit_card("676700000000000000",
|
|
18
|
-
:type => "solo",
|
|
19
|
-
:issue_number => '01'
|
|
20
|
-
)
|
|
6
|
+
@visa = credit_card("4779139500118580", :type => "visa")
|
|
7
|
+
@solo = credit_card("676700000000000000", :type => "solo", :issue_number => '01')
|
|
21
8
|
end
|
|
22
9
|
|
|
23
10
|
def teardown
|
|
24
11
|
CreditCard.require_verification_value = false
|
|
25
12
|
end
|
|
26
13
|
|
|
27
|
-
def
|
|
14
|
+
def test_constructor_should_properly_assign_values
|
|
15
|
+
c = credit_card
|
|
16
|
+
|
|
17
|
+
assert_equal "4242424242424242", c.number
|
|
18
|
+
assert_equal 9, c.month
|
|
19
|
+
assert_equal Time.now.year + 1, c.year
|
|
20
|
+
assert_equal "Longbob Longsen", c.name
|
|
21
|
+
assert_equal "visa", c.type
|
|
22
|
+
assert_valid c
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_new_credit_card_should_not_be_valid
|
|
28
26
|
c = CreditCard.new
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
assert_not_valid c
|
|
29
|
+
assert_false c.errors.empty?
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
def
|
|
35
|
-
|
|
36
|
-
assert
|
|
32
|
+
def test_should_be_a_valid_visa_card
|
|
33
|
+
assert_valid @visa
|
|
34
|
+
assert @visa.errors.empty?
|
|
37
35
|
end
|
|
38
36
|
|
|
39
|
-
def
|
|
40
|
-
|
|
37
|
+
def test_should_be_a_valid_solo_card
|
|
38
|
+
assert_valid @solo
|
|
39
|
+
assert @solo.errors.empty?
|
|
41
40
|
end
|
|
42
41
|
|
|
43
|
-
def
|
|
42
|
+
def test_cards_with_empty_names_should_not_be_valid
|
|
44
43
|
@visa.first_name = ''
|
|
45
|
-
@visa.last_name
|
|
44
|
+
@visa.last_name = ''
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
assert_not_valid @visa
|
|
47
|
+
assert_false @visa.errors.empty?
|
|
49
48
|
end
|
|
50
49
|
|
|
51
|
-
def
|
|
50
|
+
def test_should_be_able_to_access_errors_indifferently
|
|
52
51
|
@visa.first_name = ''
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
assert_not_valid @visa
|
|
55
54
|
assert @visa.errors.on(:first_name)
|
|
56
55
|
assert @visa.errors.on("first_name")
|
|
57
56
|
end
|
|
58
57
|
|
|
59
|
-
def
|
|
60
|
-
c =
|
|
61
|
-
c
|
|
62
|
-
|
|
63
|
-
c.
|
|
64
|
-
c
|
|
65
|
-
c.year = 2008
|
|
66
|
-
c.valid?
|
|
67
|
-
assert c.valid?
|
|
68
|
-
c.type = 'visa'
|
|
69
|
-
assert !c.valid?
|
|
58
|
+
def test_should_be_able_to_liberate_a_bogus_card
|
|
59
|
+
c = credit_card('', :type => 'bogus')
|
|
60
|
+
assert_valid c
|
|
61
|
+
|
|
62
|
+
c.type = 'visa'
|
|
63
|
+
assert_not_valid c
|
|
70
64
|
end
|
|
71
65
|
|
|
72
|
-
def
|
|
66
|
+
def test_should_be_able_to_identify_invalid_card_numbers
|
|
73
67
|
@visa.number = nil
|
|
74
|
-
|
|
68
|
+
assert_not_valid @visa
|
|
75
69
|
|
|
76
70
|
@visa.number = "11112222333344ff"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
assert
|
|
71
|
+
assert_not_valid @visa
|
|
72
|
+
assert_false @visa.errors.on(:type)
|
|
73
|
+
assert @visa.errors.on(:number)
|
|
80
74
|
|
|
81
75
|
@visa.number = "111122223333444"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
assert
|
|
76
|
+
assert_not_valid @visa
|
|
77
|
+
assert_false @visa.errors.on(:type)
|
|
78
|
+
assert @visa.errors.on(:number)
|
|
85
79
|
|
|
86
80
|
@visa.number = "11112222333344444"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
assert
|
|
81
|
+
assert_not_valid @visa
|
|
82
|
+
assert_false @visa.errors.on(:type)
|
|
83
|
+
assert @visa.errors.on(:number)
|
|
90
84
|
end
|
|
91
85
|
|
|
92
|
-
def
|
|
86
|
+
def test_should_have_errors_with_invalid_card_type_for_otherwise_correct_number
|
|
93
87
|
@visa.type = 'master'
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
|
|
89
|
+
assert_not_valid @visa
|
|
90
|
+
assert_not_equal @visa.errors.on(:number), @visa.errors.on(:type)
|
|
96
91
|
end
|
|
97
92
|
|
|
98
|
-
def
|
|
99
|
-
@visa.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
93
|
+
def test_should_be_invalid_when_type_cannot_be_detected
|
|
94
|
+
@visa.number = nil
|
|
95
|
+
@visa.type = nil
|
|
96
|
+
|
|
97
|
+
assert_not_valid @visa
|
|
103
98
|
assert_match /is required/, @visa.errors.on(:type)
|
|
99
|
+
assert @visa.errors.on(:type)
|
|
104
100
|
end
|
|
105
101
|
|
|
106
|
-
def
|
|
102
|
+
def test_should_be_a_valid_card_number
|
|
107
103
|
@visa.number = "4242424242424242"
|
|
108
|
-
|
|
104
|
+
|
|
105
|
+
assert_valid @visa
|
|
109
106
|
end
|
|
110
107
|
|
|
111
|
-
def
|
|
108
|
+
def test_should_require_a_valid_card_month
|
|
112
109
|
@visa.month = Time.now.month
|
|
113
110
|
@visa.year = Time.now.year
|
|
114
|
-
|
|
111
|
+
|
|
112
|
+
assert_valid @visa
|
|
115
113
|
end
|
|
116
114
|
|
|
117
|
-
def
|
|
115
|
+
def test_should_not_be_valid_with_empty_month
|
|
118
116
|
@visa.month = ''
|
|
119
|
-
|
|
117
|
+
|
|
118
|
+
assert_not_valid @visa
|
|
120
119
|
assert @visa.errors.on('month')
|
|
121
120
|
end
|
|
122
121
|
|
|
123
|
-
def
|
|
122
|
+
def test_should_not_be_valid_for_edge_month_cases
|
|
124
123
|
@visa.month = 13
|
|
125
124
|
@visa.year = Time.now.year
|
|
126
|
-
|
|
125
|
+
assert_not_valid @visa
|
|
127
126
|
assert @visa.errors.on('month')
|
|
128
127
|
|
|
129
128
|
@visa.month = 0
|
|
130
129
|
@visa.year = Time.now.year
|
|
131
|
-
|
|
130
|
+
assert_not_valid @visa
|
|
132
131
|
assert @visa.errors.on('month')
|
|
133
132
|
end
|
|
134
133
|
|
|
135
|
-
def
|
|
134
|
+
def test_should_be_invalid_with_empty_year
|
|
136
135
|
@visa.year = ''
|
|
137
|
-
|
|
136
|
+
assert_not_valid @visa
|
|
138
137
|
assert @visa.errors.on('year')
|
|
139
138
|
end
|
|
140
139
|
|
|
141
|
-
def
|
|
140
|
+
def test_should_not_be_valid_for_edge_year_cases
|
|
142
141
|
@visa.year = Time.now.year - 1
|
|
143
|
-
|
|
142
|
+
assert_not_valid @visa
|
|
144
143
|
assert @visa.errors.on('year')
|
|
145
144
|
|
|
146
145
|
@visa.year = Time.now.year + 21
|
|
147
|
-
|
|
146
|
+
assert_not_valid @visa
|
|
148
147
|
assert @visa.errors.on('year')
|
|
149
148
|
end
|
|
150
149
|
|
|
151
|
-
def
|
|
150
|
+
def test_should_be_a_valid_future_year
|
|
152
151
|
@visa.year = Time.now.year + 1
|
|
153
|
-
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def test_wrong_cardtype
|
|
157
|
-
|
|
158
|
-
c = CreditCard.new(
|
|
159
|
-
"type" => "visa",
|
|
160
|
-
"number" => "4779139500118580",
|
|
161
|
-
"month" => 10,
|
|
162
|
-
"year" => 2007,
|
|
163
|
-
"first_name" => "Tobias",
|
|
164
|
-
"last_name" => "Luetke"
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
assert c.valid?
|
|
168
|
-
|
|
169
|
-
c.type = "master"
|
|
170
|
-
assert !c.valid?
|
|
171
|
-
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def test_constructor
|
|
175
|
-
|
|
176
|
-
c = CreditCard.new(
|
|
177
|
-
"type" => "visa",
|
|
178
|
-
"number" => "4779139500118580",
|
|
179
|
-
"month" => "10",
|
|
180
|
-
"year" => "2007",
|
|
181
|
-
"first_name" => "Tobias",
|
|
182
|
-
"last_name" => "Luetke"
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
assert_equal "4779139500118580", c.number
|
|
186
|
-
assert_equal "10", c.month
|
|
187
|
-
assert_equal "2007", c.year
|
|
188
|
-
assert_equal "Tobias Luetke", c.name
|
|
189
|
-
assert_equal "visa", c.type
|
|
190
|
-
c.valid?
|
|
152
|
+
assert_valid @visa
|
|
191
153
|
end
|
|
192
154
|
|
|
193
|
-
def
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new('number' => '1112223331234').display_number
|
|
197
|
-
|
|
198
|
-
assert_equal 'XXXX-XXXX-XXXX-', CreditCard.new('number' => nil).display_number
|
|
199
|
-
assert_equal 'XXXX-XXXX-XXXX-', CreditCard.new('number' => '').display_number
|
|
200
|
-
assert_equal 'XXXX-XXXX-XXXX-123', CreditCard.new('number' => '123').display_number
|
|
201
|
-
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new('number' => '1234').display_number
|
|
202
|
-
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new('number' => '01234').display_number
|
|
155
|
+
def test_should_identify_wrong_cardtype
|
|
156
|
+
c = credit_card(:type => 'master')
|
|
157
|
+
assert_not_valid c
|
|
203
158
|
end
|
|
204
159
|
|
|
205
|
-
def
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
end
|
|
160
|
+
def test_should_display_number
|
|
161
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1111222233331234').display_number
|
|
162
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '111222233331234').display_number
|
|
163
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1112223331234').display_number
|
|
210
164
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
165
|
+
assert_nil CreditCard.new(:number => nil).display_number
|
|
166
|
+
assert_nil CreditCard.new(:number => '').display_number
|
|
167
|
+
assert_nil CreditCard.new(:number => '123').display_number
|
|
168
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1234').display_number
|
|
169
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '01234').display_number
|
|
215
170
|
end
|
|
216
171
|
|
|
217
|
-
def
|
|
218
|
-
|
|
219
|
-
date = CreditCard::ExpiryDate.new(next_month.month, next_month.year)
|
|
220
|
-
assert !date.expired?
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def test_type
|
|
224
|
-
assert_equal 'visa', CreditCard.type?('4242424242424242')
|
|
172
|
+
def test_should_correctly_identify_card_type
|
|
173
|
+
assert_equal 'visa', CreditCard.type?('4242424242424242')
|
|
225
174
|
assert_equal 'american_express', CreditCard.type?('341111111111111')
|
|
226
175
|
assert_nil CreditCard.type?('')
|
|
227
176
|
end
|
|
228
177
|
|
|
229
|
-
def
|
|
230
|
-
|
|
231
|
-
assert
|
|
178
|
+
def test_should_be_able_to_require_a_verification_value
|
|
179
|
+
CreditCard.require_verification_value = true
|
|
180
|
+
assert CreditCard.requires_verification_value?
|
|
232
181
|
end
|
|
233
182
|
|
|
234
|
-
def
|
|
183
|
+
def test_should_not_be_valid_when_requiring_a_verification_value
|
|
235
184
|
CreditCard.require_verification_value = true
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
card = CreditCard.new(
|
|
240
|
-
:type => "visa",
|
|
241
|
-
:number => "4779139500118580",
|
|
242
|
-
:month => Time.now.month,
|
|
243
|
-
:year => Time.now.year + 1,
|
|
244
|
-
:first_name => "Test",
|
|
245
|
-
:last_name => "Mensch"
|
|
246
|
-
)
|
|
185
|
+
card = credit_card('4242424242424242', :verification_value => nil)
|
|
186
|
+
assert_not_valid card
|
|
247
187
|
|
|
248
|
-
assert !card.valid?
|
|
249
188
|
card.verification_value = '123'
|
|
250
|
-
|
|
189
|
+
assert_valid card
|
|
251
190
|
end
|
|
252
191
|
|
|
253
|
-
def
|
|
254
|
-
@solo.start_month
|
|
255
|
-
@solo.start_year
|
|
192
|
+
def test_should_require_valid_start_date_for_solo_or_switch
|
|
193
|
+
@solo.start_month = nil
|
|
194
|
+
@solo.start_year = nil
|
|
256
195
|
@solo.issue_number = nil
|
|
257
196
|
|
|
258
|
-
|
|
197
|
+
assert_not_valid @solo
|
|
259
198
|
assert @solo.errors.on('start_month')
|
|
260
199
|
assert @solo.errors.on('start_year')
|
|
261
200
|
assert @solo.errors.on('issue_number')
|
|
262
201
|
|
|
263
202
|
@solo.start_month = 2
|
|
264
|
-
@solo.start_year
|
|
265
|
-
|
|
203
|
+
@solo.start_year = 2007
|
|
204
|
+
assert_valid @solo
|
|
266
205
|
end
|
|
267
206
|
|
|
268
|
-
def
|
|
269
|
-
@solo.start_month
|
|
270
|
-
@solo.start_year
|
|
207
|
+
def test_should_require_a_valid_issue_number_for_solo_or_switch
|
|
208
|
+
@solo.start_month = nil
|
|
209
|
+
@solo.start_year = 2005
|
|
271
210
|
@solo.issue_number = nil
|
|
272
211
|
|
|
273
|
-
|
|
212
|
+
assert_not_valid @solo
|
|
274
213
|
assert @solo.errors.on('start_month')
|
|
275
|
-
assert !@solo.errors.on('start_year')
|
|
276
214
|
assert @solo.errors.on('issue_number')
|
|
277
215
|
|
|
278
216
|
@solo.issue_number = 3
|
|
279
|
-
|
|
217
|
+
assert_valid @solo
|
|
280
218
|
end
|
|
281
219
|
|
|
220
|
+
def test_should_return_last_four_digits_of_card_number
|
|
221
|
+
ccn = CreditCard.new(:number => "4779139500118580")
|
|
222
|
+
assert_equal "8580", ccn.last_digits
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def test_should_be_true_when_credit_card_has_a_first_name
|
|
226
|
+
c = CreditCard.new
|
|
227
|
+
assert_false c.first_name?
|
|
228
|
+
|
|
229
|
+
c = CreditCard.new(:first_name => 'James')
|
|
230
|
+
assert c.first_name?
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def test_should_be_true_when_credit_card_has_a_last_name
|
|
234
|
+
c = CreditCard.new
|
|
235
|
+
assert_false c.last_name?
|
|
236
|
+
|
|
237
|
+
c = CreditCard.new(:last_name => 'Herdman')
|
|
238
|
+
assert c.last_name?
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def test_should_test_for_a_full_name
|
|
242
|
+
c = CreditCard.new
|
|
243
|
+
assert_false c.name?
|
|
244
|
+
|
|
245
|
+
c = CreditCard.new(:first_name => 'James', :last_name => 'Herdman')
|
|
246
|
+
assert c.name?
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# The following is a regression for a bug that raised an exception when
|
|
250
|
+
# a new credit card was validated
|
|
282
251
|
def test_validate_new_card
|
|
283
252
|
credit_card = CreditCard.new
|
|
284
253
|
|
|
@@ -286,80 +255,40 @@ class CreditCardTest < Test::Unit::TestCase
|
|
|
286
255
|
credit_card.validate
|
|
287
256
|
end
|
|
288
257
|
end
|
|
289
|
-
|
|
258
|
+
|
|
259
|
+
# The following is a regression for a bug where the keys of the
|
|
260
|
+
# credit card card_companies hash were not duped when detecting the type
|
|
290
261
|
def test_create_and_validate_credit_card_from_type
|
|
291
262
|
credit_card = CreditCard.new(:type => CreditCard.type?('4242424242424242'))
|
|
292
|
-
|
|
293
263
|
assert_nothing_raised do
|
|
294
264
|
credit_card.valid?
|
|
295
265
|
end
|
|
296
266
|
end
|
|
297
267
|
|
|
298
|
-
def
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
def test_dankort_card_type
|
|
304
|
-
assert_equal 'dankort', CreditCard.type?('5019717010103742')
|
|
268
|
+
def test_autodetection_of_credit_card_type
|
|
269
|
+
credit_card = CreditCard.new(:number => '4242424242424242')
|
|
270
|
+
credit_card.valid?
|
|
271
|
+
assert_equal 'visa', credit_card.type
|
|
305
272
|
end
|
|
306
273
|
|
|
307
|
-
def
|
|
308
|
-
|
|
274
|
+
def test_card_type_should_not_be_autodetected_when_provided
|
|
275
|
+
credit_card = CreditCard.new(:number => '4242424242424242', :type => 'master')
|
|
276
|
+
credit_card.valid?
|
|
277
|
+
assert_equal 'master', credit_card.type
|
|
309
278
|
end
|
|
310
279
|
|
|
311
|
-
def
|
|
312
|
-
|
|
280
|
+
def test_detecting_bogus_card
|
|
281
|
+
credit_card = CreditCard.new(:number => '1')
|
|
282
|
+
credit_card.valid?
|
|
283
|
+
assert_equal 'bogus', credit_card.type
|
|
313
284
|
end
|
|
314
285
|
|
|
315
|
-
def
|
|
316
|
-
|
|
286
|
+
def test_validating_bogus_card
|
|
287
|
+
credit_card = credit_card('1', :type => nil)
|
|
288
|
+
assert credit_card.valid?
|
|
317
289
|
end
|
|
318
290
|
|
|
319
|
-
def
|
|
320
|
-
assert_equal '
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
def test_detect_maestro
|
|
324
|
-
assert_equal 'maestro', CreditCard.type?('5020100000000000')
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
def test_maestro_dk_detects_as_maestro
|
|
328
|
-
assert_equal 'maestro', CreditCard.type?('6769271000000000')
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
def test_maestro_range
|
|
332
|
-
MAESTRO_CARDS.each{ |number| assert_equal 'maestro', CreditCard.type?(number) }
|
|
333
|
-
|
|
334
|
-
NON_MAESTRO_CARDS.each{ |number| assert_not_equal 'maestro', CreditCard.type?(number) }
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
def test_mastercard_range
|
|
338
|
-
assert_equal 'master', CreditCard.type?('6771890000000000')
|
|
339
|
-
assert_equal 'master', CreditCard.type?('5413031000000000')
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
def test_forbrugsforeningen
|
|
343
|
-
assert_equal 'forbrugsforeningen', CreditCard.type?('6007221000000000')
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
def test_laser_card
|
|
347
|
-
# 16 digits
|
|
348
|
-
assert_equal 'laser', CreditCard.type?('6304985028090561')
|
|
349
|
-
|
|
350
|
-
# 18 digits
|
|
351
|
-
assert_equal 'laser', CreditCard.type?('630498502809056151')
|
|
352
|
-
|
|
353
|
-
# 19 digits
|
|
354
|
-
assert_equal 'laser', CreditCard.type?('6304985028090561515')
|
|
355
|
-
|
|
356
|
-
# 17 digits
|
|
357
|
-
assert_not_equal 'laser', CreditCard.type?('63049850280905615')
|
|
358
|
-
|
|
359
|
-
# 15 digits
|
|
360
|
-
assert_not_equal 'laser', CreditCard.type?('630498502809056')
|
|
361
|
-
|
|
362
|
-
# Alternate format
|
|
363
|
-
assert_equal 'laser', CreditCard.type?('670695000000000000')
|
|
291
|
+
def test_mask_number
|
|
292
|
+
assert_equal 'XXXX-XXXX-XXXX-5100', CreditCard.mask('5105105105105100')
|
|
364
293
|
end
|
|
365
294
|
end
|