4 * Class CRM_Core_Payment_PayPalProIPNTest
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;
15 public function 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
,
23 'payment_processor' => $this->_paymentProcessorID
,
25 'receipt_from_email' => 'gaia@the.cosmos',
26 'receipt_from_name' => 'Pachamama',
27 'is_email_receipt' => TRUE,
29 $this->_contributionPageID
= $contributionPage['id'];
32 public function tearDown() {
33 $this->quickCleanUpFinancialEntities();
37 * Test IPN response updates contribution_recur & contribution for first & second contribution
39 public function testIPNPaymentRecurSuccess() {
40 $this->setupRecurringPaymentProcessorTransaction();
41 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
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());
52 $contribution = $this->callAPISuccess('contribution', 'get', array(
53 'contribution_recur_id' => $this->_contributionRecurID
,
56 $this->assertEquals(2, $contribution['count']);
57 $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']);
61 * Test IPN response updates contribution_recur & contribution for first & second contribution
63 public function testIPNPaymentMembershipRecurSuccess() {
64 $this->setupMembershipRecurringPaymentProcessorTransaction();
65 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
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());
76 $contribution = $this->callAPISuccess('contribution', 'get', array(
77 'contribution_recur_id' => $this->_contributionRecurID
,
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',
90 * Test IPN response mails don't leak.
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());
98 $mut->checkAllMailLog(array(
99 'Membership Type: General',
100 'Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
102 'Membership Start Date:',
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',
111 $mut->clearMessages();
112 $this->_contactID
= $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org'));
113 $this->_invoiceID
= uniqid();
115 $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
116 $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers')));
119 $mut->checkAllMailLog(array(
120 'Membership Type: General',
121 'Mrs. Antonia Anderson II',
122 'antonia_anderson@civicrm.org',
124 'Membership Start Date:',
125 'Transaction #: hers',
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',
136 $mut->clearMessages();
140 * Test IPN response mails don't leak.
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());
148 $mut->checkAllMailLog(array(
149 'Membership Type: General',
150 'Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
152 'Membership Start Date:',
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',
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;
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')));
171 $mut->checkAllMailLog(array(
172 'Membership Type: General',
173 'Mrs. Antonia Anderson II',
174 'antonia_anderson@civicrm.org',
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',
183 'First Name: Anthony',
184 'First Name: Antonia',
185 'Last Name: Anderson',
187 'Email Address: antonia_anderson@civicrm.org',
191 $mut->clearMessages();
195 * Get detail for recurring transaction.
197 * @param array $params
198 * Additional parameters.
201 * Parameters like AuthorizeNet silent post paramters.
203 public function getRecurTransaction($params = array()) {
204 return array_merge(array(
205 "x_amount" => "200.00",
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" => "",
222 "x_freight" => "0.00",
223 "x_tax_exempt" => "FALSE",
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',
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',
243 'x_trans_id' => '6511143069',
244 'x_auth_code' => '123456',
246 'x_response_reason_text' => 'This transaction has been approved.',
247 'x_response_reason_code' => '1',
248 'x_response_code' => '1',
255 public function getRecurSubsequentTransaction() {
256 return array_merge($this->getRecurTransaction(), array(
257 'x_trans_id' => 'second_one',
258 'x_MD5_Hash' => 'EA7A3CD65A85757827F51212CA1486A8',