3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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';
33 * Class CRM_Core_Payment_AuthorizeNetTest
35 class CRM_Core_Payment_AuthorizeNetTest
extends CiviUnitTestCase
{
37 public function setUp() {
39 $this->paymentProcessor
= new AuthorizeNet();
40 $this->processorParams
= $this->paymentProcessor
->create();
42 $paymentProcessor = array(
43 'user_name' => $this->processorParams
->user_name
,
44 'password' => $this->processorParams
->password
,
45 'url_recur' => $this->processorParams
->url_recur
,
49 $this->processor
= new CRM_Core_Payment_AuthorizeNet('Contribute', $paymentProcessor);
50 $this->_financialTypeId
= 1;
52 // for some strange unknown reason, in batch mode this value gets set to null
53 // so crude hack here to avoid an exception and hence an error
54 $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array();
57 public function tearDown() {
58 $this->paymentProcessor
->delete($this->processorParams
->id
);
59 $this->quickCleanUpFinancialEntities();
63 * Create a single post dated payment as a recurring transaction.
65 * Test works but not both due to some form of caching going on in the SmartySingleton
67 public function testCreateSingleNowDated() {
68 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
69 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
70 $nameParams = array('first_name' => $firstName, 'last_name' => $lastName);
71 $contactId = $this->individualCreate($nameParams);
73 $invoiceID = sha1(rand());
74 $amount = rand(100, 1000) . '.00';
76 $contributionRecurParams = array(
77 'contact_id' => $contactId,
80 'frequency_unit' => 'week',
81 'frequency_interval' => 1,
83 'start_date' => date('Ymd'),
84 'create_date' => date('Ymd'),
85 'invoice_id' => $invoiceID,
86 'contribution_status_id' => 2,
88 'payment_processor_id' => $this->processorParams
->id
,
90 $recur = CRM_Contribute_BAO_ContributionRecur
::add($contributionRecurParams);
92 $contributionParams = array(
93 'contact_id' => $contactId,
94 'financial_type_id' => $this->_financialTypeId
,
95 'receive_date' => date('Ymd'),
96 'total_amount' => $amount,
97 'invoice_id' => $invoiceID,
99 'contribution_recur_id' => $recur->id
,
101 'contribution_status_id' => 2,
103 $contribution = CRM_Contribute_BAO_Contribution
::add($contributionParams);
106 'qfKey' => '08ed21c7ca00a1f7d32fff2488596ef7_4454',
107 'hidden_CreditCard' => 1,
108 'billing_first_name' => $firstName,
109 'billing_middle_name' => "",
110 'billing_last_name' => $lastName,
111 'billing_street_address-5' => '8 Hobbitton Road',
112 'billing_city-5' => 'The Shire',
113 'billing_state_province_id-5' => 1012,
114 'billing_postal_code-5' => 5010,
115 'billing_country_id-5' => 1228,
116 'credit_card_number' => '4007000000027',
118 'credit_card_exp_date' => array(
122 'credit_card_type' => 'Visa',
124 'frequency_interval' => 1,
125 'frequency_unit' => 'month',
126 'installments' => 12,
127 'financial_type_id' => $this->_financialTypeId
,
128 'is_email_receipt' => 1,
129 'from_email_address' => "{$firstName}.{$lastName}@example.com",
130 'receive_date' => date('Ymd'),
131 'receipt_date_time' => '',
132 'payment_processor_id' => $this->processorParams
->id
,
133 'price_set_id' => '',
134 'total_amount' => $amount,
136 'source' => "Mordor",
137 'soft_credit_to' => '',
138 'soft_contact_id' => '',
139 'billing_state_province-5' => 'IL',
140 'state_province-5' => 'IL',
141 'billing_country-5' => 'US',
145 'ip_address' => '127.0.0.1',
148 'currencyID' => 'USD',
149 'pcp_display_in_roll' => "",
150 'pcp_roll_nickname' => "",
151 'pcp_personal_note' => "",
152 'non_deductible_amount' => "",
155 'invoiceID' => $invoiceID,
156 'contribution_page_id' => "",
157 'thankyou_date' => NULL,
158 'honor_contact_id' => NULL,
159 'first_name' => $firstName,
161 'last_name' => $lastName,
162 'street_address' => '8 Hobbiton Road',
163 'city' => 'The Shire',
164 'state_province' => 'IL',
165 'postal_code' => 5010,
167 'contributionType_name' => 'My precious',
168 'contributionType_accounting_code' => '',
169 'contributionPageID' => '',
170 'email' => "{$firstName}.{$lastName}@example.com",
171 'contactID' => $contactId,
172 'contributionID' => $contribution->id
,
173 'contributionTypeID' => $this->_financialTypeId
,
174 'contributionRecurID' => $recur->id
,
177 // turn verifySSL off
178 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
179 $this->processor
->doDirectPayment($params);
181 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
183 // if subscription was successful, processor_id / subscription-id must not be null
184 $this->assertDBNotNull('CRM_Contribute_DAO_ContributionRecur', $recur->id
, 'processor_id',
185 'id', 'Failed to create subscription with Authorize.'
188 // cancel it or the transaction will be rejected by A.net if the test is re-run
189 $subscriptionID = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur->id
, 'processor_id');
191 $result = $this->processor
->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
192 $this->assertTrue($result, 'Failed to cancel subscription with Authorize.');
196 * Create a single post dated payment as a recurring transaction
198 public function testCreateSinglePostDated() {
199 $start_date = date('Ymd', strtotime("+ 1 week"));
201 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
202 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
203 $nameParams = array('first_name' => $firstName, 'last_name' => $lastName);
204 $contactId = $this->individualCreate($nameParams);
206 $ids = array('contribution' => NULL);
207 $invoiceID = sha1(rand());
208 $amount = rand(100, 1000) . '.00';
210 $contributionRecurParams = array(
211 'contact_id' => $contactId,
214 'frequency_unit' => 'month',
215 'frequency_interval' => 1,
217 'start_date' => $start_date,
218 'create_date' => date('Ymd'),
219 'invoice_id' => $invoiceID,
220 'contribution_status_id' => 2,
222 'payment_processor_id' => $this->processorParams
->id
,
224 $recur = CRM_Contribute_BAO_ContributionRecur
::add($contributionRecurParams, $ids);
226 $contributionParams = array(
227 'contact_id' => $contactId,
228 'financial_type_id' => $this->_financialTypeId
,
229 'receive_date' => $start_date,
230 'total_amount' => $amount,
231 'invoice_id' => $invoiceID,
233 'contribution_recur_id' => $recur->id
,
235 'contribution_status_id' => 2,
238 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
241 'qfKey' => '00ed21c7ca00a1f7d555555596ef7_4454',
242 'hidden_CreditCard' => 1,
243 'billing_first_name' => $firstName,
244 'billing_middle_name' => "",
245 'billing_last_name' => $lastName,
246 'billing_street_address-5' => '8 Hobbitton Road',
247 'billing_city-5' => 'The Shire',
248 'billing_state_province_id-5' => 1012,
249 'billing_postal_code-5' => 5010,
250 'billing_country_id-5' => 1228,
251 'credit_card_number' => '4007000000027',
253 'credit_card_exp_date' => array(
257 'credit_card_type' => 'Visa',
259 'frequency_interval' => 1,
260 'frequency_unit' => 'month',
262 'financial_type_id' => $this->_financialTypeId
,
263 'is_email_receipt' => 1,
264 'from_email_address' => "{$firstName}.{$lastName}@example.com",
265 'receive_date' => $start_date,
266 'receipt_date_time' => '',
267 'payment_processor_id' => $this->processorParams
->id
,
268 'price_set_id' => '',
269 'total_amount' => $amount,
271 'source' => "Mordor",
272 'soft_credit_to' => '',
273 'soft_contact_id' => '',
274 'billing_state_province-5' => 'IL',
275 'state_province-5' => 'IL',
276 'billing_country-5' => 'US',
280 'ip_address' => '127.0.0.1',
283 'currencyID' => 'USD',
284 'pcp_display_in_roll' => "",
285 'pcp_roll_nickname' => "",
286 'pcp_personal_note' => "",
287 'non_deductible_amount' => "",
291 'contribution_page_id' => "",
292 'thankyou_date' => NULL,
293 'honor_contact_id' => NULL,
294 'invoiceID' => $invoiceID,
295 'first_name' => $firstName,
296 'middle_name' => 'bob',
297 'last_name' => $lastName,
298 'street_address' => '8 Hobbiton Road',
299 'city' => 'The Shire',
300 'state_province' => 'IL',
301 'postal_code' => 5010,
303 'contributionType_name' => 'My precious',
304 'contributionType_accounting_code' => '',
305 'contributionPageID' => '',
306 'email' => "{$firstName}.{$lastName}@example.com",
307 'contactID' => $contactId,
308 'contributionID' => $contribution['id'],
309 'contributionTypeID' => $this->_financialTypeId
,
310 'contributionRecurID' => $recur->id
,
313 // if cancel-subscription has been called earlier 'subscriptionType' would be set to cancel.
314 // to make a successful call for another trxn, we need to set it to something else.
315 $smarty = CRM_Core_Smarty
::singleton();
316 $smarty->assign('subscriptionType', 'create');
318 // turn verifySSL off
319 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
320 $result = $this->processor
->doDirectPayment($params);
322 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
324 // if subscription was successful, processor_id / subscription-id must not be null
325 $this->assertDBNotNull('CRM_Contribute_DAO_ContributionRecur', $recur->id
, 'processor_id',
326 'id', 'Failed to create subscription with Authorize.'
329 // cancel it or the transaction will be rejected by A.net if the test is re-run
330 $subscriptionID = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur->id
, 'processor_id');
332 $result = $this->processor
->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
333 $this->assertTrue($result, 'Failed to cancel subscription with Authorize.');