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,67 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class ChronopayHelperTest < Test::Unit::TestCase
4
+ include ActiveMerchant::Billing::Integrations
5
+
6
+ def setup
7
+ @helper = Chronopay::Helper.new('order-500','003176-0001-0001', :amount => 500, :currency => 'CAD')
8
+ end
9
+
10
+ def test_basic_helper_fields
11
+ assert_field 'cs1', 'order-500'
12
+ assert_field 'product_id', '003176-0001-0001'
13
+ assert_field 'product_price', '500'
14
+ assert_field 'product_price_currency', 'CAD'
15
+ end
16
+
17
+ def test_customer_fields
18
+ @helper.customer :first_name => 'Cody', :last_name => 'Fauser'
19
+ assert_field 'f_name', 'Cody'
20
+ assert_field 's_name', 'Fauser'
21
+ end
22
+
23
+ def test_address_mapping
24
+ @helper.billing_address :country => 'CAN',
25
+ :address1 => '1 My Street',
26
+ :city => 'Ottawa',
27
+ :state => 'On',
28
+ :zip => '90210'
29
+
30
+ assert_field 'country', 'CAN'
31
+ assert_field 'street', '1 My Street'
32
+ assert_field 'state', 'On'
33
+ assert_field 'zip', '90210'
34
+ end
35
+
36
+ def test_country_code_mapping
37
+ @helper.billing_address :country => 'CA'
38
+ assert_field 'country', 'CAN'
39
+ end
40
+
41
+ def test_province_code_mapping_non_us
42
+ @helper.billing_address :country => 'DE', :state => 'Berlin'
43
+ assert_field 'country', 'DEU'
44
+ assert_field 'state', 'XX'
45
+ end
46
+
47
+ def test_state_code_mapping_us
48
+ @helper.billing_address :country => 'US', :state => 'CA'
49
+ assert_field 'country', 'USA'
50
+ assert_field 'state', 'CA'
51
+ end
52
+
53
+ def test_unknown_mapping
54
+ assert_nothing_raised do
55
+ @helper.company_address :address => '500 Dwemthy Fox Road'
56
+ end
57
+ end
58
+
59
+ def test_setting_invalid_address_field
60
+ fields = @helper.fields.dup
61
+ @helper.billing_address :street => 'My Street'
62
+
63
+ # Will still set the state code to 'XX'
64
+ fields['state'] = 'XX'
65
+ assert_equal fields, @helper.fields
66
+ end
67
+ end
@@ -0,0 +1,100 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class GestpayHelperTest < Test::Unit::TestCase
4
+ include ActiveMerchant::Billing::Integrations
5
+
6
+ def setup
7
+ @helper = Gestpay::Helper.new('order-500','1234567', :amount => '5.00', :currency => 'EUR')
8
+ end
9
+
10
+ def test_basic_helper_fields
11
+ assert_field 'ShopLogin', '1234567'
12
+ assert_field 'PAY1_AMOUNT', '5.00'
13
+ assert_field 'PAY1_SHOPTRANSACTIONID', 'order-500'
14
+ assert_field 'PAY1_UICCODE', '242'
15
+ end
16
+
17
+ def test_italian_currency
18
+ @helper = Gestpay::Helper.new('order-500','1234567', :amount => '5.00', :currency => 'ITL')
19
+ assert_field 'PAY1_UICCODE', '18'
20
+ end
21
+
22
+ def test_invalid_currency
23
+ assert_raise(StandardError) do
24
+ Gestpay::Helper.new('order-500','1234567', :amount => '5.00', :currency => 'CAD')
25
+ end
26
+ end
27
+
28
+ def test_customer_fields
29
+ @helper.customer :first_name => 'Cody', :last_name => 'Fauser', :email => 'cody@example.com'
30
+ assert_field 'PAY1_CHNAME', 'Cody Fauser'
31
+ assert_field 'PAY1_CHEMAIL', 'cody@example.com'
32
+ end
33
+
34
+ def test_get_encryption_string
35
+ @helper.expects(:ssl_get).returns(encrypted_string_response)
36
+ assert_equal encrypted_string, @helper.send(:get_encrypted_string)
37
+ end
38
+
39
+ def test_get_encryption_string_fails
40
+ @helper.expects(:ssl_get).returns('#error#1132-Not accepted call: shop is not in active state#/error#\r\n')
41
+
42
+ assert_raise(StandardError) do
43
+ @helper.send(:get_encrypted_string)
44
+ end
45
+ end
46
+
47
+ def test_get_encryption_string_returns_empty_response
48
+ @helper.expects(:ssl_get).returns('')
49
+
50
+ assert_raise(StandardError) do
51
+ @helper.send(:get_encrypted_string)
52
+ end
53
+ end
54
+
55
+ def test_form_fields
56
+ @helper.expects(:ssl_get).returns(encrypted_string_response)
57
+ assert_equal '1234567', @helper.form_fields['a']
58
+ assert_equal encrypted_string, @helper.form_fields['b']
59
+ end
60
+
61
+ # Doesn't do any address mapping
62
+ def test_address_mapping
63
+ assert_nothing_raised do
64
+ @helper.billing_address :address1 => '1 My Street',
65
+ :address2 => '',
66
+ :city => 'Leeds',
67
+ :state => 'Yorkshire',
68
+ :zip => 'LS2 7EE',
69
+ :country => 'CA'
70
+ end
71
+ end
72
+
73
+ def test_unknown_address_mapping
74
+ total_fields = @helper.fields.size
75
+ @helper.billing_address :farm => 'CA'
76
+ assert_equal total_fields, @helper.fields.size
77
+ end
78
+
79
+ def test_unknown_mapping
80
+ assert_nothing_raised do
81
+ @helper.company_address :address => '500 Dwemthy Fox Road'
82
+ end
83
+ end
84
+
85
+ def test_setting_invalid_address_field
86
+ fields = @helper.fields.dup
87
+ @helper.billing_address :street => 'My Street'
88
+ assert_equal fields, @helper.fields
89
+ end
90
+
91
+ private
92
+
93
+ def encrypted_string_response
94
+ '#cryptstring#F7DEB36478FD84760F9134F23C922697272D57DE6D4518EB9B4D468B769D9A3A8071B6EB160B35CB412FC1820C7CC12D17B3141855B1ED55468613702A2E213DDE9DE5B0209E13C416448AE833525959F05693172D7F0656#/cryptstring#'
95
+ end
96
+
97
+ def encrypted_string
98
+ 'F7DEB36478FD84760F9134F23C922697272D57DE6D4518EB9B4D468B769D9A3A8071B6EB160B35CB412FC1820C7CC12D17B3141855B1ED55468613702A2E213DDE9DE5B0209E13C416448AE833525959F05693172D7F0656'
99
+ end
100
+ end
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class NochexHelperTest < Test::Unit::TestCase
4
+ include ActiveMerchant::Billing::Integrations
5
+
6
+ def setup
7
+ @helper = Nochex::Helper.new('order-500','cody@example.com', :amount => 500, :currency => 'GBP')
8
+ end
9
+
10
+ def test_basic_helper_fields
11
+ assert_field 'email', 'cody@example.com'
12
+
13
+ # Nochex requires 2 decimal places on the amount
14
+ assert_field 'amount', '5.00'
15
+ assert_field 'ordernumber', 'order-500'
16
+ end
17
+
18
+ def test_customer_fields
19
+ @helper.customer :first_name => 'Cody', :last_name => 'Fauser', :email => 'cody@example.com'
20
+ assert_field 'firstname', 'Cody'
21
+ assert_field 'lastname', 'Fauser'
22
+ assert_field 'email_address_sender', 'cody@example.com'
23
+ end
24
+
25
+ def test_address_mapping
26
+ @helper.billing_address :address1 => '1 My Street',
27
+ :city => 'Leeds',
28
+ :state => 'Yorkshire',
29
+ :zip => 'LS2 7EE'
30
+
31
+ assert_field 'firstline', '1 My Street'
32
+ assert_field 'town', 'Leeds'
33
+ assert_field 'county', 'Yorkshire'
34
+ assert_field 'postcode', 'LS2 7EE'
35
+ end
36
+
37
+ def test_unknown_address_mapping
38
+ @helper.billing_address :country => 'CA'
39
+ assert_equal 3, @helper.fields.size
40
+ end
41
+
42
+ def test_unknown_mapping
43
+ assert_nothing_raised do
44
+ @helper.company_address :address => '500 Dwemthy Fox Road'
45
+ end
46
+ end
47
+
48
+ def test_setting_invalid_address_field
49
+ fields = @helper.fields.dup
50
+ @helper.billing_address :street => 'My Street'
51
+ assert_equal fields, @helper.fields
52
+ end
53
+ end
@@ -0,0 +1,162 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class PaypalHelperTest < Test::Unit::TestCase
4
+ include ActiveMerchant::Billing::Integrations
5
+
6
+ def setup
7
+ @helper = Paypal::Helper.new(1,'cody@example.com', :amount => 500, :currency => 'CAD')
8
+ @url = 'http://example.com'
9
+ end
10
+
11
+ def test_static_fields
12
+ assert_field 'cmd', '_ext-enter'
13
+ assert_field 'redirect_cmd', '_xclick'
14
+ assert_field 'quantity', '1'
15
+ assert_field 'item_name', 'Store purchase'
16
+ assert_field 'no_shipping', '1'
17
+ assert_field 'no_note', '1'
18
+ assert_field 'charset', 'utf-8'
19
+ end
20
+
21
+ def test_basic_helper_fields
22
+ assert_field 'item_number', '1'
23
+ assert_field 'custom', '1'
24
+ assert_field 'business', 'cody@example.com'
25
+ assert_field 'amount', '500'
26
+ assert_field 'currency_code', 'CAD'
27
+ end
28
+
29
+ def test_invoice
30
+ @helper.invoice = 'Shopify shirt'
31
+ assert_field 'invoice', 'Shopify shirt'
32
+ end
33
+
34
+ def test_notification_url
35
+ @helper.notify_url = @url
36
+ assert_field 'notify_url', @url
37
+ end
38
+
39
+ def test_return_url
40
+ @helper.return_url = @url
41
+ assert_field 'return', @url
42
+ end
43
+
44
+ def test_cancel_return_url
45
+ @helper.cancel_return_url = @url
46
+ assert_field 'cancel_return', @url
47
+ end
48
+
49
+ def test_customer_fields
50
+ @helper.customer :first_name => 'Cody',
51
+ :last_name => 'Fauser',
52
+ :email => 'cody@example.com'
53
+
54
+ assert_field 'first_name', 'Cody'
55
+ assert_field 'last_name', 'Fauser'
56
+ assert_field 'email', 'cody@example.com'
57
+ end
58
+
59
+ def test_shipping_address
60
+ @helper.shipping_address :country => 'CA',
61
+ :address1 => '1 My Street',
62
+ :city => 'Ottawa',
63
+ :zip => '90210',
64
+ :phone => '(555)123-4567'
65
+
66
+ assert_field 'country', 'CA'
67
+ assert_field 'address1', '1 My Street'
68
+ assert_field 'zip', '90210'
69
+ assert_field 'night_phone_a', '555'
70
+ assert_field 'night_phone_b', '123'
71
+ assert_field 'night_phone_c', '4567'
72
+ end
73
+
74
+ def test_phone_parsing
75
+ @helper.shipping_address :phone => '111-222-3333'
76
+
77
+ assert_field 'night_phone_a', '111'
78
+ assert_field 'night_phone_b', '222'
79
+ assert_field 'night_phone_c', '3333'
80
+ end
81
+
82
+
83
+ def test_province
84
+ @helper.shipping_address :country => 'CA',
85
+ :state => 'On'
86
+
87
+ assert_field 'country', 'CA'
88
+ assert_field 'state', 'Ontario'
89
+ end
90
+
91
+ def test_state
92
+ @helper.shipping_address :country => 'US',
93
+ :state => 'TX'
94
+
95
+ assert_field 'country', 'US'
96
+ assert_field 'state', 'TX'
97
+ end
98
+
99
+ def test_shipping
100
+ @helper.shipping '7.99'
101
+ assert_field 'shipping', '7.99'
102
+ end
103
+
104
+ def test_tax
105
+ @helper.tax '14.99'
106
+ assert_field 'tax', '14.99'
107
+ end
108
+
109
+ def test_country_code
110
+ @helper.shipping_address :country => 'CAN'
111
+ assert_field 'country', 'CA'
112
+ end
113
+
114
+ def test_setting_invalid_address_field
115
+ fields = @helper.fields.dup
116
+ fields["state"] = 'N/A'
117
+
118
+ @helper.shipping_address :street => 'My Street'
119
+ assert_equal fields, @helper.fields
120
+ end
121
+
122
+ def test_setting_item_name
123
+ @helper.item_name = 'Really Cool Gizmo'
124
+ assert_field 'item_name', 'Really Cool Gizmo'
125
+ end
126
+
127
+ def test_setting_quantity
128
+ @helper.quantity = '10'
129
+ assert_field 'quantity', '10'
130
+ end
131
+
132
+ def test_setting_no_shipping
133
+ @helper.no_shipping = '0'
134
+ assert_field 'no_shipping', '0'
135
+ end
136
+
137
+ def test_setting_no_note
138
+ @helper.no_note = '0'
139
+ assert_field 'no_note', '0'
140
+ end
141
+
142
+ def test_uk_shipping_address_with_no_state
143
+ @helper.shipping_address :country => 'GB',
144
+ :state => ''
145
+
146
+ assert_field 'state', 'N/A'
147
+ end
148
+
149
+ def test_default_bn
150
+ assert_field 'bn', ActiveMerchant::Billing::Integrations::Helper.application_id
151
+ end
152
+
153
+ def test_override_bn
154
+ identifier = 'CodeGenies_ShoppingCart_IC_CA'
155
+
156
+ Paypal::Helper.application_id = identifier
157
+
158
+ @helper = Paypal::Helper.new(1,'cody@example.com', :amount => 500, :currency => 'CAD')
159
+ assert_field 'bn', identifier
160
+ end
161
+
162
+ end
@@ -0,0 +1,92 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class TwoCheckoutHelperTest < Test::Unit::TestCase
4
+ include ActiveMerchant::Billing::Integrations
5
+
6
+ def setup
7
+ @helper = TwoCheckout::Helper.new('order-500','cody@example.com', :amount => '5.00', :currency => 'USD')
8
+ end
9
+
10
+ def teardown
11
+ ActiveMerchant::Billing::Base.integration_mode = :test
12
+ end
13
+
14
+ def test_basic_helper_fields
15
+ assert_field 'sid', 'cody@example.com'
16
+
17
+ assert_field 'total', '5.00'
18
+ assert_field 'cart_order_id', 'order-500'
19
+ end
20
+
21
+ def test_customer_fields
22
+ @helper.customer :first_name => 'Cody', :last_name => 'Fauser', :email => 'cody@example.com', :phone => '(555)555-5555'
23
+ assert_field 'card_holder_name', 'Cody Fauser'
24
+ assert_field 'email', 'cody@example.com'
25
+ assert_field 'phone', '(555)555-5555'
26
+ end
27
+
28
+ def test_address_mapping
29
+ @helper.billing_address :address1 => '1 My Street',
30
+ :address2 => 'Apt. 1',
31
+ :city => 'Leeds',
32
+ :state => 'Yorkshire',
33
+ :zip => 'LS2 7EE',
34
+ :country => 'CA'
35
+
36
+ assert_field 'street_address', '1 My Street'
37
+ assert_field 'street_address2', 'Apt. 1'
38
+ assert_field 'city', 'Leeds'
39
+ assert_field 'state', 'Yorkshire'
40
+ assert_field 'zip', 'LS2 7EE'
41
+ assert_field 'country', 'CA'
42
+ end
43
+
44
+ def test_shipping_address
45
+ @helper.shipping_address :address1 => '1 My Street',
46
+ :address2 => 'Apt. 1',
47
+ :city => 'London',
48
+ :state => 'Whales',
49
+ :zip => 'LS2 7E1',
50
+ :country => 'UK'
51
+
52
+ assert_field 'ship_city', 'London'
53
+ assert_field 'ship_street_address', '1 My Street'
54
+ assert_field 'ship_state', 'Whales'
55
+ assert_field 'ship_zip', 'LS2 7E1'
56
+ assert_field 'ship_country', 'UK'
57
+ end
58
+
59
+ def test_unknown_address_mapping
60
+ @helper.billing_address :farm => 'CA'
61
+ assert_equal 5, @helper.fields.size
62
+ end
63
+
64
+ def test_unknown_mapping
65
+ assert_nothing_raised do
66
+ @helper.company_address :address => '500 Dwemthy Fox Road'
67
+ end
68
+ end
69
+
70
+ def test_setting_invalid_address_field
71
+ fields = @helper.fields.dup
72
+ @helper.billing_address :street => 'My Street'
73
+ assert_equal fields, @helper.fields
74
+ end
75
+
76
+ def test_test_mode
77
+ @helper = TwoCheckout::Helper.new('order-500','cody@example.com', :amount => '5.00', :currency => 'USD')
78
+ assert_field 'demo', 'Y'
79
+ end
80
+
81
+ def test_force_test_mode
82
+ ActiveMerchant::Billing::Base.integration_mode = :production
83
+ @helper = TwoCheckout::Helper.new('order-500','cody@example.com', :amount => '5.00', :currency => 'USD', :test => true)
84
+ assert_field 'demo', 'Y'
85
+ end
86
+
87
+ def test_production_mode
88
+ ActiveMerchant::Billing::Base.integration_mode = :production
89
+ @helper = TwoCheckout::Helper.new('order-500','cody@example.com', :amount => '5.00', :currency => 'USD')
90
+ assert !@helper.fields.has_key?("demo")
91
+ end
92
+ end