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