activemerchant 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +226 -0
  3. data/CONTRIBUTERS +52 -0
  4. data/README +34 -24
  5. data/Rakefile +152 -0
  6. data/gem-public_cert.pem +20 -0
  7. data/init.rb +3 -0
  8. data/lib/active_merchant.rb +3 -1
  9. data/lib/active_merchant/billing/credit_card.rb +21 -17
  10. data/lib/active_merchant/billing/credit_card_methods.rb +17 -19
  11. data/lib/active_merchant/billing/gateway.rb +160 -44
  12. data/lib/active_merchant/billing/gateways.rb +2 -15
  13. data/lib/active_merchant/billing/gateways/authorize_net.rb +21 -21
  14. data/lib/active_merchant/billing/gateways/bogus.rb +6 -6
  15. data/lib/active_merchant/billing/gateways/brain_tree.rb +191 -0
  16. data/lib/active_merchant/billing/gateways/card_stream.rb +207 -0
  17. data/lib/active_merchant/billing/gateways/cyber_source.rb +402 -0
  18. data/lib/active_merchant/billing/gateways/data_cash.rb +41 -97
  19. data/lib/active_merchant/billing/gateways/efsnet.rb +256 -0
  20. data/lib/active_merchant/billing/gateways/eway.rb +77 -29
  21. data/lib/active_merchant/billing/gateways/exact.rb +230 -0
  22. data/lib/active_merchant/billing/gateways/linkpoint.rb +6 -33
  23. data/lib/active_merchant/billing/gateways/moneris.rb +155 -125
  24. data/lib/active_merchant/billing/gateways/net_registry.rb +257 -0
  25. data/lib/active_merchant/billing/gateways/pay_junction.rb +407 -0
  26. data/lib/active_merchant/billing/gateways/payflow.rb +163 -25
  27. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +56 -38
  28. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +10 -1
  29. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +9 -0
  30. data/lib/active_merchant/billing/gateways/payflow_express.rb +36 -11
  31. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +6 -0
  32. data/lib/active_merchant/billing/gateways/payflow_uk.rb +7 -3
  33. data/lib/active_merchant/billing/gateways/payment_express.rb +261 -0
  34. data/lib/active_merchant/billing/gateways/paypal.rb +18 -4
  35. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +31 -15
  36. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +8 -0
  37. data/lib/active_merchant/billing/gateways/paypal_express.rb +33 -8
  38. data/lib/active_merchant/billing/gateways/plugnpay.rb +300 -0
  39. data/lib/active_merchant/billing/gateways/protx.rb +285 -0
  40. data/lib/active_merchant/billing/gateways/psigate.rb +13 -12
  41. data/lib/active_merchant/billing/gateways/psl_card.rb +297 -0
  42. data/lib/active_merchant/billing/gateways/quickpay.rb +197 -0
  43. data/lib/active_merchant/billing/gateways/realex.rb +212 -0
  44. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  45. data/lib/active_merchant/billing/gateways/trans_first.rb +136 -0
  46. data/lib/active_merchant/billing/gateways/trust_commerce.rb +43 -20
  47. data/lib/active_merchant/billing/gateways/usa_epay.rb +6 -5
  48. data/lib/active_merchant/billing/gateways/verifi.rb +235 -0
  49. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  50. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +0 -2
  51. data/lib/active_merchant/billing/integrations/helper.rb +8 -1
  52. data/lib/active_merchant/billing/integrations/nochex.rb +62 -1
  53. data/lib/active_merchant/billing/integrations/nochex/notification.rb +9 -16
  54. data/lib/active_merchant/billing/integrations/notification.rb +1 -1
  55. data/lib/active_merchant/billing/integrations/paypal/helper.rb +59 -46
  56. data/lib/active_merchant/billing/integrations/paypal/notification.rb +14 -47
  57. data/lib/active_merchant/lib/error.rb +4 -0
  58. data/lib/active_merchant/lib/post_data.rb +22 -0
  59. data/lib/active_merchant/lib/posts_data.rb +23 -5
  60. data/lib/active_merchant/lib/requires_parameters.rb +2 -2
  61. data/lib/active_merchant/lib/validateable.rb +1 -1
  62. data/lib/support/gateway_support.rb +45 -0
  63. data/lib/tasks/cia.rb +1 -1
  64. data/script/generate +14 -0
  65. data/script/generator/base.rb +45 -0
  66. data/script/generator/generator.rb +24 -0
  67. data/script/generator/generators/gateway/gateway_generator.rb +14 -0
  68. data/script/generator/generators/gateway/templates/gateway.rb +73 -0
  69. data/script/generator/generators/gateway/templates/gateway_test.rb +41 -0
  70. data/script/generator/generators/gateway/templates/remote_gateway_test.rb +56 -0
  71. data/script/generator/generators/integration/integration_generator.rb +25 -0
  72. data/script/generator/generators/integration/templates/helper.rb +34 -0
  73. data/script/generator/generators/integration/templates/helper_test.rb +54 -0
  74. data/script/generator/generators/integration/templates/integration.rb +18 -0
  75. data/script/generator/generators/integration/templates/module_test.rb +9 -0
  76. data/script/generator/generators/integration/templates/notification.rb +100 -0
  77. data/script/generator/generators/integration/templates/notification_test.rb +41 -0
  78. data/script/generator/manifest.rb +20 -0
  79. data/test/extra/binding_of_caller.rb +80 -0
  80. data/test/extra/breakpoint.rb +547 -0
  81. data/test/fixtures.yml +251 -0
  82. data/test/remote_tests/remote_authorize_net_test.rb +113 -0
  83. data/test/remote_tests/remote_brain_tree_test.rb +78 -0
  84. data/test/remote_tests/remote_card_stream_test.rb +160 -0
  85. data/test/remote_tests/remote_cyber_source_test.rb +130 -0
  86. data/test/remote_tests/remote_data_cash_test.rb +155 -0
  87. data/test/remote_tests/remote_efsnet_test.rb +93 -0
  88. data/test/remote_tests/remote_eway_test.rb +71 -0
  89. data/test/remote_tests/remote_exact_test.rb +59 -0
  90. data/test/remote_tests/remote_gestpay_integration_test.rb +37 -0
  91. data/test/remote_tests/remote_linkpoint_test.rb +144 -0
  92. data/test/remote_tests/remote_moneris_test.rb +110 -0
  93. data/test/remote_tests/remote_net_registry_test.rb +120 -0
  94. data/test/remote_tests/remote_pay_junction_test.rb +162 -0
  95. data/test/remote_tests/remote_payflow_express_test.rb +50 -0
  96. data/test/remote_tests/remote_payflow_test.rb +241 -0
  97. data/test/remote_tests/remote_payflow_uk_test.rb +172 -0
  98. data/test/remote_tests/remote_payment_express_test.rb +136 -0
  99. data/test/remote_tests/remote_paypal_express_test.rb +49 -0
  100. data/test/remote_tests/remote_paypal_integration_test.rb +14 -0
  101. data/test/remote_tests/remote_paypal_test.rb +163 -0
  102. data/test/remote_tests/remote_plugnpay_test.rb +70 -0
  103. data/test/remote_tests/remote_protx_test.rb +184 -0
  104. data/test/remote_tests/remote_psigate_test.rb +87 -0
  105. data/test/remote_tests/remote_psl_card_test.rb +105 -0
  106. data/test/remote_tests/remote_quickpay_test.rb +182 -0
  107. data/test/remote_tests/remote_realex_test.rb +227 -0
  108. data/test/remote_tests/remote_secure_pay_test.rb +36 -0
  109. data/test/remote_tests/remote_trans_first_test.rb +37 -0
  110. data/test/remote_tests/remote_trust_commerce_test.rb +136 -0
  111. data/test/remote_tests/remote_usa_epay_test.rb +57 -0
  112. data/test/remote_tests/remote_verifi_test.rb +107 -0
  113. data/test/remote_tests/remote_viaklix_test.rb +53 -0
  114. data/test/test_helper.rb +132 -0
  115. data/test/unit/base_test.rb +61 -0
  116. data/test/unit/country_code_test.rb +33 -0
  117. data/test/unit/country_test.rb +64 -0
  118. data/test/unit/credit_card_formatting_test.rb +24 -0
  119. data/test/unit/credit_card_methods_test.rb +37 -0
  120. data/test/unit/credit_card_test.rb +365 -0
  121. data/test/unit/gateways/authorize_net_test.rb +140 -0
  122. data/test/unit/gateways/bogus_test.rb +43 -0
  123. data/test/unit/gateways/brain_tree_test.rb +77 -0
  124. data/test/unit/gateways/card_stream_test.rb +37 -0
  125. data/test/unit/gateways/cyber_source_test.rb +151 -0
  126. data/test/unit/gateways/data_cash_test.rb +23 -0
  127. data/test/unit/gateways/efsnet_test.rb +70 -0
  128. data/test/unit/gateways/eway_test.rb +105 -0
  129. data/test/unit/gateways/exact_test.rb +118 -0
  130. data/test/unit/gateways/gateway_test.rb +24 -0
  131. data/test/unit/gateways/linkpoint_test.rb +165 -0
  132. data/test/unit/gateways/moneris_test.rb +167 -0
  133. data/test/unit/gateways/net_registry_test.rb +478 -0
  134. data/test/unit/gateways/pay_junction_test.rb +61 -0
  135. data/test/unit/gateways/payflow_express_test.rb +165 -0
  136. data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
  137. data/test/unit/gateways/payflow_test.rb +230 -0
  138. data/test/unit/gateways/payflow_uk_test.rb +68 -0
  139. data/test/unit/gateways/payment_express_test.rb +215 -0
  140. data/test/unit/gateways/paypal_express_test.rb +222 -0
  141. data/test/unit/gateways/paypal_test.rb +241 -0
  142. data/test/unit/gateways/plugnpay_test.rb +79 -0
  143. data/test/unit/gateways/protx_test.rb +110 -0
  144. data/test/unit/gateways/psigate_test.rb +110 -0
  145. data/test/unit/gateways/psl_card_test.rb +51 -0
  146. data/test/unit/gateways/quickpay_test.rb +125 -0
  147. data/test/unit/gateways/realex_test.rb +150 -0
  148. data/test/unit/gateways/secure_pay_test.rb +78 -0
  149. data/test/unit/gateways/trans_first_test.rb +125 -0
  150. data/test/unit/gateways/trust_commerce_test.rb +57 -0
  151. data/test/unit/gateways/usa_epay_test.rb +117 -0
  152. data/test/unit/gateways/verifi_test.rb +91 -0
  153. data/test/unit/gateways/viaklix_test.rb +72 -0
  154. data/test/unit/integrations/action_view_helper_test.rb +54 -0
  155. data/test/unit/integrations/bogus_module_test.rb +16 -0
  156. data/test/unit/integrations/chronopay_module_test.rb +9 -0
  157. data/test/unit/integrations/gestpay_module_test.rb +10 -0
  158. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  159. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  160. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  161. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  162. data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
  163. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  164. data/test/unit/integrations/nochex_module_test.rb +9 -0
  165. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  166. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  167. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  168. data/test/unit/integrations/notifications/notification_test.rb +41 -0
  169. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  170. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  171. data/test/unit/integrations/paypal_module_test.rb +24 -0
  172. data/test/unit/integrations/two_checkout_module_test.rb +9 -0
  173. data/test/unit/post_data_test.rb +55 -0
  174. data/test/unit/response_test.rb +14 -0
  175. data/test/unit/validateable_test.rb +56 -0
  176. metadata +160 -7
  177. metadata.gz.sig +0 -0
  178. 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