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