activemerchant 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +226 -0
- data/CONTRIBUTERS +52 -0
- data/README +34 -24
- data/Rakefile +152 -0
- data/gem-public_cert.pem +20 -0
- data/init.rb +3 -0
- data/lib/active_merchant.rb +3 -1
- data/lib/active_merchant/billing/credit_card.rb +21 -17
- data/lib/active_merchant/billing/credit_card_methods.rb +17 -19
- data/lib/active_merchant/billing/gateway.rb +160 -44
- data/lib/active_merchant/billing/gateways.rb +2 -15
- data/lib/active_merchant/billing/gateways/authorize_net.rb +21 -21
- data/lib/active_merchant/billing/gateways/bogus.rb +6 -6
- data/lib/active_merchant/billing/gateways/brain_tree.rb +191 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +207 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +402 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +41 -97
- data/lib/active_merchant/billing/gateways/efsnet.rb +256 -0
- data/lib/active_merchant/billing/gateways/eway.rb +77 -29
- data/lib/active_merchant/billing/gateways/exact.rb +230 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -33
- data/lib/active_merchant/billing/gateways/moneris.rb +155 -125
- data/lib/active_merchant/billing/gateways/net_registry.rb +257 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +407 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +163 -25
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +56 -38
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +10 -1
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +9 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +36 -11
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +6 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +7 -3
- data/lib/active_merchant/billing/gateways/payment_express.rb +261 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +18 -4
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +31 -15
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +8 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +33 -8
- data/lib/active_merchant/billing/gateways/plugnpay.rb +300 -0
- data/lib/active_merchant/billing/gateways/protx.rb +285 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +13 -12
- data/lib/active_merchant/billing/gateways/psl_card.rb +297 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +197 -0
- data/lib/active_merchant/billing/gateways/realex.rb +212 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +136 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +43 -20
- data/lib/active_merchant/billing/gateways/usa_epay.rb +6 -5
- data/lib/active_merchant/billing/gateways/verifi.rb +235 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +0 -2
- data/lib/active_merchant/billing/integrations/helper.rb +8 -1
- data/lib/active_merchant/billing/integrations/nochex.rb +62 -1
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +9 -16
- data/lib/active_merchant/billing/integrations/notification.rb +1 -1
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +59 -46
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +14 -47
- 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 +23 -5
- data/lib/active_merchant/lib/requires_parameters.rb +2 -2
- data/lib/active_merchant/lib/validateable.rb +1 -1
- data/lib/support/gateway_support.rb +45 -0
- data/lib/tasks/cia.rb +1 -1
- data/script/generate +14 -0
- data/script/generator/base.rb +45 -0
- data/script/generator/generator.rb +24 -0
- data/script/generator/generators/gateway/gateway_generator.rb +14 -0
- data/script/generator/generators/gateway/templates/gateway.rb +73 -0
- data/script/generator/generators/gateway/templates/gateway_test.rb +41 -0
- data/script/generator/generators/gateway/templates/remote_gateway_test.rb +56 -0
- data/script/generator/generators/integration/integration_generator.rb +25 -0
- data/script/generator/generators/integration/templates/helper.rb +34 -0
- data/script/generator/generators/integration/templates/helper_test.rb +54 -0
- data/script/generator/generators/integration/templates/integration.rb +18 -0
- data/script/generator/generators/integration/templates/module_test.rb +9 -0
- data/script/generator/generators/integration/templates/notification.rb +100 -0
- data/script/generator/generators/integration/templates/notification_test.rb +41 -0
- data/script/generator/manifest.rb +20 -0
- data/test/extra/binding_of_caller.rb +80 -0
- data/test/extra/breakpoint.rb +547 -0
- data/test/fixtures.yml +251 -0
- data/test/remote_tests/remote_authorize_net_test.rb +113 -0
- data/test/remote_tests/remote_brain_tree_test.rb +78 -0
- data/test/remote_tests/remote_card_stream_test.rb +160 -0
- data/test/remote_tests/remote_cyber_source_test.rb +130 -0
- data/test/remote_tests/remote_data_cash_test.rb +155 -0
- data/test/remote_tests/remote_efsnet_test.rb +93 -0
- data/test/remote_tests/remote_eway_test.rb +71 -0
- data/test/remote_tests/remote_exact_test.rb +59 -0
- data/test/remote_tests/remote_gestpay_integration_test.rb +37 -0
- data/test/remote_tests/remote_linkpoint_test.rb +144 -0
- data/test/remote_tests/remote_moneris_test.rb +110 -0
- data/test/remote_tests/remote_net_registry_test.rb +120 -0
- data/test/remote_tests/remote_pay_junction_test.rb +162 -0
- data/test/remote_tests/remote_payflow_express_test.rb +50 -0
- data/test/remote_tests/remote_payflow_test.rb +241 -0
- data/test/remote_tests/remote_payflow_uk_test.rb +172 -0
- data/test/remote_tests/remote_payment_express_test.rb +136 -0
- data/test/remote_tests/remote_paypal_express_test.rb +49 -0
- data/test/remote_tests/remote_paypal_integration_test.rb +14 -0
- data/test/remote_tests/remote_paypal_test.rb +163 -0
- data/test/remote_tests/remote_plugnpay_test.rb +70 -0
- data/test/remote_tests/remote_protx_test.rb +184 -0
- data/test/remote_tests/remote_psigate_test.rb +87 -0
- data/test/remote_tests/remote_psl_card_test.rb +105 -0
- data/test/remote_tests/remote_quickpay_test.rb +182 -0
- data/test/remote_tests/remote_realex_test.rb +227 -0
- data/test/remote_tests/remote_secure_pay_test.rb +36 -0
- data/test/remote_tests/remote_trans_first_test.rb +37 -0
- data/test/remote_tests/remote_trust_commerce_test.rb +136 -0
- data/test/remote_tests/remote_usa_epay_test.rb +57 -0
- data/test/remote_tests/remote_verifi_test.rb +107 -0
- data/test/remote_tests/remote_viaklix_test.rb +53 -0
- data/test/test_helper.rb +132 -0
- data/test/unit/base_test.rb +61 -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 +24 -0
- data/test/unit/credit_card_methods_test.rb +37 -0
- data/test/unit/credit_card_test.rb +365 -0
- data/test/unit/gateways/authorize_net_test.rb +140 -0
- data/test/unit/gateways/bogus_test.rb +43 -0
- data/test/unit/gateways/brain_tree_test.rb +77 -0
- data/test/unit/gateways/card_stream_test.rb +37 -0
- data/test/unit/gateways/cyber_source_test.rb +151 -0
- data/test/unit/gateways/data_cash_test.rb +23 -0
- data/test/unit/gateways/efsnet_test.rb +70 -0
- data/test/unit/gateways/eway_test.rb +105 -0
- data/test/unit/gateways/exact_test.rb +118 -0
- data/test/unit/gateways/gateway_test.rb +24 -0
- data/test/unit/gateways/linkpoint_test.rb +165 -0
- data/test/unit/gateways/moneris_test.rb +167 -0
- data/test/unit/gateways/net_registry_test.rb +478 -0
- data/test/unit/gateways/pay_junction_test.rb +61 -0
- data/test/unit/gateways/payflow_express_test.rb +165 -0
- data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
- data/test/unit/gateways/payflow_test.rb +230 -0
- data/test/unit/gateways/payflow_uk_test.rb +68 -0
- data/test/unit/gateways/payment_express_test.rb +215 -0
- data/test/unit/gateways/paypal_express_test.rb +222 -0
- data/test/unit/gateways/paypal_test.rb +241 -0
- data/test/unit/gateways/plugnpay_test.rb +79 -0
- data/test/unit/gateways/protx_test.rb +110 -0
- data/test/unit/gateways/psigate_test.rb +110 -0
- data/test/unit/gateways/psl_card_test.rb +51 -0
- data/test/unit/gateways/quickpay_test.rb +125 -0
- data/test/unit/gateways/realex_test.rb +150 -0
- data/test/unit/gateways/secure_pay_test.rb +78 -0
- data/test/unit/gateways/trans_first_test.rb +125 -0
- data/test/unit/gateways/trust_commerce_test.rb +57 -0
- data/test/unit/gateways/usa_epay_test.rb +117 -0
- data/test/unit/gateways/verifi_test.rb +91 -0
- data/test/unit/gateways/viaklix_test.rb +72 -0
- data/test/unit/integrations/action_view_helper_test.rb +54 -0
- data/test/unit/integrations/bogus_module_test.rb +16 -0
- data/test/unit/integrations/chronopay_module_test.rb +9 -0
- data/test/unit/integrations/gestpay_module_test.rb +10 -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/nochex_helper_test.rb +53 -0
- data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
- data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
- data/test/unit/integrations/nochex_module_test.rb +9 -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/nochex_notification_test.rb +51 -0
- data/test/unit/integrations/notifications/notification_test.rb +41 -0
- data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
- data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
- data/test/unit/integrations/paypal_module_test.rb +24 -0
- data/test/unit/integrations/two_checkout_module_test.rb +9 -0
- data/test/unit/post_data_test.rb +55 -0
- data/test/unit/response_test.rb +14 -0
- data/test/unit/validateable_test.rb +56 -0
- metadata +160 -7
- metadata.gz.sig +0 -0
- data/lib/active_merchant/billing/gateways/payflow/f73e89fd.0 +0 -17
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
ActiveMerchant::Billing::Base.mode = :test
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
ActiveMerchant::Billing::Base.mode = :test
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_gateway_by_name
|
13
|
+
assert_equal BogusGateway, Base.gateway(:bogus)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_get_moneris_by_name
|
17
|
+
assert_equal MonerisGateway, Base.gateway(:moneris)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_get_authorize_net_by_name
|
21
|
+
assert_equal AuthorizeNetGateway, Base.gateway(:authorize_net)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_get_usay_epay_by_name
|
25
|
+
assert_equal UsaEpayGateway, Base.gateway(:usa_epay)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_get_linkpoint_by_name
|
29
|
+
assert_equal LinkpointGateway, Base.gateway(:linkpoint)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_get_authorize_net_deprecated
|
33
|
+
assert_equal AuthorizedNetGateway, Base.gateway(:authorized_net)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_integration
|
37
|
+
chronopay = Base.integration(:chronopay)
|
38
|
+
assert_equal ActiveMerchant::Billing::Integrations::Chronopay, chronopay
|
39
|
+
assert_instance_of ActiveMerchant::Billing::Integrations::Chronopay::Notification, chronopay.notification('name=cody')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_set_modes
|
43
|
+
ActiveMerchant::Billing::Base.mode = :test
|
44
|
+
assert_equal :test, ActiveMerchant::Billing::Base.mode
|
45
|
+
assert_equal :test, ActiveMerchant::Billing::Base.gateway_mode
|
46
|
+
assert_equal :test, ActiveMerchant::Billing::Base.integration_mode
|
47
|
+
|
48
|
+
ActiveMerchant::Billing::Base.mode = :production
|
49
|
+
assert_equal :production, ActiveMerchant::Billing::Base.mode
|
50
|
+
assert_equal :production, ActiveMerchant::Billing::Base.gateway_mode
|
51
|
+
assert_equal :production, ActiveMerchant::Billing::Base.integration_mode
|
52
|
+
|
53
|
+
ActiveMerchant::Billing::Base.mode = :development
|
54
|
+
ActiveMerchant::Billing::Base.gateway_mode = :test
|
55
|
+
ActiveMerchant::Billing::Base.integration_mode = :staging
|
56
|
+
assert_equal :development, ActiveMerchant::Billing::Base.mode
|
57
|
+
assert_equal :test, ActiveMerchant::Billing::Base.gateway_mode
|
58
|
+
assert_equal :staging, ActiveMerchant::Billing::Base.integration_mode
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CountryCodeTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant
|
5
|
+
|
6
|
+
def test_alpha2_country_code
|
7
|
+
code = CountryCode.new('CA')
|
8
|
+
assert_equal 'CA', code.value
|
9
|
+
assert_equal 'CA', code.to_s
|
10
|
+
assert_equal :alpha2, code.format
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_lower_alpha2_country_code
|
14
|
+
code = CountryCode.new('ca')
|
15
|
+
assert_equal 'CA', code.value
|
16
|
+
assert_equal 'CA', code.to_s
|
17
|
+
assert_equal :alpha2, code.format
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_alpha2_country_code
|
21
|
+
code = CountryCode.new('CAN')
|
22
|
+
assert_equal :alpha3, code.format
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_numeric_code
|
26
|
+
code = CountryCode.new('004')
|
27
|
+
assert_equal :numeric, code.format
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_invalid_code_format
|
31
|
+
assert_raise(CountryCodeFormatError){ CountryCode.new('Canada') }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CountryTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant
|
5
|
+
|
6
|
+
def test_country_from_hash
|
7
|
+
country = Country.new(:name => 'Canada', :alpha2 => 'CA', :alpha3 => 'CAN', :numeric => '124')
|
8
|
+
assert_equal 'CA', country.code(:alpha2).to_s
|
9
|
+
assert_equal 'CAN', country.code(:alpha3).to_s
|
10
|
+
assert_equal '124', country.code(:numeric).to_s
|
11
|
+
assert_equal 'Canada', country.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_country_for_alpha2_code
|
15
|
+
country = Country.find('CA')
|
16
|
+
assert_equal 'CA', country.code(:alpha2).to_s
|
17
|
+
assert_equal 'CAN', country.code(:alpha3).to_s
|
18
|
+
assert_equal '124', country.code(:numeric).to_s
|
19
|
+
assert_equal 'Canada', country.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_country_for_alpha3_code
|
23
|
+
country = Country.find('CAN')
|
24
|
+
assert_equal 'Canada', country.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_country_for_numeric_code
|
28
|
+
country = Country.find('124')
|
29
|
+
assert_equal 'Canada', country.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_find_country_by_name
|
33
|
+
country = Country.find('Canada')
|
34
|
+
assert_equal 'Canada', country.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_find_unknown_country_name
|
38
|
+
assert_raise(InvalidCountryCodeError) do
|
39
|
+
Country.find('Asskickistan')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_find_australia
|
44
|
+
country = Country.find('AU')
|
45
|
+
assert_equal 'AU', country.code(:alpha2).to_s
|
46
|
+
|
47
|
+
country = Country.find('Australia')
|
48
|
+
assert_equal 'AU', country.code(:alpha2).to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_find_united_kingdom
|
52
|
+
country = Country.find('GB')
|
53
|
+
assert_equal 'GB', country.code(:alpha2).to_s
|
54
|
+
|
55
|
+
country = Country.find('United Kingdom')
|
56
|
+
assert_equal 'GB', country.code(:alpha2).to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_raise_on_nil_name
|
60
|
+
assert_raise(InvalidCountryCodeError) do
|
61
|
+
Country.find(nil)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CreditCardFormattingTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant::Billing::CreditCardFormatting
|
5
|
+
|
6
|
+
def test_format_expiry_year
|
7
|
+
year = 2005
|
8
|
+
|
9
|
+
assert_equal '05', format(year, :two_digits)
|
10
|
+
assert_equal '2005', format(year, :four_digits)
|
11
|
+
assert_equal '05', format(05, :two_digits)
|
12
|
+
assert_equal '0005', format(05, :four_digits)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_format_expiry_month
|
16
|
+
month = 8
|
17
|
+
assert_equal '08', format(month, :two_digits)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_format_empty_numbers
|
21
|
+
assert_equal '', format(nil, :two_digits)
|
22
|
+
assert_equal '', format('', :two_digits)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CreditCardMethodsTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant::Billing::CreditCardMethods
|
5
|
+
|
6
|
+
def test_valid_expiry_months
|
7
|
+
assert !valid_month?(-1)
|
8
|
+
1.upto(12){ |m| assert valid_month?(m) }
|
9
|
+
assert !valid_month?(13)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_valid_expiry_year
|
13
|
+
0.upto(20){ |n| assert valid_expiry_year?(Time.now.year + n) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_invalid_expiry_year
|
17
|
+
assert !valid_expiry_year?(-1)
|
18
|
+
assert !valid_expiry_year?(Time.now.year + 21)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_valid_start_year
|
22
|
+
assert !valid_start_year?(1987)
|
23
|
+
assert valid_start_year?(1988)
|
24
|
+
assert valid_start_year?(2007)
|
25
|
+
assert valid_start_year?(3000)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_valid_issue_number
|
29
|
+
assert valid_issue_number?(1)
|
30
|
+
assert !valid_issue_number?(-1)
|
31
|
+
assert valid_issue_number?(10)
|
32
|
+
assert valid_issue_number?('12')
|
33
|
+
assert valid_issue_number?(0)
|
34
|
+
assert !valid_issue_number?(123)
|
35
|
+
assert !valid_issue_number?('CAT')
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,365 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
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
|
+
def setup
|
11
|
+
CreditCard.require_verification_value = false
|
12
|
+
|
13
|
+
@visa = credit_card("4779139500118580",
|
14
|
+
:type => "visa"
|
15
|
+
)
|
16
|
+
|
17
|
+
@solo = credit_card("676700000000000000",
|
18
|
+
:type => "solo",
|
19
|
+
:issue_number => '01'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
CreditCard.require_verification_value = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_validation
|
28
|
+
c = CreditCard.new
|
29
|
+
|
30
|
+
assert !c.valid?
|
31
|
+
assert !c.errors.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_valid
|
35
|
+
assert @visa.valid?
|
36
|
+
assert @visa.errors.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_valid_solo_card
|
40
|
+
assert @solo.valid?
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_empty_names
|
44
|
+
@visa.first_name = ''
|
45
|
+
@visa.last_name = ''
|
46
|
+
|
47
|
+
assert !@visa.valid?
|
48
|
+
assert !@visa.errors.empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_indifferent_error_access
|
52
|
+
@visa.first_name = ''
|
53
|
+
|
54
|
+
assert !@visa.valid?
|
55
|
+
assert @visa.errors.on(:first_name)
|
56
|
+
assert @visa.errors.on("first_name")
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_liberate_bogus_card
|
60
|
+
c = CreditCard.new
|
61
|
+
c.type = 'bogus'
|
62
|
+
c.first_name = "Name"
|
63
|
+
c.last_name = "Last"
|
64
|
+
c.month = 7
|
65
|
+
c.year = 2008
|
66
|
+
c.valid?
|
67
|
+
assert c.valid?
|
68
|
+
c.type = 'visa'
|
69
|
+
assert !c.valid?
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_invalid_card_numbers
|
73
|
+
@visa.number = nil
|
74
|
+
assert !@visa.valid?
|
75
|
+
|
76
|
+
@visa.number = "11112222333344ff"
|
77
|
+
assert !@visa.valid?
|
78
|
+
assert @visa.errors.on(:number)
|
79
|
+
assert !@visa.errors.on(:type)
|
80
|
+
|
81
|
+
@visa.number = "111122223333444"
|
82
|
+
assert !@visa.valid?
|
83
|
+
assert @visa.errors.on(:number)
|
84
|
+
assert !@visa.errors.on(:type)
|
85
|
+
|
86
|
+
@visa.number = "11112222333344444"
|
87
|
+
assert !@visa.valid?
|
88
|
+
assert @visa.errors.on(:number)
|
89
|
+
assert !@visa.errors.on(:type)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_invalid_card_type_does_not_match_number
|
93
|
+
@visa.type = 'master'
|
94
|
+
assert !@visa.valid?
|
95
|
+
assert @visa.errors.on(:number) ^ @visa.errors.on(:type)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_empty_type_should_be_invalid
|
99
|
+
@visa.type = ''
|
100
|
+
assert !@visa.valid?
|
101
|
+
assert @visa.errors.on(:type)
|
102
|
+
assert !@visa.errors.on(:number)
|
103
|
+
assert_match /is required/, @visa.errors.on(:type)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_valid_card_number
|
107
|
+
@visa.number = "4242424242424242"
|
108
|
+
assert @visa.valid?
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_valid_card_month
|
112
|
+
@visa.month = Time.now.month
|
113
|
+
@visa.year = Time.now.year
|
114
|
+
assert @visa.valid?
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_empty_month_should_be_invalid
|
118
|
+
@visa.month = ''
|
119
|
+
assert !@visa.valid?
|
120
|
+
assert @visa.errors.on('month')
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_edge_cases_for_valid_months
|
124
|
+
@visa.month = 13
|
125
|
+
@visa.year = Time.now.year
|
126
|
+
assert !@visa.valid?
|
127
|
+
assert @visa.errors.on('month')
|
128
|
+
|
129
|
+
@visa.month = 0
|
130
|
+
@visa.year = Time.now.year
|
131
|
+
assert !@visa.valid?
|
132
|
+
assert @visa.errors.on('month')
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_empty_year_should_be_invalid
|
136
|
+
@visa.year = ''
|
137
|
+
assert !@visa.valid?
|
138
|
+
assert @visa.errors.on('year')
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_edge_cases_for_valid_years
|
142
|
+
@visa.year = Time.now.year - 1
|
143
|
+
assert !@visa.valid?
|
144
|
+
assert @visa.errors.on('year')
|
145
|
+
|
146
|
+
@visa.year = Time.now.year + 21
|
147
|
+
assert !@visa.valid?
|
148
|
+
assert @visa.errors.on('year')
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_valid_year
|
152
|
+
@visa.year = Time.now.year + 1
|
153
|
+
assert @visa.valid?
|
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?
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_display_number
|
194
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new('number' => '1111222233331234').display_number
|
195
|
+
assert_equal 'XXXX-XXXX-XXXX-1234', CreditCard.new('number' => '111222233331234').display_number
|
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
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_expired_date
|
206
|
+
last_month = Time.now - 2.months
|
207
|
+
date = CreditCard::ExpiryDate.new(last_month.month, last_month.year)
|
208
|
+
assert date.expired?
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_today_is_not_expired
|
212
|
+
today = Time.now
|
213
|
+
date = CreditCard::ExpiryDate.new(today.month, today.year)
|
214
|
+
assert !date.expired?
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_not_expired
|
218
|
+
next_month = Time.now + 1.month
|
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')
|
225
|
+
assert_equal 'american_express', CreditCard.type?('341111111111111')
|
226
|
+
assert_nil CreditCard.type?('')
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_does_not_require_verification_value
|
230
|
+
assert !CreditCard.requires_verification_value?
|
231
|
+
assert @visa.valid?
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_requires_verification_value
|
235
|
+
CreditCard.require_verification_value = true
|
236
|
+
|
237
|
+
assert CreditCard.requires_verification_value?
|
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
|
+
)
|
247
|
+
|
248
|
+
assert !card.valid?
|
249
|
+
card.verification_value = '123'
|
250
|
+
assert card.valid?
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_solo_is_valid_with_start_date
|
254
|
+
@solo.start_month = nil
|
255
|
+
@solo.start_year = nil
|
256
|
+
@solo.issue_number = nil
|
257
|
+
|
258
|
+
assert !@solo.valid?
|
259
|
+
assert @solo.errors.on('start_month')
|
260
|
+
assert @solo.errors.on('start_year')
|
261
|
+
assert @solo.errors.on('issue_number')
|
262
|
+
|
263
|
+
@solo.start_month = 2
|
264
|
+
@solo.start_year = 2007
|
265
|
+
assert @solo.valid?
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_solo_is_valid_with_issue_number
|
269
|
+
@solo.start_month = nil
|
270
|
+
@solo.start_year = 2005
|
271
|
+
@solo.issue_number = nil
|
272
|
+
|
273
|
+
assert !@solo.valid?
|
274
|
+
assert @solo.errors.on('start_month')
|
275
|
+
assert !@solo.errors.on('start_year')
|
276
|
+
assert @solo.errors.on('issue_number')
|
277
|
+
|
278
|
+
@solo.issue_number = 3
|
279
|
+
assert @solo.valid?
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_validate_new_card
|
283
|
+
credit_card = CreditCard.new
|
284
|
+
|
285
|
+
assert_nothing_raised do
|
286
|
+
credit_card.validate
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_create_and_validate_credit_card_from_type
|
291
|
+
credit_card = CreditCard.new(:type => CreditCard.type?('4242424242424242'))
|
292
|
+
|
293
|
+
assert_nothing_raised do
|
294
|
+
credit_card.valid?
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_ensure_type_from_credit_card_class_is_not_frozen
|
299
|
+
type = CreditCard.type?('4242424242424242')
|
300
|
+
assert !type.frozen?
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_dankort_card_type
|
304
|
+
assert_equal 'dankort', CreditCard.type?('5019717010103742')
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_visa_dankort_detected_as_visa
|
308
|
+
assert_equal 'visa', CreditCard.type?('4571100000000000')
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_electron_dk_detected_as_visa
|
312
|
+
assert_equal 'visa', CreditCard.type?('4175001000000000')
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_detect_diners_club
|
316
|
+
assert_equal 'diners_club', CreditCard.type?('36148010000000')
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_detect_diners_club_dk
|
320
|
+
assert_equal 'diners_club', CreditCard.type?('30401000000000')
|
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')
|
364
|
+
end
|
365
|
+
end
|