smulube-activemerchant 1.5.1.1 → 1.5.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/.gitignore +6 -0
  2. data/Rakefile +85 -0
  3. data/generators/gateway/USAGE +5 -0
  4. data/generators/gateway/gateway_generator.rb +61 -0
  5. data/generators/gateway/templates/gateway.rb +77 -0
  6. data/generators/gateway/templates/gateway_test.rb +49 -0
  7. data/generators/gateway/templates/remote_gateway_test.rb +57 -0
  8. data/generators/integration/USAGE +5 -0
  9. data/generators/integration/integration_generator.rb +68 -0
  10. data/generators/integration/templates/helper.rb +34 -0
  11. data/generators/integration/templates/helper_test.rb +54 -0
  12. data/generators/integration/templates/integration.rb +18 -0
  13. data/generators/integration/templates/module_test.rb +9 -0
  14. data/generators/integration/templates/notification.rb +100 -0
  15. data/generators/integration/templates/notification_test.rb +41 -0
  16. data/init.rb +3 -0
  17. data/lib/active_merchant/billing/gateways/payflow_nvp_uk.rb +18 -11
  18. data/lib/active_merchant/version.rb +3 -0
  19. data/lib/active_merchant.rb +1 -0
  20. data/script/destroy +14 -0
  21. data/script/generate +14 -0
  22. data/test/fixtures.yml +355 -0
  23. data/test/remote/gateways/remote_authorize_net_cim_test.rb +460 -0
  24. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  25. data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
  26. data/test/remote/gateways/remote_beanstream_test.rb +150 -0
  27. data/test/remote/gateways/remote_braintree_test.rb +147 -0
  28. data/test/remote/gateways/remote_card_stream_test.rb +148 -0
  29. data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
  30. data/test/remote/gateways/remote_data_cash_test.rb +356 -0
  31. data/test/remote/gateways/remote_efsnet_test.rb +81 -0
  32. data/test/remote/gateways/remote_elavon_test.rb +66 -0
  33. data/test/remote/gateways/remote_eway_test.rb +74 -0
  34. data/test/remote/gateways/remote_exact_test.rb +60 -0
  35. data/test/remote/gateways/remote_first_pay_test.rb +87 -0
  36. data/test/remote/gateways/remote_instapay_test.rb +61 -0
  37. data/test/remote/gateways/remote_jetpay_test.rb +103 -0
  38. data/test/remote/gateways/remote_linkpoint_test.rb +121 -0
  39. data/test/remote/gateways/remote_merchant_e_solutions_test.rb +173 -0
  40. data/test/remote/gateways/remote_merchant_ware_test.rb +113 -0
  41. data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
  42. data/test/remote/gateways/remote_modern_payments_test.rb +57 -0
  43. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  44. data/test/remote/gateways/remote_net_registry_test.rb +85 -0
  45. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  46. data/test/remote/gateways/remote_ogone_test.rb +115 -0
  47. data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
  48. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  49. data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
  50. data/test/remote/gateways/remote_payflow_nvp_uk_test.rb +57 -0
  51. data/test/remote/gateways/remote_payflow_test.rb +237 -0
  52. data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
  53. data/test/remote/gateways/remote_payment_express_test.rb +136 -0
  54. data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
  55. data/test/remote/gateways/remote_paypal_test.rb +191 -0
  56. data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
  57. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  58. data/test/remote/gateways/remote_psl_card_test.rb +123 -0
  59. data/test/remote/gateways/remote_quickpay_test.rb +190 -0
  60. data/test/remote/gateways/remote_realex_test.rb +224 -0
  61. data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
  62. data/test/remote/gateways/remote_sage_pay_test.rb +219 -0
  63. data/test/remote/gateways/remote_sage_test.rb +87 -0
  64. data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
  65. data/test/remote/gateways/remote_sallie_mae_test.rb +51 -0
  66. data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
  67. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  68. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  69. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  70. data/test/remote/gateways/remote_trans_first_test.rb +34 -0
  71. data/test/remote/gateways/remote_transax_test.rb +112 -0
  72. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  73. data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
  74. data/test/remote/gateways/remote_verifi_test.rb +107 -0
  75. data/test/remote/gateways/remote_viaklix_test.rb +43 -0
  76. data/test/remote/gateways/remote_wirecard_test.rb +111 -0
  77. data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
  78. data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
  79. data/test/test_helper.rb +184 -0
  80. data/test/unit/avs_result_test.rb +59 -0
  81. data/test/unit/base_test.rb +54 -0
  82. data/test/unit/check_test.rb +88 -0
  83. data/test/unit/connection_test.rb +129 -0
  84. data/test/unit/country_code_test.rb +33 -0
  85. data/test/unit/country_test.rb +64 -0
  86. data/test/unit/credit_card_formatting_test.rb +19 -0
  87. data/test/unit/credit_card_methods_test.rb +179 -0
  88. data/test/unit/credit_card_test.rb +318 -0
  89. data/test/unit/cvv_result_test.rb +33 -0
  90. data/test/unit/expiry_date_test.rb +32 -0
  91. data/test/unit/gateways/authorize_net_cim_test.rb +676 -0
  92. data/test/unit/gateways/authorize_net_test.rb +290 -0
  93. data/test/unit/gateways/beanstream_interac_test.rb +51 -0
  94. data/test/unit/gateways/beanstream_test.rb +144 -0
  95. data/test/unit/gateways/bogus_test.rb +58 -0
  96. data/test/unit/gateways/braintree_test.rb +118 -0
  97. data/test/unit/gateways/card_stream_test.rb +90 -0
  98. data/test/unit/gateways/cyber_source_test.rb +188 -0
  99. data/test/unit/gateways/data_cash_test.rb +133 -0
  100. data/test/unit/gateways/efsnet_test.rb +123 -0
  101. data/test/unit/gateways/elavon_test.rb +139 -0
  102. data/test/unit/gateways/eway_test.rb +118 -0
  103. data/test/unit/gateways/exact_test.rb +156 -0
  104. data/test/unit/gateways/first_pay_test.rb +125 -0
  105. data/test/unit/gateways/gateway_test.rb +48 -0
  106. data/test/unit/gateways/instapay_test.rb +102 -0
  107. data/test/unit/gateways/jetpay_test.rb +185 -0
  108. data/test/unit/gateways/linkpoint_test.rb +197 -0
  109. data/test/unit/gateways/merchant_e_solutions_test.rb +169 -0
  110. data/test/unit/gateways/merchant_ware_test.rb +188 -0
  111. data/test/unit/gateways/modern_payments_cim_test.rb +162 -0
  112. data/test/unit/gateways/moneris_test.rb +158 -0
  113. data/test/unit/gateways/net_registry_test.rb +416 -0
  114. data/test/unit/gateways/netbilling_test.rb +54 -0
  115. data/test/unit/gateways/ogone_test.rb +319 -0
  116. data/test/unit/gateways/pay_junction_test.rb +123 -0
  117. data/test/unit/gateways/pay_secure_test.rb +71 -0
  118. data/test/unit/gateways/payflow_express_test.rb +173 -0
  119. data/test/unit/gateways/payflow_express_uk_test.rb +86 -0
  120. data/test/unit/gateways/payflow_nvp_uk_test.rb +201 -0
  121. data/test/unit/gateways/payflow_test.rb +305 -0
  122. data/test/unit/gateways/payflow_uk_test.rb +30 -0
  123. data/test/unit/gateways/payment_express_test.rb +195 -0
  124. data/test/unit/gateways/paypal_express_test.rb +382 -0
  125. data/test/unit/gateways/paypal_test.rb +569 -0
  126. data/test/unit/gateways/plugnpay_test.rb +86 -0
  127. data/test/unit/gateways/psigate_test.rb +169 -0
  128. data/test/unit/gateways/psl_card_test.rb +64 -0
  129. data/test/unit/gateways/quickpay_test.rb +112 -0
  130. data/test/unit/gateways/realex_test.rb +151 -0
  131. data/test/unit/gateways/sage_bankcard_test.rb +196 -0
  132. data/test/unit/gateways/sage_pay_test.rb +139 -0
  133. data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
  134. data/test/unit/gateways/sallie_mae_test.rb +53 -0
  135. data/test/unit/gateways/secure_pay_au_test.rb +207 -0
  136. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  137. data/test/unit/gateways/secure_pay_test.rb +101 -0
  138. data/test/unit/gateways/skip_jack_test.rb +228 -0
  139. data/test/unit/gateways/trans_first_test.rb +112 -0
  140. data/test/unit/gateways/trust_commerce_test.rb +90 -0
  141. data/test/unit/gateways/usa_epay_test.rb +128 -0
  142. data/test/unit/gateways/verifi_test.rb +96 -0
  143. data/test/unit/gateways/viaklix_test.rb +78 -0
  144. data/test/unit/gateways/wirecard_test.rb +250 -0
  145. data/test/unit/generators/test_gateway_generator.rb +46 -0
  146. data/test/unit/generators/test_generator_helper.rb +20 -0
  147. data/test/unit/generators/test_integration_generator.rb +53 -0
  148. data/test/unit/integrations/action_view_helper_test.rb +50 -0
  149. data/test/unit/integrations/bogus_module_test.rb +20 -0
  150. data/test/unit/integrations/chronopay_module_test.rb +13 -0
  151. data/test/unit/integrations/gestpay_module_test.rb +14 -0
  152. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  153. data/test/unit/integrations/helpers/chronopay_helper_test.rb +110 -0
  154. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  155. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  156. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  157. data/test/unit/integrations/helpers/paypal_helper_test.rb +171 -0
  158. data/test/unit/integrations/helpers/quickpay_helper_test.rb +40 -0
  159. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  160. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  161. data/test/unit/integrations/nochex_module_test.rb +13 -0
  162. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  163. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  164. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
  165. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  166. data/test/unit/integrations/notifications/notification_test.rb +54 -0
  167. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  168. data/test/unit/integrations/notifications/quickpay_notification_test.rb +69 -0
  169. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  170. data/test/unit/integrations/paypal_module_test.rb +28 -0
  171. data/test/unit/integrations/quickpay_module_test.rb +9 -0
  172. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  173. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  174. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  175. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  176. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  177. data/test/unit/integrations/returns/return_test.rb +11 -0
  178. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  179. data/test/unit/integrations/two_checkout_module_test.rb +13 -0
  180. data/test/unit/post_data_test.rb +55 -0
  181. data/test/unit/posts_data_test.rb +48 -0
  182. data/test/unit/response_test.rb +28 -0
  183. data/test/unit/utils_test.rb +7 -0
  184. data/test/unit/validateable_test.rb +60 -0
  185. data.tar.gz.sig +0 -0
  186. metadata +453 -107
  187. metadata.gz.sig +0 -0
