patmaddox-activemerchant 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +480 -0
- data/CONTRIBUTORS +126 -0
- data/MIT-LICENSE +20 -0
- data/README +136 -0
- data/Rakefile +153 -0
- data/gem-public_cert.pem +20 -0
- data/init.rb +3 -0
- data/lib/active_merchant.rb +66 -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 +159 -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 +158 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +657 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +743 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +101 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +595 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -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 +205 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +279 -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/payflow.rb +236 -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 +138 -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 +230 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +306 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
- data/lib/active_merchant/billing/gateways/realex.rb +200 -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 +308 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +26 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +228 -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/integrations.rb +29 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -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 +81 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +156 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -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 +83 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/helper.rb +93 -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/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 +17 -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 +35 -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/response.rb +32 -0
- data/lib/active_merchant/lib/connection.rb +170 -0
- data/lib/active_merchant/lib/country.rb +319 -0
- data/lib/active_merchant/lib/error.rb +4 -0
- data/lib/active_merchant/lib/post_data.rb +22 -0
- data/lib/active_merchant/lib/posts_data.rb +47 -0
- data/lib/active_merchant/lib/requires_parameters.rb +16 -0
- data/lib/active_merchant/lib/utils.rb +18 -0
- data/lib/active_merchant/lib/validateable.rb +76 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/fixtures.yml +355 -0
- data/test/remote/gateways/remote_authorize_net_cim_test.rb +460 -0
- data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
- data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
- data/test/remote/gateways/remote_beanstream_test.rb +150 -0
- data/test/remote/gateways/remote_braintree_test.rb +154 -0
- data/test/remote/gateways/remote_card_stream_test.rb +148 -0
- data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
- data/test/remote/gateways/remote_data_cash_test.rb +357 -0
- data/test/remote/gateways/remote_efsnet_test.rb +81 -0
- data/test/remote/gateways/remote_elavon_test.rb +66 -0
- data/test/remote/gateways/remote_eway_test.rb +74 -0
- data/test/remote/gateways/remote_exact_test.rb +60 -0
- data/test/remote/gateways/remote_first_pay_test.rb +87 -0
- data/test/remote/gateways/remote_instapay_test.rb +61 -0
- data/test/remote/gateways/remote_jetpay_test.rb +103 -0
- data/test/remote/gateways/remote_linkpoint_test.rb +121 -0
- data/test/remote/gateways/remote_merchant_e_solutions_test.rb +173 -0
- data/test/remote/gateways/remote_merchant_ware_test.rb +113 -0
- data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
- data/test/remote/gateways/remote_modern_payments_test.rb +57 -0
- data/test/remote/gateways/remote_moneris_test.rb +82 -0
- data/test/remote/gateways/remote_net_registry_test.rb +85 -0
- data/test/remote/gateways/remote_netbilling_test.rb +70 -0
- data/test/remote/gateways/remote_ogone_test.rb +115 -0
- data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
- data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
- data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
- data/test/remote/gateways/remote_payflow_test.rb +237 -0
- data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
- data/test/remote/gateways/remote_payment_express_test.rb +136 -0
- data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
- data/test/remote/gateways/remote_paypal_test.rb +191 -0
- data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
- data/test/remote/gateways/remote_psigate_test.rb +50 -0
- data/test/remote/gateways/remote_psl_card_test.rb +125 -0
- data/test/remote/gateways/remote_quickpay_test.rb +190 -0
- data/test/remote/gateways/remote_realex_test.rb +224 -0
- data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
- data/test/remote/gateways/remote_sage_pay_test.rb +219 -0
- data/test/remote/gateways/remote_sage_test.rb +87 -0
- data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
- data/test/remote/gateways/remote_sallie_mae_test.rb +51 -0
- data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
- 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/gateways/remote_trans_first_test.rb +34 -0
- data/test/remote/gateways/remote_transax_test.rb +112 -0
- data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
- data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
- data/test/remote/gateways/remote_verifi_test.rb +107 -0
- data/test/remote/gateways/remote_viaklix_test.rb +43 -0
- data/test/remote/gateways/remote_wirecard_test.rb +111 -0
- data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
- data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
- data/test/test_helper.rb +182 -0
- data/test/unit/avs_result_test.rb +59 -0
- data/test/unit/base_test.rb +55 -0
- data/test/unit/check_test.rb +88 -0
- data/test/unit/connection_test.rb +129 -0
- data/test/unit/country_code_test.rb +33 -0
- data/test/unit/country_test.rb +64 -0
- data/test/unit/credit_card_formatting_test.rb +19 -0
- data/test/unit/credit_card_methods_test.rb +179 -0
- data/test/unit/credit_card_test.rb +318 -0
- data/test/unit/cvv_result_test.rb +33 -0
- data/test/unit/expiry_date_test.rb +32 -0
- data/test/unit/gateways/authorize_net_cim_test.rb +676 -0
- data/test/unit/gateways/authorize_net_test.rb +290 -0
- data/test/unit/gateways/beanstream_interac_test.rb +51 -0
- data/test/unit/gateways/beanstream_test.rb +108 -0
- data/test/unit/gateways/bogus_test.rb +46 -0
- data/test/unit/gateways/braintree_test.rb +126 -0
- data/test/unit/gateways/card_stream_test.rb +90 -0
- data/test/unit/gateways/cyber_source_test.rb +188 -0
- data/test/unit/gateways/data_cash_test.rb +133 -0
- data/test/unit/gateways/efsnet_test.rb +123 -0
- data/test/unit/gateways/elavon_test.rb +139 -0
- data/test/unit/gateways/eway_test.rb +118 -0
- data/test/unit/gateways/exact_test.rb +156 -0
- data/test/unit/gateways/first_pay_test.rb +125 -0
- data/test/unit/gateways/gateway_test.rb +48 -0
- data/test/unit/gateways/instapay_test.rb +102 -0
- data/test/unit/gateways/jetpay_test.rb +185 -0
- data/test/unit/gateways/linkpoint_test.rb +197 -0
- data/test/unit/gateways/merchant_e_solutions_test.rb +169 -0
- data/test/unit/gateways/merchant_ware_test.rb +188 -0
- data/test/unit/gateways/modern_payments_cim_test.rb +162 -0
- data/test/unit/gateways/moneris_test.rb +158 -0
- data/test/unit/gateways/net_registry_test.rb +416 -0
- data/test/unit/gateways/netbilling_test.rb +54 -0
- data/test/unit/gateways/ogone_test.rb +319 -0
- data/test/unit/gateways/pay_junction_test.rb +123 -0
- data/test/unit/gateways/pay_secure_test.rb +71 -0
- data/test/unit/gateways/payflow_express_test.rb +173 -0
- data/test/unit/gateways/payflow_express_uk_test.rb +86 -0
- data/test/unit/gateways/payflow_test.rb +305 -0
- data/test/unit/gateways/payflow_uk_test.rb +30 -0
- data/test/unit/gateways/payment_express_test.rb +195 -0
- data/test/unit/gateways/paypal_express_test.rb +382 -0
- data/test/unit/gateways/paypal_test.rb +569 -0
- data/test/unit/gateways/plugnpay_test.rb +86 -0
- data/test/unit/gateways/psigate_test.rb +169 -0
- data/test/unit/gateways/psl_card_test.rb +64 -0
- data/test/unit/gateways/quickpay_test.rb +112 -0
- data/test/unit/gateways/realex_test.rb +151 -0
- data/test/unit/gateways/sage_bankcard_test.rb +196 -0
- data/test/unit/gateways/sage_pay_test.rb +139 -0
- data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
- data/test/unit/gateways/sallie_mae_test.rb +53 -0
- data/test/unit/gateways/secure_pay_au_test.rb +207 -0
- data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
- data/test/unit/gateways/secure_pay_test.rb +87 -0
- data/test/unit/gateways/skip_jack_test.rb +213 -0
- data/test/unit/gateways/trans_first_test.rb +112 -0
- data/test/unit/gateways/trust_commerce_test.rb +90 -0
- data/test/unit/gateways/usa_epay_test.rb +128 -0
- data/test/unit/gateways/verifi_test.rb +96 -0
- data/test/unit/gateways/viaklix_test.rb +78 -0
- data/test/unit/gateways/wirecard_test.rb +250 -0
- 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 +50 -0
- data/test/unit/integrations/bogus_module_test.rb +20 -0
- data/test/unit/integrations/chronopay_module_test.rb +13 -0
- data/test/unit/integrations/gestpay_module_test.rb +14 -0
- data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
- data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
- data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
- data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
- data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
- data/test/unit/integrations/helpers/paypal_helper_test.rb +171 -0
- data/test/unit/integrations/helpers/quickpay_helper_test.rb +40 -0
- data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
- data/test/unit/integrations/hi_trust_module_test.rb +13 -0
- data/test/unit/integrations/nochex_module_test.rb +13 -0
- data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
- data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
- data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
- data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
- data/test/unit/integrations/notifications/notification_test.rb +54 -0
- data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
- data/test/unit/integrations/notifications/quickpay_notification_test.rb +69 -0
- data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
- data/test/unit/integrations/paypal_module_test.rb +28 -0
- data/test/unit/integrations/quickpay_module_test.rb +9 -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 +13 -0
- data/test/unit/post_data_test.rb +55 -0
- data/test/unit/posts_data_test.rb +48 -0
- data/test/unit/response_test.rb +28 -0
- data/test/unit/utils_test.rb +7 -0
- data/test/unit/validateable_test.rb +60 -0
- metadata +367 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CreditCardMethodsTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant::Billing::CreditCardMethods
|
5
|
+
|
6
|
+
class CreditCard
|
7
|
+
include ActiveMerchant::Billing::CreditCardMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
def maestro_card_numbers
|
11
|
+
%w[
|
12
|
+
5000000000000000 5099999999999999 5600000000000000
|
13
|
+
5899999999999999 6000000000000000 6999999999999999
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
def non_maestro_card_numbers
|
18
|
+
%w[
|
19
|
+
4999999999999999 5100000000000000 5599999999999999
|
20
|
+
5900000000000000 5999999999999999 7000000000000000
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
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
|
41
|
+
assert valid_start_year?(1988)
|
42
|
+
assert valid_start_year?(2007)
|
43
|
+
assert valid_start_year?(3000)
|
44
|
+
|
45
|
+
assert_false valid_start_year?(1987)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_be_able_to_identify_valid_issue_numbers
|
49
|
+
assert valid_issue_number?(1)
|
50
|
+
assert valid_issue_number?(10)
|
51
|
+
assert valid_issue_number?('12')
|
52
|
+
assert valid_issue_number?(0)
|
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
|
+
|
122
|
+
# Alternate format (16 digits)
|
123
|
+
assert_equal 'laser', CreditCard.type?('6706123456789012')
|
124
|
+
|
125
|
+
# New format (16 digits)
|
126
|
+
assert_equal 'laser', CreditCard.type?('6709123456789012')
|
127
|
+
|
128
|
+
# Ulster bank (Ireland) with 12 digits
|
129
|
+
assert_equal 'laser', CreditCard.type?('677117111234')
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_should_detect_when_an_argument_type_does_not_match_calculated_type
|
133
|
+
assert CreditCard.matching_type?('4175001000000000', 'visa')
|
134
|
+
assert_false CreditCard.matching_type?('4175001000000000', 'master')
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_detecting_full_range_of_maestro_card_numbers
|
138
|
+
maestro = '50000000000'
|
139
|
+
|
140
|
+
assert_equal 11, maestro.length
|
141
|
+
assert_not_equal 'maestro', CreditCard.type?(maestro)
|
142
|
+
|
143
|
+
while maestro.length < 19
|
144
|
+
maestro << '0'
|
145
|
+
assert_equal 'maestro', CreditCard.type?(maestro)
|
146
|
+
end
|
147
|
+
|
148
|
+
assert_equal 19, maestro.length
|
149
|
+
|
150
|
+
maestro << '0'
|
151
|
+
assert_not_equal 'maestro', CreditCard.type?(maestro)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_matching_discover_card
|
155
|
+
assert CreditCard.matching_type?('6011000000000000', 'discover')
|
156
|
+
assert CreditCard.matching_type?('6500000000000000', 'discover')
|
157
|
+
|
158
|
+
assert_false CreditCard.matching_type?('6010000000000000', 'discover')
|
159
|
+
assert_false CreditCard.matching_type?('6600000000000000', 'discover')
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_16_digit_maestro_uk
|
163
|
+
number = '6759000000000000'
|
164
|
+
assert_equal 16, number.length
|
165
|
+
assert_equal 'switch', CreditCard.type?(number)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_18_digit_maestro_uk
|
169
|
+
number = '675900000000000000'
|
170
|
+
assert_equal 18, number.length
|
171
|
+
assert_equal 'switch', CreditCard.type?(number)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_19_digit_maestro_uk
|
175
|
+
number = '6759000000000000000'
|
176
|
+
assert_equal 19, number.length
|
177
|
+
assert_equal 'switch', CreditCard.type?(number)
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,318 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CreditCardTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
CreditCard.require_verification_value = false
|
6
|
+
@visa = credit_card("4779139500118580", :type => "visa")
|
7
|
+
@solo = credit_card("676700000000000000", :type => "solo", :issue_number => '01')
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
CreditCard.require_verification_value = false
|
12
|
+
end
|
13
|
+
|
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
|
26
|
+
c = CreditCard.new
|
27
|
+
|
28
|
+
assert_not_valid c
|
29
|
+
assert_false c.errors.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_be_a_valid_visa_card
|
33
|
+
assert_valid @visa
|
34
|
+
assert @visa.errors.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_be_a_valid_solo_card
|
38
|
+
assert_valid @solo
|
39
|
+
assert @solo.errors.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_cards_with_empty_names_should_not_be_valid
|
43
|
+
@visa.first_name = ''
|
44
|
+
@visa.last_name = ''
|
45
|
+
|
46
|
+
assert_not_valid @visa
|
47
|
+
assert_false @visa.errors.empty?
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_be_able_to_access_errors_indifferently
|
51
|
+
@visa.first_name = ''
|
52
|
+
|
53
|
+
assert_not_valid @visa
|
54
|
+
assert @visa.errors.on(:first_name)
|
55
|
+
assert @visa.errors.on("first_name")
|
56
|
+
end
|
57
|
+
|
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
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_should_be_able_to_identify_invalid_card_numbers
|
67
|
+
@visa.number = nil
|
68
|
+
assert_not_valid @visa
|
69
|
+
|
70
|
+
@visa.number = "11112222333344ff"
|
71
|
+
assert_not_valid @visa
|
72
|
+
assert_false @visa.errors.on(:type)
|
73
|
+
assert @visa.errors.on(:number)
|
74
|
+
|
75
|
+
@visa.number = "111122223333444"
|
76
|
+
assert_not_valid @visa
|
77
|
+
assert_false @visa.errors.on(:type)
|
78
|
+
assert @visa.errors.on(:number)
|
79
|
+
|
80
|
+
@visa.number = "11112222333344444"
|
81
|
+
assert_not_valid @visa
|
82
|
+
assert_false @visa.errors.on(:type)
|
83
|
+
assert @visa.errors.on(:number)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_should_have_errors_with_invalid_card_type_for_otherwise_correct_number
|
87
|
+
@visa.type = 'master'
|
88
|
+
|
89
|
+
assert_not_valid @visa
|
90
|
+
assert_not_equal @visa.errors.on(:number), @visa.errors.on(:type)
|
91
|
+
end
|
92
|
+
|
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
|
98
|
+
assert_match /is required/, @visa.errors.on(:type)
|
99
|
+
assert @visa.errors.on(:type)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_should_be_a_valid_card_number
|
103
|
+
@visa.number = "4242424242424242"
|
104
|
+
|
105
|
+
assert_valid @visa
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_should_require_a_valid_card_month
|
109
|
+
@visa.month = Time.now.month
|
110
|
+
@visa.year = Time.now.year
|
111
|
+
|
112
|
+
assert_valid @visa
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_should_not_be_valid_with_empty_month
|
116
|
+
@visa.month = ''
|
117
|
+
|
118
|
+
assert_not_valid @visa
|
119
|
+
assert @visa.errors.on('month')
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_should_not_be_valid_for_edge_month_cases
|
123
|
+
@visa.month = 13
|
124
|
+
@visa.year = Time.now.year
|
125
|
+
assert_not_valid @visa
|
126
|
+
assert @visa.errors.on('month')
|
127
|
+
|
128
|
+
@visa.month = 0
|
129
|
+
@visa.year = Time.now.year
|
130
|
+
assert_not_valid @visa
|
131
|
+
assert @visa.errors.on('month')
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_should_be_invalid_with_empty_year
|
135
|
+
@visa.year = ''
|
136
|
+
assert_not_valid @visa
|
137
|
+
assert @visa.errors.on('year')
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_should_not_be_valid_for_edge_year_cases
|
141
|
+
@visa.year = Time.now.year - 1
|
142
|
+
assert_not_valid @visa
|
143
|
+
assert @visa.errors.on('year')
|
144
|
+
|
145
|
+
@visa.year = Time.now.year + 21
|
146
|
+
assert_not_valid @visa
|
147
|
+
assert @visa.errors.on('year')
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_should_be_a_valid_future_year
|
151
|
+
@visa.year = Time.now.year + 1
|
152
|
+
assert_valid @visa
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
def test_should_be_valid_with_start_month_and_year_as_string
|
157
|
+
@solo.start_month = '2'
|
158
|
+
@solo.start_year = '2007'
|
159
|
+
assert_valid @solo
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_should_identify_wrong_cardtype
|
163
|
+
c = credit_card(:type => 'master')
|
164
|
+
assert_not_valid c
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_should_display_number
|
168
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1111222233331234').display_number
|
169
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '111222233331234').display_number
|
170
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1112223331234').display_number
|
171
|
+
|
172
|
+
assert_equal 'XXXX-XXXX-XXXX-', CreditCard.new(:number => nil).display_number
|
173
|
+
assert_equal 'XXXX-XXXX-XXXX-', CreditCard.new(:number => '').display_number
|
174
|
+
assert_equal 'XXXX-XXXX-XXXX-123', CreditCard.new(:number => '123').display_number
|
175
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '1234').display_number
|
176
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new(:number => '01234').display_number
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_should_correctly_identify_card_type
|
180
|
+
assert_equal 'visa', CreditCard.type?('4242424242424242')
|
181
|
+
assert_equal 'american_express', CreditCard.type?('341111111111111')
|
182
|
+
assert_nil CreditCard.type?('')
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_should_be_able_to_require_a_verification_value
|
186
|
+
CreditCard.require_verification_value = true
|
187
|
+
assert CreditCard.requires_verification_value?
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_should_not_be_valid_when_requiring_a_verification_value
|
191
|
+
CreditCard.require_verification_value = true
|
192
|
+
card = credit_card('4242424242424242', :verification_value => nil)
|
193
|
+
assert_not_valid card
|
194
|
+
|
195
|
+
card.verification_value = '123'
|
196
|
+
assert_valid card
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_should_require_valid_start_date_for_solo_or_switch
|
200
|
+
@solo.start_month = nil
|
201
|
+
@solo.start_year = nil
|
202
|
+
@solo.issue_number = nil
|
203
|
+
|
204
|
+
assert_not_valid @solo
|
205
|
+
assert @solo.errors.on('start_month')
|
206
|
+
assert @solo.errors.on('start_year')
|
207
|
+
assert @solo.errors.on('issue_number')
|
208
|
+
|
209
|
+
@solo.start_month = 2
|
210
|
+
@solo.start_year = 2007
|
211
|
+
assert_valid @solo
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_should_require_a_valid_issue_number_for_solo_or_switch
|
215
|
+
@solo.start_month = nil
|
216
|
+
@solo.start_year = 2005
|
217
|
+
@solo.issue_number = nil
|
218
|
+
|
219
|
+
assert_not_valid @solo
|
220
|
+
assert @solo.errors.on('start_month')
|
221
|
+
assert @solo.errors.on('issue_number')
|
222
|
+
|
223
|
+
@solo.issue_number = 3
|
224
|
+
assert_valid @solo
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_should_return_last_four_digits_of_card_number
|
228
|
+
ccn = CreditCard.new(:number => "4779139500118580")
|
229
|
+
assert_equal "8580", ccn.last_digits
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_bogus_last_digits
|
233
|
+
ccn = CreditCard.new(:number => "1")
|
234
|
+
assert_equal "1", ccn.last_digits
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_should_be_true_when_credit_card_has_a_first_name
|
238
|
+
c = CreditCard.new
|
239
|
+
assert_false c.first_name?
|
240
|
+
|
241
|
+
c = CreditCard.new(:first_name => 'James')
|
242
|
+
assert c.first_name?
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_should_be_true_when_credit_card_has_a_last_name
|
246
|
+
c = CreditCard.new
|
247
|
+
assert_false c.last_name?
|
248
|
+
|
249
|
+
c = CreditCard.new(:last_name => 'Herdman')
|
250
|
+
assert c.last_name?
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_should_test_for_a_full_name
|
254
|
+
c = CreditCard.new
|
255
|
+
assert_false c.name?
|
256
|
+
|
257
|
+
c = CreditCard.new(:first_name => 'James', :last_name => 'Herdman')
|
258
|
+
assert c.name?
|
259
|
+
end
|
260
|
+
|
261
|
+
# The following is a regression for a bug that raised an exception when
|
262
|
+
# a new credit card was validated
|
263
|
+
def test_validate_new_card
|
264
|
+
credit_card = CreditCard.new
|
265
|
+
|
266
|
+
assert_nothing_raised do
|
267
|
+
credit_card.validate
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
# The following is a regression for a bug where the keys of the
|
272
|
+
# credit card card_companies hash were not duped when detecting the type
|
273
|
+
def test_create_and_validate_credit_card_from_type
|
274
|
+
credit_card = CreditCard.new(:type => CreditCard.type?('4242424242424242'))
|
275
|
+
assert_nothing_raised do
|
276
|
+
credit_card.valid?
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_autodetection_of_credit_card_type
|
281
|
+
credit_card = CreditCard.new(:number => '4242424242424242')
|
282
|
+
credit_card.valid?
|
283
|
+
assert_equal 'visa', credit_card.type
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_card_type_should_not_be_autodetected_when_provided
|
287
|
+
credit_card = CreditCard.new(:number => '4242424242424242', :type => 'master')
|
288
|
+
credit_card.valid?
|
289
|
+
assert_equal 'master', credit_card.type
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_detecting_bogus_card
|
293
|
+
credit_card = CreditCard.new(:number => '1')
|
294
|
+
credit_card.valid?
|
295
|
+
assert_equal 'bogus', credit_card.type
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_validating_bogus_card
|
299
|
+
credit_card = credit_card('1', :type => nil)
|
300
|
+
assert credit_card.valid?
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_mask_number
|
304
|
+
assert_equal 'XXXX-XXXX-XXXX-5100', CreditCard.mask('5105105105105100')
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_strip_non_digit_characters
|
308
|
+
card = credit_card('4242-4242 %%%%%%4242......4242')
|
309
|
+
assert card.valid?
|
310
|
+
assert_equal "4242424242424242", card.number
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_before_validate_handles_blank_number
|
314
|
+
card = credit_card(nil)
|
315
|
+
assert !card.valid?
|
316
|
+
assert_equal "", card.number
|
317
|
+
end
|
318
|
+
end
|