Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | ||
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
30 | require_once 'CiviTest/AuthorizeNet.php'; | |
a7d56832 | 31 | |
6a488035 TO |
32 | class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { |
33 | function get_info() { | |
34 | return array( | |
35 | 'name' => 'Authorize.net processing', | |
36 | 'description' => 'Test Authorize.ne methods.', | |
37 | 'group' => 'Payment Processor Tests', | |
38 | ); | |
39 | } | |
40 | ||
41 | function setUp() { | |
42 | parent::setUp(); | |
43 | $this->paymentProcessor = new AuthorizeNet(); | |
44 | $this->processorParams = $this->paymentProcessor->create(); | |
45 | ||
46 | $paymentProcessor = array( | |
47 | 'user_name' => $this->processorParams->user_name, | |
48 | 'password' => $this->processorParams->password, | |
49 | 'url_recur' => $this->processorParams->url_recur, | |
a7d56832 | 50 | 'signature' => '', |
6a488035 TO |
51 | ); |
52 | ||
53 | $this->processor = new CRM_Core_Payment_AuthorizeNet('Contribute', $paymentProcessor); | |
e6ff1593 | 54 | $this->_financialTypeId = 1; |
6a488035 TO |
55 | |
56 | // for some strange unknown reason, in batch mode this value gets set to null | |
57 | // so crude hack here to avoid an exception and hence an error | |
58 | $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array( ); | |
59 | } | |
60 | ||
61 | function tearDown() { | |
62 | $this->paymentProcessor->delete($this->processorParams->id); | |
b38530f2 | 63 | $this->quickCleanUpFinancialEntities(); |
6a488035 TO |
64 | } |
65 | ||
66 | /** | |
67 | * create a single post dated payment as a recurring transaction. | |
68 | * | |
69 | * Test works but not both due to some form of caching going on in the SmartySingleton | |
70 | */ | |
71 | function testCreateSingleNowDated() { | |
72 | $firstName = 'John_' . substr(sha1(rand()), 0, 7); | |
73 | $lastName = 'Smith_' . substr(sha1(rand()), 0, 7); | |
74 | $nameParams = array('first_name' => $firstName, 'last_name' => $lastName); | |
a7d56832 | 75 | $contactId = $this->individualCreate($nameParams); |
6a488035 | 76 | |
6a488035 TO |
77 | $invoiceID = sha1(rand()); |
78 | $amount = rand(100, 1000) . '.00'; | |
79 | ||
80 | $contributionRecurParams = array( | |
81 | 'contact_id' => $contactId, | |
82 | 'amount' => $amount, | |
83 | 'currency' => 'USD', | |
84 | 'frequency_unit' => 'week', | |
85 | 'frequency_interval' => 1, | |
86 | 'installments' => 2, | |
87 | 'start_date' => date('Ymd'), | |
88 | 'create_date' => date('Ymd'), | |
89 | 'invoice_id' => $invoiceID, | |
90 | 'contribution_status_id' => 2, | |
91 | 'is_test' => 1, | |
92 | 'payment_processor_id' => $this->processorParams->id, | |
93 | ); | |
a7d56832 | 94 | $recur = CRM_Contribute_BAO_ContributionRecur::add($contributionRecurParams); |
6a488035 TO |
95 | |
96 | $contributionParams = array( | |
97 | 'contact_id' => $contactId, | |
e6ff1593 | 98 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
99 | 'receive_date' => date('Ymd'), |
100 | 'total_amount' => $amount, | |
101 | 'invoice_id' => $invoiceID, | |
102 | 'currency' => 'USD', | |
103 | 'contribution_recur_id' => $recur->id, | |
104 | 'is_test' => 1, | |
105 | 'contribution_status_id' => 2, | |
106 | ); | |
a7d56832 | 107 | $contribution = CRM_Contribute_BAO_Contribution::add($contributionParams); |
6a488035 TO |
108 | |
109 | $params = array( | |
110 | 'qfKey' => '08ed21c7ca00a1f7d32fff2488596ef7_4454', | |
111 | 'hidden_CreditCard' => 1, | |
112 | 'billing_first_name' => $firstName, | |
113 | 'billing_middle_name' => "", | |
114 | 'billing_last_name' => $lastName, | |
115 | 'billing_street_address-5' => '8 Hobbitton Road', | |
116 | 'billing_city-5' => 'The Shire', | |
117 | 'billing_state_province_id-5' => 1012, | |
118 | 'billing_postal_code-5' => 5010, | |
119 | 'billing_country_id-5' => 1228, | |
120 | 'credit_card_number' => '4007000000027', | |
121 | 'cvv2' => 123, | |
122 | 'credit_card_exp_date' => array( | |
123 | 'M' => 10, | |
124 | 'Y' => 2019, | |
125 | ), | |
126 | 'credit_card_type' => 'Visa', | |
127 | 'is_recur' => 1, | |
128 | 'frequency_interval' => 1, | |
129 | 'frequency_unit' => 'month', | |
130 | 'installments' => 12, | |
e6ff1593 | 131 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
132 | 'is_email_receipt' => 1, |
133 | 'from_email_address' => "{$firstName}.{$lastName}@example.com", | |
134 | 'receive_date' => date('Ymd'), | |
135 | 'receipt_date_time' => '', | |
136 | 'payment_processor_id' => $this->processorParams->id, | |
137 | 'price_set_id' => '', | |
138 | 'total_amount' => $amount, | |
139 | 'currency' => 'USD', | |
140 | 'source' => "Mordor", | |
141 | 'soft_credit_to' => '', | |
142 | 'soft_contact_id' => '', | |
143 | 'billing_state_province-5' => 'IL', | |
144 | 'state_province-5' => 'IL', | |
145 | 'billing_country-5' => 'US', | |
146 | 'country-5' => 'US', | |
147 | 'year' => 2019, | |
148 | 'month' => 10, | |
149 | 'ip_address' => '127.0.0.1', | |
150 | 'amount' => 7, | |
151 | 'amount_level' => 0, | |
152 | 'currencyID' => 'USD', | |
153 | 'pcp_display_in_roll' => "", | |
154 | 'pcp_roll_nickname' => "", | |
155 | 'pcp_personal_note' => "", | |
156 | 'non_deductible_amount' => "", | |
157 | 'fee_amount' => "", | |
158 | 'net_amount' => "", | |
159 | 'invoiceID' => $invoiceID, | |
160 | 'contribution_page_id' => "", | |
161 | 'thankyou_date' => NULL, | |
162 | 'honor_contact_id' => NULL, | |
163 | 'first_name' => $firstName, | |
164 | 'middle_name' => '', | |
165 | 'last_name' => $lastName, | |
166 | 'street_address' => '8 Hobbiton Road', | |
167 | 'city' => 'The Shire', | |
168 | 'state_province' => 'IL', | |
169 | 'postal_code' => 5010, | |
170 | 'country' => 'US', | |
171 | 'contributionType_name' => 'My precious', | |
172 | 'contributionType_accounting_code' => '', | |
173 | 'contributionPageID' => '', | |
174 | 'email' => "{$firstName}.{$lastName}@example.com", | |
175 | 'contactID' => $contactId, | |
176 | 'contributionID' => $contribution->id, | |
e6ff1593 | 177 | 'contributionTypeID' => $this->_financialTypeId, |
6a488035 TO |
178 | 'contributionRecurID' => $recur->id, |
179 | ); | |
180 | ||
181 | // turn verifySSL off | |
182 | CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'); | |
183 | $result = $this->processor->doDirectPayment($params); | |
184 | // turn verifySSL on | |
185 | CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'); | |
186 | ||
187 | // if subscription was successful, processor_id / subscription-id must not be null | |
188 | $this->assertDBNotNull('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id', | |
189 | 'id', 'Failed to create subscription with Authorize.' | |
190 | ); | |
191 | ||
192 | // cancel it or the transaction will be rejected by A.net if the test is re-run | |
193 | $subscriptionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id'); | |
a7d56832 | 194 | $message = ''; |
6a488035 TO |
195 | $result = $this->processor->cancelSubscription($message, array('subscriptionId' => $subscriptionID)); |
196 | $this->assertTrue($result, 'Failed to cancel subscription with Authorize.'); | |
6a488035 TO |
197 | } |
198 | ||
199 | /** | |
200 | * create a single post dated payment as a recurring transaction | |
201 | */ | |
202 | function testCreateSinglePostDated() { | |
203 | $start_date = date('Ymd', strtotime("+ 1 week")); | |
204 | ||
205 | $firstName = 'John_' . substr(sha1(rand()), 0, 7); | |
206 | $lastName = 'Smith_' . substr(sha1(rand()), 0, 7); | |
207 | $nameParams = array('first_name' => $firstName, 'last_name' => $lastName); | |
a7d56832 | 208 | $contactId = $this->individualCreate($nameParams); |
6a488035 TO |
209 | |
210 | $ids = array('contribution' => NULL); | |
211 | $invoiceID = sha1(rand()); | |
212 | $amount = rand(100, 1000) . '.00'; | |
213 | ||
214 | $contributionRecurParams = array( | |
215 | 'contact_id' => $contactId, | |
216 | 'amount' => $amount, | |
217 | 'currency' => 'USD', | |
218 | 'frequency_unit' => 'month', | |
219 | 'frequency_interval' => 1, | |
220 | 'installments' => 3, | |
221 | 'start_date' => $start_date, | |
222 | 'create_date' => date('Ymd'), | |
223 | 'invoice_id' => $invoiceID, | |
224 | 'contribution_status_id' => 2, | |
225 | 'is_test' => 1, | |
226 | 'payment_processor_id' => $this->processorParams->id, | |
227 | ); | |
228 | $recur = CRM_Contribute_BAO_ContributionRecur::add($contributionRecurParams, $ids); | |
229 | ||
230 | $contributionParams = array( | |
231 | 'contact_id' => $contactId, | |
e6ff1593 | 232 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
233 | 'receive_date' => $start_date, |
234 | 'total_amount' => $amount, | |
235 | 'invoice_id' => $invoiceID, | |
236 | 'currency' => 'USD', | |
237 | 'contribution_recur_id' => $recur->id, | |
238 | 'is_test' => 1, | |
239 | 'contribution_status_id' => 2, | |
240 | ); | |
e6ff1593 | 241 | |
a7d56832 | 242 | $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); |
6a488035 TO |
243 | |
244 | $params = array( | |
245 | 'qfKey' => '00ed21c7ca00a1f7d555555596ef7_4454', | |
246 | 'hidden_CreditCard' => 1, | |
247 | 'billing_first_name' => $firstName, | |
248 | 'billing_middle_name' => "", | |
249 | 'billing_last_name' => $lastName, | |
250 | 'billing_street_address-5' => '8 Hobbitton Road', | |
251 | 'billing_city-5' => 'The Shire', | |
252 | 'billing_state_province_id-5' => 1012, | |
253 | 'billing_postal_code-5' => 5010, | |
254 | 'billing_country_id-5' => 1228, | |
255 | 'credit_card_number' => '4007000000027', | |
256 | 'cvv2' => 123, | |
257 | 'credit_card_exp_date' => array( | |
258 | 'M' => 11, | |
259 | 'Y' => 2019, | |
260 | ), | |
261 | 'credit_card_type' => 'Visa', | |
262 | 'is_recur' => 1, | |
263 | 'frequency_interval' => 1, | |
264 | 'frequency_unit' => 'month', | |
265 | 'installments' => 3, | |
e6ff1593 | 266 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
267 | 'is_email_receipt' => 1, |
268 | 'from_email_address' => "{$firstName}.{$lastName}@example.com", | |
269 | 'receive_date' => $start_date, | |
270 | 'receipt_date_time' => '', | |
271 | 'payment_processor_id' => $this->processorParams->id, | |
272 | 'price_set_id' => '', | |
273 | 'total_amount' => $amount, | |
274 | 'currency' => 'USD', | |
275 | 'source' => "Mordor", | |
276 | 'soft_credit_to' => '', | |
277 | 'soft_contact_id' => '', | |
278 | 'billing_state_province-5' => 'IL', | |
279 | 'state_province-5' => 'IL', | |
280 | 'billing_country-5' => 'US', | |
281 | 'country-5' => 'US', | |
282 | 'year' => 2019, | |
283 | 'month' => 10, | |
284 | 'ip_address' => '127.0.0.1', | |
285 | 'amount' => 70, | |
286 | 'amount_level' => 0, | |
287 | 'currencyID' => 'USD', | |
288 | 'pcp_display_in_roll' => "", | |
289 | 'pcp_roll_nickname' => "", | |
290 | 'pcp_personal_note' => "", | |
291 | 'non_deductible_amount' => "", | |
292 | 'fee_amount' => "", | |
293 | 'net_amount' => "", | |
294 | 'invoice_id' => "", | |
295 | 'contribution_page_id' => "", | |
296 | 'thankyou_date' => NULL, | |
297 | 'honor_contact_id' => NULL, | |
298 | 'invoiceID' => $invoiceID, | |
299 | 'first_name' => $firstName, | |
300 | 'middle_name' => 'bob', | |
301 | 'last_name' => $lastName, | |
302 | 'street_address' => '8 Hobbiton Road', | |
303 | 'city' => 'The Shire', | |
304 | 'state_province' => 'IL', | |
305 | 'postal_code' => 5010, | |
306 | 'country' => 'US', | |
307 | 'contributionType_name' => 'My precious', | |
308 | 'contributionType_accounting_code' => '', | |
309 | 'contributionPageID' => '', | |
310 | 'email' => "{$firstName}.{$lastName}@example.com", | |
311 | 'contactID' => $contactId, | |
a7d56832 | 312 | 'contributionID' => $contribution['id'], |
e6ff1593 | 313 | 'contributionTypeID' => $this->_financialTypeId, |
6a488035 TO |
314 | 'contributionRecurID' => $recur->id, |
315 | ); | |
316 | ||
317 | // if cancel-subscription has been called earlier 'subscriptionType' would be set to cancel. | |
318 | // to make a successful call for another trxn, we need to set it to something else. | |
319 | $smarty = CRM_Core_Smarty::singleton(); | |
320 | $smarty->assign('subscriptionType', 'create'); | |
321 | ||
322 | // turn verifySSL off | |
323 | CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'); | |
324 | $result = $this->processor->doDirectPayment($params); | |
325 | // turn verifySSL on | |
326 | CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'); | |
327 | ||
328 | // if subscription was successful, processor_id / subscription-id must not be null | |
329 | $this->assertDBNotNull('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id', | |
330 | 'id', 'Failed to create subscription with Authorize.' | |
331 | ); | |
332 | ||
333 | // cancel it or the transaction will be rejected by A.net if the test is re-run | |
334 | $subscriptionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id'); | |
a7d56832 | 335 | $message = ''; |
6a488035 TO |
336 | $result = $this->processor->cancelSubscription($message, array('subscriptionId' => $subscriptionID)); |
337 | $this->assertTrue($result, 'Failed to cancel subscription with Authorize.'); | |
6a488035 TO |
338 | } |
339 | } |