tests/phpunit - Declare `@group headless`
[civicrm-core.git] / tests / phpunit / CRM / Core / Payment / AuthorizeNetIPNTest.php
CommitLineData
0dbefed3
EM
1<?php
2
0dbefed3
EM
3/**
4 * Class CRM_Core_Payment_PayPalProIPNTest
acb109b7 5 * @group headless
0dbefed3
EM
6 */
7class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase {
8 protected $_contributionID;
9 protected $_invoiceID = 'c2r9c15f7be20b4f3fef1f77e4c37424';
10 protected $_financialTypeID = 1;
11 protected $_contactID;
12 protected $_contributionRecurID;
13 protected $_contributionPageID;
14 protected $_paymentProcessorID;
15
00be9182 16 public function setUp() {
0dbefed3 17 parent::setUp();
034efa4e 18 $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate(array('is_test' => 0));
0dbefed3
EM
19 $this->_contactID = $this->individualCreate();
20 $contributionPage = $this->callAPISuccess('contribution_page', 'create', array(
21 'title' => "Test Contribution Page",
22 'financial_type_id' => $this->_financialTypeID,
23 'currency' => 'USD',
24 'payment_processor' => $this->_paymentProcessorID,
481312d9 25 'max_amount' => 1000,
26 'receipt_from_email' => 'gaia@the.cosmos',
27 'receipt_from_name' => 'Pachamama',
28 'is_email_receipt' => TRUE,
0dbefed3
EM
29 ));
30 $this->_contributionPageID = $contributionPage['id'];
31 }
32
00be9182 33 public function tearDown() {
0dbefed3
EM
34 $this->quickCleanUpFinancialEntities();
35 }
36
37 /**
100fef9d 38 * Test IPN response updates contribution_recur & contribution for first & second contribution
0dbefed3 39 */
00be9182 40 public function testIPNPaymentRecurSuccess() {
0dbefed3 41 $this->setupRecurringPaymentProcessorTransaction();
8f234057 42 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
43 $IPN->main();
0dbefed3
EM
44 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
45 $this->assertEquals(1, $contribution['contribution_status_id']);
46 $this->assertEquals('6511143069', $contribution['trxn_id']);
47 // source gets set by processor
48 $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
49 $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
50 $this->assertEquals(5, $contributionRecur['contribution_status_id']);
8f234057 51 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
52 $IPN->main();
92915c55
TO
53 $contribution = $this->callAPISuccess('contribution', 'get', array(
54 'contribution_recur_id' => $this->_contributionRecurID,
28a04ea9 55 'sequential' => 1,
92915c55 56 ));
0dbefed3
EM
57 $this->assertEquals(2, $contribution['count']);
58 $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']);
59 }
60
8c15aab2 61 /**
100fef9d 62 * Test IPN response updates contribution_recur & contribution for first & second contribution
8c15aab2 63 */
00be9182 64 public function testIPNPaymentMembershipRecurSuccess() {
8c15aab2 65 $this->setupMembershipRecurringPaymentProcessorTransaction();
8f234057 66 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
67 $IPN->main();
8c15aab2
EM
68 $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
69 $this->assertEquals(1, $contribution['contribution_status_id']);
70 $this->assertEquals('6511143069', $contribution['trxn_id']);
71 // source gets set by processor
72 $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
73 $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
74 $this->assertEquals(5, $contributionRecur['contribution_status_id']);
8f234057 75 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
76 $IPN->main();
92915c55
TO
77 $contribution = $this->callAPISuccess('contribution', 'get', array(
78 'contribution_recur_id' => $this->_contributionRecurID,
28a04ea9 79 'sequential' => 1,
92915c55 80 ));
8c15aab2
EM
81 $this->assertEquals(2, $contribution['count']);
82 $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']);
6c6e6187 83 $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id']));
92915c55
TO
84 $this->callAPISuccessGetSingle('line_item', array(
85 'contribution_id' => $contribution['values'][1]['id'],
28a04ea9 86 'entity_table' => 'civicrm_membership',
92915c55 87 ));
8c15aab2
EM
88 }
89
0dbefed3 90 /**
481312d9 91 * Test IPN response mails don't leak.
0dbefed3 92 */
481312d9 93 public function testIPNPaymentMembershipRecurSuccessNoLeakage() {
94 $mut = new CiviMailUtils($this, TRUE);
95 $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
96 $this->addProfile('supporter_profile', $this->_contributionPageID);
97 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
98 $IPN->main();
99 $mut->checkAllMailLog(array(
100 'Membership Type: General',
101 'Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
102 'Amount: $ 200.00',
103 'Membership Start Date:',
104 'Supporter Profile',
105 'First Name: Anthony',
106 'Last Name: Anderson',
107 'Email Address: anthony_anderson@civicrm.org',
108 'This membership will be automatically renewed every',
109 'Dear Mr. Anthony Anderson II',
110 'Thanks for your auto renew membership sign-up',
111 ));
112 $mut->clearMessages();
113 $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org'));
114 $this->_invoiceID = uniqid();
115
116 $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
117 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers')));
118 $IPN->main();
119
120 $mut->checkAllMailLog(array(
121 'Membership Type: General',
122 'Mrs. Antonia Anderson II',
123 'antonia_anderson@civicrm.org',
124 'Amount: $ 200.00',
125 'Membership Start Date:',
126 'Transaction #: hers',
127 'Supporter Profile',
128 'First Name: Antonia',
129 'Last Name: Anderson',
130 'Email Address: antonia_anderson@civicrm.org',
131 'This membership will be automatically renewed every',
132 'Dear Mrs. Antonia Anderson II',
133 'Thanks for your auto renew membership sign-up',
134 ));
135
136 $mut->stop();
137 $mut->clearMessages();
138 }
139
c198e59d 140 /**
141 * Test IPN response mails don't leak.
142 */
143 public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline() {
144 $mut = new CiviMailUtils($this, TRUE);
145 $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
146 $this->addProfile('supporter_profile', $this->_contributionPageID);
147 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
148 $IPN->main();
149 $mut->checkAllMailLog(array(
150 'Membership Type: General',
151 'Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
152 'Amount: $ 200.00',
153 'Membership Start Date:',
154 'Supporter Profile',
155 'First Name: Anthony',
156 'Last Name: Anderson',
157 'Email Address: anthony_anderson@civicrm.org',
158 'This membership will be automatically renewed every',
159 'Dear Mr. Anthony Anderson II',
160 'Thanks for your auto renew membership sign-up',
161 ));
162
163 $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org'));
164 $this->_invoiceID = uniqid();
165 $this->_contributionPageID = NULL;
166
167 $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
168 $mut->clearMessages(99999);
169 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers')));
170 $IPN->main();
171
172 $mut->checkAllMailLog(array(
173 'Membership Type: General',
174 'Mrs. Antonia Anderson II',
175 'antonia_anderson@civicrm.org',
176 'Amount: $ 200.00',
177 'Membership Start Date:',
178 'Transaction #: hers',
179 'This membership will be automatically renewed every',
180 'Dear Mrs. Antonia Anderson II',
181 'Thanks for your auto renew membership sign-up',
c7e7164f 182 ),
183 array(
184 'First Name: Anthony',
185 'First Name: Antonia',
186 'Last Name: Anderson',
187 'Supporter Profile',
188 'Email Address: antonia_anderson@civicrm.org',
189 ));
c198e59d 190
191 $mut->stop();
192 $mut->clearMessages();
193 }
194
481312d9 195 /**
196 * Get detail for recurring transaction.
197 *
198 * @param array $params
199 * Additional parameters.
200 *
201 * @return array
202 * Parameters like AuthorizeNet silent post paramters.
203 */
204 public function getRecurTransaction($params = array()) {
205 return array_merge(array(
0dbefed3
EM
206 "x_amount" => "200.00",
207 "x_country" => 'US',
208 "x_phone" => "",
209 "x_fax" => "",
210 "x_email" => "me@gmail.com",
211 "x_description" => "lots of money",
212 "x_type" => "auth_capture",
213 "x_ship_to_first_name" => "",
214 "x_ship_to_last_name" => "",
215 "x_ship_to_company" => "",
216 "x_ship_to_address" => "",
217 "x_ship_to_city" => "",
218 "x_ship_to_state" => "",
219 "x_ship_to_zip" => "",
220 "x_ship_to_country" => "",
221 "x_tax" => "0.00",
222 "x_duty" => "0.00",
223 "x_freight" => "0.00",
224 "x_tax_exempt" => "FALSE",
225 "x_po_num" => "",
226 "x_MD5_Hash" => "1B7C0C5B4DEDD9CAD0636E35E22FC594",
227 "x_cvv2_resp_code" => "",
228 "x_cavv_response" => "",
229 "x_test_request" => "false",
481312d9 230 "x_subscription_id" => $this->_contactID,
0dbefed3
EM
231 "x_subscription_paynum" => "1",
232 'x_first_name' => 'Robert',
233 'x_zip' => '90210',
234 'x_state' => 'WA',
235 'x_city' => 'Dallas',
236 'x_address' => '41 My ST',
237 'x_invoice_num' => $this->_contributionID,
238 'x_cust_id' => $this->_contactID,
239 'x_company' => 'nowhere@civicrm.org',
240 'x_last_name' => 'Roberts',
241 'x_account_number' => 'XXXX5077',
242 'x_card_type' => 'Visa',
243 'x_method' => 'CC',
244 'x_trans_id' => '6511143069',
245 'x_auth_code' => '123456',
246 'x_avs_code' => 'Z',
247 'x_response_reason_text' => 'This transaction has been approved.',
248 'x_response_reason_code' => '1',
21dfd5f5 249 'x_response_code' => '1',
481312d9 250 ), $params);
0dbefed3
EM
251 }
252
253 /**
254 * @return array
255 */
00be9182 256 public function getRecurSubsequentTransaction() {
0dbefed3
EM
257 return array_merge($this->getRecurTransaction(), array(
258 'x_trans_id' => 'second_one',
259 'x_MD5_Hash' => 'EA7A3CD65A85757827F51212CA1486A8',
260 ));
261 }
96025800 262
0dbefed3 263}