@@ -0,0 +1,460 @@
1
+ require 'test_helper'
2
+ require 'pp'
3
+
4
+ class AuthorizeNetCimTest < Test::Unit::TestCase
5
+ def setup
6
+ Base.mode = :test
7
+
8
+ @gateway = AuthorizeNetCimGateway.new(fixtures(:authorize_net))
9
+ @amount = 100
10
+ @credit_card = credit_card('4242424242424242')
11
+ @payment = {
12
+ :credit_card => @credit_card
13
+ }
14
+ @profile = {
15
+ :merchant_customer_id => 'Up to 20 chars', # Optional
16
+ :description => 'Up to 255 Characters', # Optional
17
+ :email => 'Up to 255 Characters', # Optional
18
+ :payment_profiles => { # Optional
19
+ :customer_type => 'individual', # Optional
20
+ :bill_to => @address,
21
+ :payment => @payment
22
+ },
23
+ :ship_to_list => {
24
+ :first_name => 'John',
25
+ :last_name => 'Doe',
26
+ :company => 'Widgets, Inc',
27
+ :address1 => '1234 Fake Street',
28
+ :city => 'Anytown',
29
+ :state => 'MD',
30
+ :zip => '12345',
31
+ :country => 'USA',
32
+ :phone_number => '(123)123-1234', # Optional - Up to 25 digits (no letters)
33
+ :fax_number => '(123)123-1234' # Optional - Up to 25 digits (no letters)
34
+ }
35
+ }
36
+ @options = {
37
+ :ref_id => '1234', # Optional
38
+ :profile => @profile
39
+ }
40
+ end
41
+
42
+ def teardown
43
+ if @customer_profile_id
44
+ assert response = @gateway.delete_customer_profile(:customer_profile_id => @customer_profile_id)
45
+ assert_success response
46
+ @customer_profile_id = nil
47
+ end
48
+ end
49
+
50
+ def test_successful_profile_create_get_update_and_delete
51
+ assert response = @gateway.create_customer_profile(@options)
52
+ @customer_profile_id = response.authorization
53
+
54
+ assert_success response
55
+ assert response.test?
56
+
57
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
58
+ assert response.test?
59
+ assert_success response
60
+ assert_equal @customer_profile_id, response.authorization
61
+ assert_equal 'Successful.', response.message
62
+ assert response.params['profile']['payment_profiles']['customer_payment_profile_id'] =~ /\d+/, 'The customer_payment_profile_id should be a number'
63
+ assert_equal "XXXX#{@credit_card.last_digits}", response.params['profile']['payment_profiles']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in #{@credit_card.last_digits}"
64
+ assert_equal @profile[:merchant_customer_id], response.params['profile']['merchant_customer_id']
65
+ assert_equal @profile[:description], response.params['profile']['description']
66
+ assert_equal @profile[:email], response.params['profile']['email']
67
+ assert_equal @profile[:payment_profiles][:customer_type], response.params['profile']['payment_profiles']['customer_type']
68
+ assert_equal @profile[:ship_to_list][:phone_number], response.params['profile']['ship_to_list']['phone_number']
69
+ assert_equal @profile[:ship_to_list][:company], response.params['profile']['ship_to_list']['company']
70
+
71
+ assert response = @gateway.update_customer_profile(:profile => {:customer_profile_id => @customer_profile_id, :email => 'new email address'})
72
+ assert response.test?
73
+ assert_success response
74
+ assert_nil response.authorization
75
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
76
+ assert_nil response.params['profile']['merchant_customer_id']
77
+ assert_nil response.params['profile']['description']
78
+ assert_equal 'new email address', response.params['profile']['email']
79
+ end
80
+
81
+ def test_successful_create_customer_profile_transaction_auth_only_and_then_capture_only_requests
82
+ assert response = @gateway.create_customer_profile(@options)
83
+ @customer_profile_id = response.authorization
84
+
85
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
86
+ @customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
87
+
88
+ assert response = @gateway.create_customer_profile_transaction(
89
+ :transaction => {
90
+ :customer_profile_id => @customer_profile_id,
91
+ :customer_payment_profile_id => @customer_payment_profile_id,
92
+ :type => :auth_only,
93
+ :amount => @amount
94
+ }
95
+ )
96
+
97
+ assert response.test?
98
+ assert_success response
99
+ assert_nil response.authorization
100
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
101
+ assert response.params['direct_response']['approval_code'] =~ /\w{6}/
102
+ assert_equal "auth_only", response.params['direct_response']['transaction_type']
103
+ assert_equal "100.00", response.params['direct_response']['amount']
104
+ assert_match /\d+/, response.params['direct_response']['transaction_id']
105
+
106
+ approval_code = response.params['direct_response']['approval_code']
107
+
108
+ # Capture the previously authorized funds
109
+
110
+ assert response = @gateway.create_customer_profile_transaction(
111
+ :transaction => {
112
+ :customer_profile_id => @customer_profile_id,
113
+ :customer_payment_profile_id => @customer_payment_profile_id,
114
+ :type => :capture_only,
115
+ :amount => @amount,
116
+ :approval_code => approval_code
117
+ }
118
+ )
119
+
120
+ assert response.test?
121
+ assert_success response
122
+ assert_nil response.authorization
123
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
124
+ assert_equal approval_code, response.params['direct_response']['approval_code']
125
+ assert_equal "capture_only", response.params['direct_response']['transaction_type']
126
+ assert_equal "100.00", response.params['direct_response']['amount']
127
+ end
128
+
129
+ def test_successful_create_customer_profile_transaction_auth_capture_request
130
+ assert response = @gateway.create_customer_profile(@options)
131
+ @customer_profile_id = response.authorization
132
+
133
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
134
+ @customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
135
+
136
+ assert response = @gateway.create_customer_profile_transaction(
137
+ :transaction => {
138
+ :customer_profile_id => @customer_profile_id,
139
+ :customer_payment_profile_id => @customer_payment_profile_id,
140
+ :type => :auth_capture,
141
+ :order => {
142
+ :invoice_number => '1234',
143
+ :description => 'Test Order Description',
144
+ :purchase_order_number => '4321'
145
+ },
146
+ :amount => @amount
147
+ }
148
+ )
149
+
150
+ assert response.test?
151
+ assert_success response
152
+ assert_nil response.authorization
153
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
154
+ assert response.params['direct_response']['approval_code'] =~ /\w{6}/
155
+ assert_equal "auth_capture", response.params['direct_response']['transaction_type']
156
+ assert_equal "100.00", response.params['direct_response']['amount']
157
+ assert_equal response.params['direct_response']['invoice_number'], '1234'
158
+ assert_equal response.params['direct_response']['order_description'], 'Test Order Description'
159
+ assert_equal response.params['direct_response']['purchase_order_number'], '4321'
160
+ end
161
+
162
+ def test_successful_create_customer_payment_profile_request
163
+ payment_profile = @options[:profile].delete(:payment_profiles)
164
+ assert response = @gateway.create_customer_profile(@options)
165
+ @customer_profile_id = response.authorization
166
+
167
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
168
+ assert_nil response.params['profile']['payment_profiles']
169
+
170
+ assert response = @gateway.create_customer_payment_profile(
171
+ :customer_profile_id => @customer_profile_id,
172
+ :payment_profile => payment_profile
173
+ )
174
+
175
+ assert response.test?
176
+ assert_success response
177
+ assert_nil response.authorization
178
+ assert customer_payment_profile_id = response.params['customer_payment_profile_id']
179
+ assert customer_payment_profile_id =~ /\d+/, "The customerPaymentProfileId should be numeric. It was #{customer_payment_profile_id}"
180
+ end
181
+
182
+ def test_successful_create_customer_payment_profile_request_with_bank_account
183
+ payment_profile = @options[:profile].delete(:payment_profiles)
184
+ assert response = @gateway.create_customer_profile(@options)
185
+ @customer_profile_id = response.authorization
186
+
187
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
188
+ assert_nil response.params['profile']['payment_profiles']
189
+
190
+ assert response = @gateway.create_customer_payment_profile(
191
+ :customer_profile_id => @customer_profile_id,
192
+ :payment_profile => {
193
+ :customer_type => 'individual', # Optional
194
+ :bill_to => @address,
195
+ :payment => {
196
+ :bank_account => {
197
+ :account_type => :checking,
198
+ :name_on_account => 'John Doe',
199
+ :echeck_type => :ccd,
200
+ :bank_name => 'Bank of America',
201
+ :routing_number => '123456789',
202
+ :account_number => '12345'
203
+ }
204
+ },
205
+ :drivers_license => {
206
+ :state => 'MD',
207
+ :number => '12345',
208
+ :date_of_birth => '1981-3-31'
209
+ },
210
+ :tax_id => '123456789'
211
+ }
212
+ )
213
+
214
+ assert response.test?
215
+ assert_success response
216
+ assert_nil response.authorization
217
+ assert customer_payment_profile_id = response.params['customer_payment_profile_id']
218
+ assert customer_payment_profile_id =~ /\d+/, "The customerPaymentProfileId should be numeric. It was #{customer_payment_profile_id}"
219
+ end
220
+
221
+ def test_successful_create_customer_shipping_address_request
222
+ shipping_address = @options[:profile].delete(:ship_to_list)
223
+ assert response = @gateway.create_customer_profile(@options)
224
+ @customer_profile_id = response.authorization
225
+
226
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
227
+ assert_nil response.params['profile']['ship_to_list']
228
+
229
+ assert response = @gateway.create_customer_shipping_address(
230
+ :customer_profile_id => @customer_profile_id,
231
+ :address => shipping_address
232
+ )
233
+
234
+ assert response.test?
235
+ assert_success response
236
+ assert_nil response.authorization
237
+ assert customer_address_id = response.params['customer_address_id']
238
+ assert customer_address_id =~ /\d+/, "The customerAddressId should be numeric. It was #{customer_address_id}"
239
+ end
240
+
241
+ def test_successful_get_customer_profile_with_multiple_payment_profiles
242
+ second_payment_profile = {
243
+ :customer_type => 'individual',
244
+ :bill_to => @address,
245
+ :payment => {
246
+ :credit_card => credit_card('1234123412341234')
247
+ }
248
+ }
249
+ assert response = @gateway.create_customer_profile(@options)
250
+ @customer_profile_id = response.authorization
251
+
252
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
253
+
254
+ assert response = @gateway.create_customer_payment_profile(
255
+ :customer_profile_id => @customer_profile_id,
256
+ :payment_profile => second_payment_profile
257
+ )
258
+
259
+ assert response.test?
260
+ assert_success response
261
+ assert_nil response.authorization
262
+ assert customer_payment_profile_id = response.params['customer_payment_profile_id']
263
+ assert customer_payment_profile_id =~ /\d+/, "The customerPaymentProfileId should be numeric. It was #{customer_payment_profile_id}"
264
+
265
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
266
+ assert_equal 2, response.params['profile']['payment_profiles'].size
267
+ assert_equal 'XXXX4242', response.params['profile']['payment_profiles'][0]['payment']['credit_card']['card_number']
268
+ assert_equal 'XXXX1234', response.params['profile']['payment_profiles'][1]['payment']['credit_card']['card_number']
269
+ end
270
+
271
+ def test_successful_delete_customer_payment_profile_request
272
+ assert response = @gateway.create_customer_profile(@options)
273
+ @customer_profile_id = response.authorization
274
+
275
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
276
+ assert customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
277
+
278
+ assert response = @gateway.delete_customer_payment_profile(
279
+ :customer_profile_id => @customer_profile_id,
280
+ :customer_payment_profile_id => customer_payment_profile_id
281
+ )
282
+
283
+ assert response.test?
284
+ assert_success response
285
+ assert_nil response.authorization
286
+
287
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
288
+ assert_nil response.params['profile']['payment_profiles']
289
+ end
290
+
291
+ def test_successful_delete_customer_shipping_address_request
292
+ assert response = @gateway.create_customer_profile(@options)
293
+ @customer_profile_id = response.authorization
294
+
295
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
296
+ assert customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
297
+
298
+ assert response = @gateway.delete_customer_shipping_address(
299
+ :customer_profile_id => @customer_profile_id,
300
+ :customer_address_id => customer_address_id
301
+ )
302
+
303
+ assert response.test?
304
+ assert_success response
305
+ assert_nil response.authorization
306
+
307
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
308
+ assert_nil response.params['profile']['ship_to_list']
309
+ end
310
+
311
+ def test_successful_get_customer_payment_profile_request
312
+ assert response = @gateway.create_customer_profile(@options)
313
+ @customer_profile_id = response.authorization
314
+
315
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
316
+ assert customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
317
+
318
+ assert response = @gateway.get_customer_payment_profile(
319
+ :customer_profile_id => @customer_profile_id,
320
+ :customer_payment_profile_id => customer_payment_profile_id
321
+ )
322
+
323
+ assert response.test?
324
+ assert_success response
325
+ assert_nil response.authorization
326
+ assert response.params['payment_profile']['customer_payment_profile_id'] =~ /\d+/, 'The customer_payment_profile_id should be a number'
327
+ assert_equal "XXXX#{@credit_card.last_digits}", response.params['payment_profile']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in #{@credit_card.last_digits}"
328
+ assert_equal @profile[:payment_profiles][:customer_type], response.params['payment_profile']['customer_type']
329
+ end
330
+
331
+ def test_successful_get_customer_shipping_address_request
332
+ assert response = @gateway.create_customer_profile(@options)
333
+ @customer_profile_id = response.authorization
334
+
335
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
336
+ assert customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
337
+
338
+ assert response = @gateway.get_customer_shipping_address(
339
+ :customer_profile_id => @customer_profile_id,
340
+ :customer_address_id => customer_address_id
341
+ )
342
+
343
+ assert response.test?
344
+ assert_success response
345
+ assert_nil response.authorization
346
+ assert response.params['address']['customer_address_id'] =~ /\d+/, 'The customer_address_id should be a number'
347
+ assert_equal @profile[:ship_to_list][:city], response.params['address']['city']
348
+ end
349
+
350
+ def test_successful_update_customer_payment_profile_request
351
+ # Create a new Customer Profile with Payment Profile
352
+ assert response = @gateway.create_customer_profile(@options)
353
+ @customer_profile_id = response.authorization
354
+
355
+ # Get the customerPaymentProfileId
356
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
357
+ assert customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
358
+
359
+ # Get the customerPaymentProfile
360
+ assert response = @gateway.get_customer_payment_profile(
361
+ :customer_profile_id => @customer_profile_id,
362
+ :customer_payment_profile_id => customer_payment_profile_id
363
+ )
364
+
365
+ # The value before updating
366
+ assert_equal "XXXX4242", response.params['payment_profile']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in 4242"
367
+
368
+ #Update the payment profile
369
+ assert response = @gateway.update_customer_payment_profile(
370
+ :customer_profile_id => @customer_profile_id,
371
+ :payment_profile => {
372
+ :customer_payment_profile_id => customer_payment_profile_id,
373
+ :payment => {
374
+ :credit_card => credit_card('1234123412341234')
375
+ }
376
+ }
377
+ )
378
+ assert response.test?
379
+ assert_success response
380
+ assert_nil response.authorization
381
+
382
+ # Get the updated payment profile
383
+ assert response = @gateway.get_customer_payment_profile(
384
+ :customer_profile_id => @customer_profile_id,
385
+ :customer_payment_profile_id => customer_payment_profile_id
386
+ )
387
+
388
+ # Show that the payment profile was updated
389
+ assert_equal "XXXX1234", response.params['payment_profile']['payment']['credit_card']['card_number'], "The card number should contain the last 4 digits of the card we passed in: 1234"
390
+ # Show that fields that were left out of the update were cleared
391
+ assert_nil response.params['payment_profile']['customer_type']
392
+ end
393
+
394
+ def test_successful_update_customer_shipping_address_request
395
+ # Create a new Customer Profile with Shipping Address
396
+ assert response = @gateway.create_customer_profile(@options)
397
+ @customer_profile_id = response.authorization
398
+
399
+ # Get the customerAddressId
400
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
401
+ assert customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
402
+
403
+ # Get the customerShippingAddress
404
+ assert response = @gateway.get_customer_shipping_address(
405
+ :customer_profile_id => @customer_profile_id,
406
+ :customer_address_id => customer_address_id
407
+ )
408
+
409
+ assert address = response.params['address']
410
+ # The value before updating
411
+ assert_equal "1234 Fake Street", address['address']
412
+
413
+ # Update the address and remove the phone_number
414
+ new_address = address.symbolize_keys.merge!(
415
+ :address => '5678 Fake Street'
416
+ )
417
+ new_address.delete(:phone_number)
418
+
419
+ #Update the shipping address
420
+ assert response = @gateway.update_customer_shipping_address(
421
+ :customer_profile_id => @customer_profile_id,
422
+ :address => new_address
423
+ )
424
+ assert response.test?
425
+ assert_success response
426
+ assert_nil response.authorization
427
+
428
+ # Get the updated shipping address
429
+ assert response = @gateway.get_customer_shipping_address(
430
+ :customer_profile_id => @customer_profile_id,
431
+ :customer_address_id => customer_address_id
432
+ )
433
+
434
+ # Show that the shipping address was updated
435
+ assert_equal "5678 Fake Street", response.params['address']['address']
436
+ # Show that fields that were left out of the update were cleared
437
+ assert_nil response.params['address']['phone_number']
438
+ end
439
+
440
+ def test_successful_validate_customer_payment_profile_request
441
+ assert response = @gateway.create_customer_profile(@options)
442
+ @customer_profile_id = response.authorization
443
+
444
+ assert response = @gateway.get_customer_profile(:customer_profile_id => @customer_profile_id)
445
+ assert @customer_payment_profile_id = response.params['profile']['payment_profiles']['customer_payment_profile_id']
446
+ assert @customer_address_id = response.params['profile']['ship_to_list']['customer_address_id']
447
+
448
+ assert response = @gateway.validate_customer_payment_profile(
449
+ :customer_profile_id => @customer_profile_id,
450
+ :customer_payment_profile_id => @customer_payment_profile_id,
451
+ :customer_address_id => @customer_address_id,
452
+ :validation_mode => :live
453
+ )
454
+
455
+ assert response.test?
456
+ assert_success response
457
+ assert_nil response.authorization
458
+ assert_equal "This transaction has been approved.", response.params['direct_response']['message']
459
+ end
460
+ end
@@ -0,0 +1,145 @@
1
+ require 'test_helper'
2
+
3
+ class AuthorizeNetTest < Test::Unit::TestCase
4
+ def setup
5
+ Base.mode = :test
6
+
7
+ @gateway = AuthorizeNetGateway.new(fixtures(:authorize_net))
8
+ @amount = 100
9
+ @credit_card = credit_card('4242424242424242')
10
+ @options = {
11
+ :order_id => generate_unique_id,
12
+ :billing_address => address,
13
+ :description => 'Store purchase'
14
+ }
15
+
16
+ @recurring_options = {
17
+ :amount => 100,
18
+ :subscription_name => 'Test Subscription 1',
19
+ :credit_card => @credit_card,
20
+ :billing_address => address.merge(:first_name => 'Jim', :last_name => 'Smith'),
21
+ :interval => {
22
+ :length => 1,
23
+ :unit => :months
24
+ },
25
+ :duration => {
26
+ :start_date => Date.today,
27
+ :occurrences => 1
28
+ }
29
+ }
30
+ end
31
+
32
+ def test_successful_purchase
33
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
34
+ assert_success response
35
+ assert response.test?
36
+ assert_equal 'This transaction has been approved', response.message
37
+ assert response.authorization
38
+ end
39
+
40
+ def test_expired_credit_card
41
+ @credit_card.year = 2004
42
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
43
+ assert_failure response
44
+ assert response.test?
45
+ assert_equal 'The credit card has expired', response.message
46
+ end
47
+
48
+ def test_forced_test_mode_purchase
49
+ gateway = AuthorizeNetGateway.new(fixtures(:authorize_net).update(:test => true))
50
+ assert response = gateway.purchase(@amount, @credit_card, @options)
51
+ assert_success response
52
+ assert response.test?
53
+ assert_match(/TESTMODE/, response.message)
54
+ assert response.authorization
55
+ end
56
+
57
+ def test_successful_authorization
58
+ assert response = @gateway.authorize(@amount, @credit_card, @options)
59
+ assert_success response
60
+ assert_equal 'This transaction has been approved', response.message
61
+ assert response.authorization
62
+ end
63
+
64
+ def test_authorization_and_capture
65
+ assert authorization = @gateway.authorize(@amount, @credit_card, @options)
66
+ assert_success authorization
67
+
68
+ assert capture = @gateway.capture(@amount, authorization.authorization)
69
+ assert_success capture
70
+ assert_equal 'This transaction has been approved', capture.message
71
+ end
72
+
73
+ def test_authorization_and_void
74
+ assert authorization = @gateway.authorize(@amount, @credit_card, @options)
75
+ assert_success authorization
76
+
77
+ assert void = @gateway.void(authorization.authorization)
78
+ assert_success void
79
+ assert_equal 'This transaction has been approved', void.message
80
+ end
81
+
82
+ def test_bad_login
83
+ gateway = AuthorizeNetGateway.new(
84
+ :login => 'X',
85
+ :password => 'Y'
86
+ )
87
+
88
+ assert response = gateway.purchase(@amount, @credit_card)
89
+
90
+ assert_equal Response, response.class
91
+ assert_equal ["avs_result_code",
92
+ "card_code",
93
+ "response_code",
94
+ "response_reason_code",
95
+ "response_reason_text",
96
+ "transaction_id"], response.params.keys.sort
97
+
98
+ assert_match(/The merchant login ID or password is invalid/, response.message)
99
+
100
+ assert_equal false, response.success?
101
+ end
102
+
103
+ def test_using_test_request
104
+ gateway = AuthorizeNetGateway.new(
105
+ :login => 'X',
106
+ :password => 'Y'
107
+ )
108
+
109
+ assert response = gateway.purchase(@amount, @credit_card)
110
+
111
+ assert_equal Response, response.class
112
+ assert_equal ["avs_result_code",
113
+ "card_code",
114
+ "response_code",
115
+ "response_reason_code",
116
+ "response_reason_text",
117
+ "transaction_id"], response.params.keys.sort
118
+
119
+ assert_match(/The merchant login ID or password is invalid/, response.message)
120
+
121
+ assert_equal false, response.success?
122
+ end
123
+
124
+ def test_successful_recurring
125
+ assert response = @gateway.recurring(@amount, @credit_card, @recurring_options)
126
+ assert_success response
127
+ assert response.test?
128
+
129
+ subscription_id = response.authorization
130
+
131
+ assert response = @gateway.update_recurring(:subscription_id => subscription_id, :amount => @amount * 2)
132
+ assert_success response
133
+
134
+ assert response = @gateway.cancel_recurring(subscription_id)
135
+ assert_success response
136
+ end
137
+
138
+ def test_recurring_should_fail_expired_credit_card
139
+ @credit_card.year = 2004
140
+ assert response = @gateway.recurring(@amount, @credit_card, @recurring_options)
141
+ assert_failure response
142
+ assert response.test?
143
+ assert_equal 'E00018', response.params['code']
144
+ end
145
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteBeanstreamInteracTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @gateway = BeanstreamInteracGateway.new(fixtures(:beanstream_interac))
7
+
8
+ @amount = 100
9
+
10
+ @options = {
11
+ :order_id => generate_unique_id,
12
+ :billing_address => {
13
+ :name => 'xiaobo zzz',
14
+ :phone => '555-555-5555',
15
+ :address1 => '1234 Levesque St.',
16
+ :address2 => 'Apt B',
17
+ :city => 'Montreal',
18
+ :state => 'QC',
19
+ :country => 'CA',
20
+ :zip => 'H2C1X8'
21
+ },
22
+ :email => 'xiaobozzz@example.com',
23
+ :subtotal => 800,
24
+ :shipping => 100,
25
+ :tax1 => 100,
26
+ :tax2 => 100,
27
+ :custom => 'reference one'
28
+ }
29
+ end
30
+
31
+ def test_successful_purchase
32
+ assert response = @gateway.purchase(@amount, @options)
33
+ assert_success response
34
+ assert_equal "R", response.params["responseType"]
35
+ assert_false response.redirect.blank?
36
+ end
37
+
38
+ def test_failed_confirmation
39
+ assert response = @gateway.confirm("")
40
+ assert_failure response
41
+ end
42
+
43
+ def test_invalid_login
44
+ gateway = BeanstreamInteracGateway.new(
45
+ :merchant_id => '',
46
+ :login => '',
47
+ :password => ''
48
+ )
49
+ assert response = gateway.purchase(@amount, @options)
50
+ assert_failure response
51
+ assert_equal 'Invalid merchant id (merchant_id = 0)', response.message
52
+ end
53
+ end