3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
30 require_once 'CiviTest/AuthorizeNet.php';
32 class CRM_Core_Payment_AuthorizeNetTest
extends CiviUnitTestCase
{
35 'name' => 'Authorize.net processing',
36 'description' => 'Test Authorize.ne methods.',
37 'group' => 'Payment Processor Tests',
43 $this->paymentProcessor
= new AuthorizeNet();
44 $this->processorParams
= $this->paymentProcessor
->create();
46 $paymentProcessor = array(
47 'user_name' => $this->processorParams
->user_name
,
48 'password' => $this->processorParams
->password
,
49 'url_recur' => $this->processorParams
->url_recur
,
53 $this->processor
= new CRM_Core_Payment_AuthorizeNet('Contribute', $paymentProcessor);
54 $this->_financialTypeId
= 1;
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( );
62 $this->paymentProcessor
->delete($this->processorParams
->id
);
63 $this->quickCleanUpFinancialEntities();
67 * create a single post dated payment as a recurring transaction.
69 * Test works but not both due to some form of caching going on in the SmartySingleton
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);
75 $contactId = $this->individualCreate($nameParams);
77 $invoiceID = sha1(rand());
78 $amount = rand(100, 1000) . '.00';
80 $contributionRecurParams = array(
81 'contact_id' => $contactId,
84 'frequency_unit' => 'week',
85 'frequency_interval' => 1,
87 'start_date' => date('Ymd'),
88 'create_date' => date('Ymd'),
89 'invoice_id' => $invoiceID,
90 'contribution_status_id' => 2,
92 'payment_processor_id' => $this->processorParams
->id
,
94 $recur = CRM_Contribute_BAO_ContributionRecur
::add($contributionRecurParams);
96 $contributionParams = array(
97 'contact_id' => $contactId,
98 'financial_type_id' => $this->_financialTypeId
,
99 'receive_date' => date('Ymd'),
100 'total_amount' => $amount,
101 'invoice_id' => $invoiceID,
103 'contribution_recur_id' => $recur->id
,
105 'contribution_status_id' => 2,
107 $contribution = CRM_Contribute_BAO_Contribution
::add($contributionParams);
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',
122 'credit_card_exp_date' => array(
126 'credit_card_type' => 'Visa',
128 'frequency_interval' => 1,
129 'frequency_unit' => 'month',
130 'installments' => 12,
131 'financial_type_id' => $this->_financialTypeId
,
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,
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',
149 'ip_address' => '127.0.0.1',
152 'currencyID' => 'USD',
153 'pcp_display_in_roll' => "",
154 'pcp_roll_nickname' => "",
155 'pcp_personal_note' => "",
156 'non_deductible_amount' => "",
159 'invoiceID' => $invoiceID,
160 'contribution_page_id' => "",
161 'thankyou_date' => NULL,
162 'honor_contact_id' => NULL,
163 'first_name' => $firstName,
165 'last_name' => $lastName,
166 'street_address' => '8 Hobbiton Road',
167 'city' => 'The Shire',
168 'state_province' => 'IL',
169 'postal_code' => 5010,
171 'contributionType_name' => 'My precious',
172 'contributionType_accounting_code' => '',
173 'contributionPageID' => '',
174 'email' => "{$firstName}.{$lastName}@example.com",
175 'contactID' => $contactId,
176 'contributionID' => $contribution->id
,
177 'contributionTypeID' => $this->_financialTypeId
,
178 'contributionRecurID' => $recur->id
,
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);
185 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
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.'
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');
195 $result = $this->processor
->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
196 $this->assertTrue($result, 'Failed to cancel subscription with Authorize.');
200 * create a single post dated payment as a recurring transaction
202 function testCreateSinglePostDated() {
203 $start_date = date('Ymd', strtotime("+ 1 week"));
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);
208 $contactId = $this->individualCreate($nameParams);
210 $ids = array('contribution' => NULL);
211 $invoiceID = sha1(rand());
212 $amount = rand(100, 1000) . '.00';
214 $contributionRecurParams = array(
215 'contact_id' => $contactId,
218 'frequency_unit' => 'month',
219 'frequency_interval' => 1,
221 'start_date' => $start_date,
222 'create_date' => date('Ymd'),
223 'invoice_id' => $invoiceID,
224 'contribution_status_id' => 2,
226 'payment_processor_id' => $this->processorParams
->id
,
228 $recur = CRM_Contribute_BAO_ContributionRecur
::add($contributionRecurParams, $ids);
230 $contributionParams = array(
231 'contact_id' => $contactId,
232 'financial_type_id' => $this->_financialTypeId
,
233 'receive_date' => $start_date,
234 'total_amount' => $amount,
235 'invoice_id' => $invoiceID,
237 'contribution_recur_id' => $recur->id
,
239 'contribution_status_id' => 2,
242 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
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',
257 'credit_card_exp_date' => array(
261 'credit_card_type' => 'Visa',
263 'frequency_interval' => 1,
264 'frequency_unit' => 'month',
266 'financial_type_id' => $this->_financialTypeId
,
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,
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',
284 'ip_address' => '127.0.0.1',
287 'currencyID' => 'USD',
288 'pcp_display_in_roll' => "",
289 'pcp_roll_nickname' => "",
290 'pcp_personal_note' => "",
291 'non_deductible_amount' => "",
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,
307 'contributionType_name' => 'My precious',
308 'contributionType_accounting_code' => '',
309 'contributionPageID' => '',
310 'email' => "{$firstName}.{$lastName}@example.com",
311 'contactID' => $contactId,
312 'contributionID' => $contribution['id'],
313 'contributionTypeID' => $this->_financialTypeId
,
314 'contributionRecurID' => $recur->id
,
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');
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);
326 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
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.'
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');
336 $result = $this->processor
->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
337 $this->assertTrue($result, 'Failed to cancel subscription with Authorize.');