3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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';
32 * Class CRM_Core_Payment_AuthorizeNetTest
34 class CRM_Core_Payment_AuthorizeNetTest
extends CiviUnitTestCase
{
36 public function setUp() {
38 $this->_paymentProcessorID
= $this->paymentProcessorAuthorizeNetCreate();
40 $this->processor
= Civi\Payment\System
::singleton()->getById($this->_paymentProcessorID
);
41 $this->_financialTypeId
= 1;
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
45 $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array();
48 public function tearDown() {
49 $this->quickCleanUpFinancialEntities();
53 * Create a single post dated payment as a recurring transaction.
55 * Test works but not both due to some form of caching going on in the SmartySingleton
57 public function testCreateSingleNowDated() {
58 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
59 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
60 $nameParams = array('first_name' => $firstName, 'last_name' => $lastName);
61 $contactId = $this->individualCreate($nameParams);
63 $invoiceID = sha1(rand());
64 $amount = rand(100, 1000) . '.00';
66 $contributionRecurParams = array(
67 'contact_id' => $contactId,
70 'frequency_unit' => 'week',
71 'frequency_interval' => 1,
73 'start_date' => date('Ymd'),
74 'create_date' => date('Ymd'),
75 'invoice_id' => $invoiceID,
76 'contribution_status_id' => 2,
78 'payment_processor_id' => $this->_paymentProcessorID
,
80 $recur = CRM_Contribute_BAO_ContributionRecur
::add($contributionRecurParams);
82 $contributionParams = array(
83 'contact_id' => $contactId,
84 'financial_type_id' => $this->_financialTypeId
,
85 'receive_date' => date('Ymd'),
86 'total_amount' => $amount,
87 'invoice_id' => $invoiceID,
89 'contribution_recur_id' => $recur->id
,
91 'contribution_status_id' => 2,
93 $contribution = CRM_Contribute_BAO_Contribution
::add($contributionParams);
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',
108 'credit_card_exp_date' => array(
112 'credit_card_type' => 'Visa',
114 'frequency_interval' => 1,
115 'frequency_unit' => 'month',
116 'installments' => 12,
117 'financial_type_id' => $this->_financialTypeId
,
118 'is_email_receipt' => 1,
119 'from_email_address' => "{$firstName}.{$lastName}@example.com",
120 'receive_date' => date('Ymd'),
121 'receipt_date_time' => '',
122 'payment_processor_id' => $this->_paymentProcessorID
,
123 'price_set_id' => '',
124 'total_amount' => $amount,
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',
135 'ip_address' => '127.0.0.1',
138 'currencyID' => 'USD',
139 'pcp_display_in_roll' => "",
140 'pcp_roll_nickname' => "",
141 'pcp_personal_note' => "",
142 'non_deductible_amount' => "",
145 'invoiceID' => $invoiceID,
146 'contribution_page_id' => "",
147 'thankyou_date' => NULL,
148 'honor_contact_id' => NULL,
149 'first_name' => $firstName,
151 'last_name' => $lastName,
152 'street_address' => '8 Hobbiton Road',
153 'city' => 'The Shire',
154 'state_province' => 'IL',
155 'postal_code' => 5010,
157 'contributionType_name' => 'My precious',
158 'contributionType_accounting_code' => '',
159 'contributionPageID' => '',
160 'email' => "{$firstName}.{$lastName}@example.com",
161 'contactID' => $contactId,
162 'contributionID' => $contribution->id
,
163 'contributionTypeID' => $this->_financialTypeId
,
164 'contributionRecurID' => $recur->id
,
167 // turn verifySSL off
168 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
169 $this->processor
->doPayment($params);
171 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
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.'
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');
181 $result = $this->processor
->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
182 $this->assertTrue($result, 'Failed to cancel subscription with Authorize.');
186 * Create a single post dated payment as a recurring transaction.
188 public function testCreateSinglePostDated() {
189 $start_date = date('Ymd', strtotime("+ 1 week"));
191 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
192 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
193 $nameParams = array('first_name' => $firstName, 'last_name' => $lastName);
194 $contactId = $this->individualCreate($nameParams);
196 $ids = array('contribution' => NULL);
197 $invoiceID = sha1(rand());
198 $amount = rand(100, 1000) . '.00';
200 $contributionRecurParams = array(
201 'contact_id' => $contactId,
204 'frequency_unit' => 'month',
205 'frequency_interval' => 1,
207 'start_date' => $start_date,
208 'create_date' => date('Ymd'),
209 'invoice_id' => $invoiceID,
210 'contribution_status_id' => 2,
212 'payment_processor_id' => $this->_paymentProcessorID
,
214 $recur = CRM_Contribute_BAO_ContributionRecur
::add($contributionRecurParams, $ids);
216 $contributionParams = array(
217 'contact_id' => $contactId,
218 'financial_type_id' => $this->_financialTypeId
,
219 'receive_date' => $start_date,
220 'total_amount' => $amount,
221 'invoice_id' => $invoiceID,
223 'contribution_recur_id' => $recur->id
,
225 'contribution_status_id' => 2,
228 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
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',
243 'credit_card_exp_date' => array(
247 'credit_card_type' => 'Visa',
249 'frequency_interval' => 1,
250 'frequency_unit' => 'month',
252 'financial_type_id' => $this->_financialTypeId
,
253 'is_email_receipt' => 1,
254 'from_email_address' => "{$firstName}.{$lastName}@example.com",
255 'receive_date' => $start_date,
256 'receipt_date_time' => '',
257 'payment_processor_id' => $this->_paymentProcessorID
,
258 'price_set_id' => '',
259 'total_amount' => $amount,
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',
270 'ip_address' => '127.0.0.1',
273 'currencyID' => 'USD',
274 'pcp_display_in_roll' => "",
275 'pcp_roll_nickname' => "",
276 'pcp_personal_note' => "",
277 'non_deductible_amount' => "",
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,
293 'contributionType_name' => 'My precious',
294 'contributionType_accounting_code' => '',
295 'contributionPageID' => '',
296 'email' => "{$firstName}.{$lastName}@example.com",
297 'contactID' => $contactId,
298 'contributionID' => $contribution['id'],
299 'contributionTypeID' => $this->_financialTypeId
,
300 'contributionRecurID' => $recur->id
,
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');
308 // turn verifySSL off
309 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
310 $result = $this->processor
->doPayment($params);
312 CRM_Core_BAO_Setting
::setItem('0', CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'verifySSL');
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.'
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');
322 $result = $this->processor
->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
323 $this->assertTrue($result, 'Failed to cancel subscription with Authorize.');