Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
1d86918a | 29 | * Class CRM_Core_Payment_BaseIPN. |
6a488035 TO |
30 | */ |
31 | class CRM_Core_Payment_BaseIPN { | |
32 | ||
518fa0ee | 33 | public static $_now = NULL; |
8196c759 | 34 | |
c8aa607b | 35 | /** |
36 | * Input parameters from payment processor. Store these so that | |
37 | * the code does not need to keep retrieving from the http request | |
38 | * @var array | |
39 | */ | |
be2fb01f | 40 | protected $_inputParameters = []; |
c8aa607b | 41 | |
59cdadfc | 42 | /** |
43 | * Only used by AuthorizeNetIPN. | |
518fa0ee | 44 | * @var bool |
59cdadfc | 45 | * |
46 | * @deprecated | |
47 | * | |
59cdadfc | 48 | */ |
937cf542 EM |
49 | protected $_isRecurring = FALSE; |
50 | ||
59cdadfc | 51 | /** |
52 | * Only used by AuthorizeNetIPN. | |
518fa0ee | 53 | * @var bool |
59cdadfc | 54 | * |
55 | * @deprecated | |
56 | * | |
59cdadfc | 57 | */ |
937cf542 | 58 | protected $_isFirstOrLastRecurringPayment = FALSE; |
353ffa53 | 59 | |
8196c759 | 60 | /** |
fe482240 | 61 | * Constructor. |
8196c759 | 62 | */ |
00be9182 | 63 | public function __construct() { |
6a488035 TO |
64 | self::$_now = date('YmdHis'); |
65 | } | |
66 | ||
c8aa607b | 67 | /** |
fe482240 | 68 | * Store input array on the class. |
77b97be7 | 69 | * |
c8aa607b | 70 | * @param array $parameters |
77b97be7 EM |
71 | * |
72 | * @throws CRM_Core_Exception | |
c8aa607b | 73 | */ |
00be9182 | 74 | public function setInputParameters($parameters) { |
22e263ad | 75 | if (!is_array($parameters)) { |
cc0c30cc | 76 | throw new CRM_Core_Exception('Invalid input parameters'); |
c8aa607b | 77 | } |
78 | $this->_inputParameters = $parameters; | |
79 | } | |
353ffa53 | 80 | |
8196c759 | 81 | /** |
1d86918a EM |
82 | * Validate incoming data. |
83 | * | |
84 | * This function is intended to ensure that incoming data matches | |
8196c759 | 85 | * It provides a form of pseudo-authentication - by checking the calling fn already knows |
86 | * the correct contact id & contribution id (this can be problematic when that has changed in | |
87 | * the meantime for transactions that are delayed & contacts are merged in-between. e.g | |
88 | * Paypal allows you to resend Instant Payment Notifications if you, for example, moved site | |
89 | * and didn't update your IPN URL. | |
90 | * | |
6a0b768e TO |
91 | * @param array $input |
92 | * Interpreted values from the values returned through the IPN. | |
93 | * @param array $ids | |
94 | * More interpreted values (ids) from the values returned through the IPN. | |
95 | * @param array $objects | |
96 | * An empty array that will be populated with loaded object. | |
97 | * @param bool $required | |
98 | * Boolean Return FALSE if the relevant objects don't exist. | |
99 | * @param int $paymentProcessorID | |
100 | * Id of the payment processor ID in use. | |
1d86918a | 101 | * |
5c766a0b | 102 | * @return bool |
8196c759 | 103 | */ |
00be9182 | 104 | public function validateData(&$input, &$ids, &$objects, $required = TRUE, $paymentProcessorID = NULL) { |
6a488035 TO |
105 | |
106 | // make sure contact exists and is valid | |
5a9c68ac | 107 | $contact = new CRM_Contact_BAO_Contact(); |
6a488035 TO |
108 | $contact->id = $ids['contact']; |
109 | if (!$contact->find(TRUE)) { | |
92fcb95f | 110 | CRM_Core_Error::debug_log_message("Could not find contact record: {$ids['contact']} in IPN request: " . print_r($input, TRUE)); |
6a488035 TO |
111 | echo "Failure: Could not find contact record: {$ids['contact']}<p>"; |
112 | return FALSE; | |
113 | } | |
114 | ||
115 | // make sure contribution exists and is valid | |
5a9c68ac | 116 | $contribution = new CRM_Contribute_BAO_Contribution(); |
6a488035 TO |
117 | $contribution->id = $ids['contribution']; |
118 | if (!$contribution->find(TRUE)) { | |
92fcb95f | 119 | CRM_Core_Error::debug_log_message("Could not find contribution record: {$contribution->id} in IPN request: " . print_r($input, TRUE)); |
6a488035 TO |
120 | echo "Failure: Could not find contribution record for {$contribution->id}<p>"; |
121 | return FALSE; | |
122 | } | |
123 | $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date); | |
d9924163 | 124 | $contribution->receipt_date = CRM_Utils_Date::isoToMysql($contribution->receipt_date); |
6a488035 TO |
125 | |
126 | $objects['contact'] = &$contact; | |
127 | $objects['contribution'] = &$contribution; | |
d0488f03 | 128 | |
129 | // CRM-19478: handle oddity when p=null is set in place of contribution page ID, | |
130 | if (!empty($ids['contributionPage']) && !is_numeric($ids['contributionPage'])) { | |
131 | // We don't need to worry if about removing contribution page id as it will be set later in | |
132 | // CRM_Contribute_BAO_Contribution::loadRelatedObjects(..) using $objects['contribution']->contribution_page_id | |
133 | unset($ids['contributionPage']); | |
134 | } | |
135 | ||
6a488035 TO |
136 | if (!$this->loadObjects($input, $ids, $objects, $required, $paymentProcessorID)) { |
137 | return FALSE; | |
138 | } | |
a284891b EM |
139 | //the process is that the loadObjects is kind of hacked by loading the objects for the original contribution and then somewhat inconsistently using them for the |
140 | //current contribution. Here we ensure that the original contribution is available to the complete transaction function | |
141 | //we don't want to fix this in the payment processor classes because we would have to fix all of them - so better to fix somewhere central | |
142 | if (isset($objects['contributionRecur'])) { | |
143 | $objects['first_contribution'] = $objects['contribution']; | |
144 | } | |
6a488035 TO |
145 | return TRUE; |
146 | } | |
147 | ||
8196c759 | 148 | /** |
fe482240 | 149 | * Load objects related to contribution. |
6a488035 TO |
150 | * |
151 | * @input array information from Payment processor | |
dd244018 | 152 | * |
3aaa68fb | 153 | * @param array $input |
8196c759 | 154 | * @param array $ids |
155 | * @param array $objects | |
6a0b768e TO |
156 | * @param bool $required |
157 | * @param int $paymentProcessorID | |
8196c759 | 158 | * @param array $error_handling |
dd244018 | 159 | * |
3aaa68fb | 160 | * @return bool|array |
6a488035 | 161 | */ |
00be9182 | 162 | public function loadObjects(&$input, &$ids, &$objects, $required, $paymentProcessorID, $error_handling = NULL) { |
6a488035 TO |
163 | if (empty($error_handling)) { |
164 | // default options are that we log an error & echo it out | |
165 | // note that we should refactor this error handling into error code @ some point | |
166 | // but for now setting up enough separation so we can do unit tests | |
be2fb01f | 167 | $error_handling = [ |
6a488035 TO |
168 | 'log_error' => 1, |
169 | 'echo_error' => 1, | |
be2fb01f | 170 | ]; |
6a488035 TO |
171 | } |
172 | $ids['paymentProcessor'] = $paymentProcessorID; | |
173 | if (is_a($objects['contribution'], 'CRM_Contribute_BAO_Contribution')) { | |
174 | $contribution = &$objects['contribution']; | |
175 | } | |
176 | else { | |
177 | //legacy support - functions are 'used' to be able to pass in a DAO | |
178 | $contribution = new CRM_Contribute_BAO_Contribution(); | |
179 | $contribution->id = CRM_Utils_Array::value('contribution', $ids); | |
180 | $contribution->find(TRUE); | |
181 | $objects['contribution'] = &$contribution; | |
182 | } | |
183 | try { | |
276e3ec6 | 184 | $success = $contribution->loadRelatedObjects($input, $ids); |
185 | if ($required && empty($contribution->_relatedObjects['paymentProcessor'])) { | |
186 | throw new CRM_Core_Exception("Could not find payment processor for contribution record: " . $contribution->id); | |
187 | } | |
6a488035 | 188 | } |
353ffa53 | 189 | catch (Exception $e) { |
cc0c30cc | 190 | $success = FALSE; |
a7488080 | 191 | if (!empty($error_handling['log_error'])) { |
6a488035 TO |
192 | CRM_Core_Error::debug_log_message($e->getMessage()); |
193 | } | |
a7488080 | 194 | if (!empty($error_handling['echo_error'])) { |
6c552737 | 195 | echo $e->getMessage(); |
6a488035 | 196 | } |
a7488080 | 197 | if (!empty($error_handling['return_error'])) { |
be2fb01f | 198 | return [ |
6a488035 TO |
199 | 'is_error' => 1, |
200 | 'error_message' => ($e->getMessage()), | |
be2fb01f | 201 | ]; |
6a488035 TO |
202 | } |
203 | } | |
204 | $objects = array_merge($objects, $contribution->_relatedObjects); | |
205 | return $success; | |
206 | } | |
207 | ||
8196c759 | 208 | /** |
fe482240 | 209 | * Set contribution to failed. |
28de42d1 | 210 | * |
8196c759 | 211 | * @param array $objects |
212 | * @param object $transaction | |
213 | * @param array $input | |
28de42d1 | 214 | * |
5c766a0b | 215 | * @return bool |
e44c82e1 | 216 | * @throws \CiviCRM_API3_Exception |
8196c759 | 217 | */ |
be2fb01f | 218 | public function failed(&$objects, &$transaction, $input = []) { |
6a488035 | 219 | $contribution = &$objects['contribution']; |
be2fb01f | 220 | $memberships = []; |
a7488080 | 221 | if (!empty($objects['membership'])) { |
6a488035 TO |
222 | $memberships = &$objects['membership']; |
223 | if (is_numeric($memberships)) { | |
be2fb01f | 224 | $memberships = [$objects['membership']]; |
6a488035 TO |
225 | } |
226 | } | |
227 | ||
228 | $addLineItems = FALSE; | |
229 | if (empty($contribution->id)) { | |
230 | $addLineItems = TRUE; | |
231 | } | |
232 | $participant = &$objects['participant']; | |
233 | ||
3aaa68fb | 234 | // CRM-15546 |
be2fb01f | 235 | $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [ |
518fa0ee SL |
236 | 'labelColumn' => 'name', |
237 | 'flip' => 1, | |
238 | ]); | |
e44c82e1 | 239 | $contribution->contribution_status_id = $contributionStatuses['Failed']; |
5a9c68ac PJ |
240 | $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date); |
241 | $contribution->receipt_date = CRM_Utils_Date::isoToMysql($contribution->receipt_date); | |
242 | $contribution->thankyou_date = CRM_Utils_Date::isoToMysql($contribution->thankyou_date); | |
6a488035 TO |
243 | $contribution->save(); |
244 | ||
28de42d1 | 245 | // Add line items for recurring payments. |
a7488080 | 246 | if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id && $addLineItems) { |
e577770c | 247 | CRM_Contribute_BAO_ContributionRecur::addRecurLineItems($objects['contributionRecur']->id, $contribution); |
6a488035 TO |
248 | } |
249 | ||
8381af80 | 250 | //add new soft credit against current contribution id and |
6357981e | 251 | //copy initial contribution custom fields for recurring contributions |
a7488080 | 252 | if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id) { |
e577770c EM |
253 | CRM_Contribute_BAO_ContributionRecur::addrecurSoftCredit($objects['contributionRecur']->id, $contribution->id); |
254 | CRM_Contribute_BAO_ContributionRecur::copyCustomValues($objects['contributionRecur']->id, $contribution->id); | |
6357981e PJ |
255 | } |
256 | ||
0bad10e7 | 257 | if (empty($input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'])) { |
6a488035 TO |
258 | if (!empty($memberships)) { |
259 | foreach ($memberships as $membership) { | |
56c7d914 MWMC |
260 | // @fixme Should we cancel only Pending memberships? per cancelled() |
261 | $this->cancelMembership($membership, $membership->status_id, FALSE); | |
6a488035 TO |
262 | } |
263 | } | |
d63f4fc3 | 264 | |
6a488035 | 265 | if ($participant) { |
56c7d914 | 266 | $this->cancelParticipant($participant->id); |
6a488035 TO |
267 | } |
268 | } | |
269 | ||
270 | $transaction->commit(); | |
e44c82e1 | 271 | Civi::log()->debug("Setting contribution status to Failed"); |
6a488035 TO |
272 | return TRUE; |
273 | } | |
274 | ||
8196c759 | 275 | /** |
fe482240 | 276 | * Handled pending contribution status. |
1d86918a | 277 | * |
8196c759 | 278 | * @param array $objects |
279 | * @param object $transaction | |
1d86918a | 280 | * |
5c766a0b | 281 | * @return bool |
8196c759 | 282 | */ |
00be9182 | 283 | public function pending(&$objects, &$transaction) { |
6a488035 | 284 | $transaction->commit(); |
e44c82e1 | 285 | Civi::log()->debug("Returning since contribution status is Pending"); |
6a488035 TO |
286 | echo "Success: Returning since contribution status is pending<p>"; |
287 | return TRUE; | |
288 | } | |
289 | ||
6c786a9b | 290 | /** |
1d86918a EM |
291 | * Process cancelled payment outcome. |
292 | * | |
3aaa68fb | 293 | * @param array $objects |
294 | * @param CRM_Core_Transaction $transaction | |
6c786a9b EM |
295 | * @param array $input |
296 | * | |
297 | * @return bool | |
e44c82e1 | 298 | * @throws \CiviCRM_API3_Exception |
6c786a9b | 299 | */ |
be2fb01f | 300 | public function cancelled(&$objects, &$transaction, $input = []) { |
6a488035 | 301 | $contribution = &$objects['contribution']; |
e44c82e1 MWMC |
302 | $memberships = []; |
303 | if (!empty($objects['membership'])) { | |
304 | $memberships = &$objects['membership']; | |
305 | if (is_numeric($memberships)) { | |
306 | $memberships = [$objects['membership']]; | |
307 | } | |
6a488035 TO |
308 | } |
309 | ||
6a488035 TO |
310 | $addLineItems = FALSE; |
311 | if (empty($contribution->id)) { | |
312 | $addLineItems = TRUE; | |
313 | } | |
e44c82e1 MWMC |
314 | $participant = &$objects['participant']; |
315 | ||
316 | // CRM-15546 | |
be2fb01f | 317 | $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [ |
518fa0ee SL |
318 | 'labelColumn' => 'name', |
319 | 'flip' => 1, | |
320 | ]); | |
71d085fe | 321 | $contribution->contribution_status_id = $contributionStatuses['Cancelled']; |
6a488035 TO |
322 | $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date); |
323 | $contribution->receipt_date = CRM_Utils_Date::isoToMysql($contribution->receipt_date); | |
324 | $contribution->thankyou_date = CRM_Utils_Date::isoToMysql($contribution->thankyou_date); | |
e44c82e1 MWMC |
325 | $contribution->cancel_date = self::$_now; |
326 | $contribution->cancel_reason = CRM_Utils_Array::value('reasonCode', $input); | |
6a488035 TO |
327 | $contribution->save(); |
328 | ||
e44c82e1 | 329 | // Add line items for recurring payments. |
a7488080 | 330 | if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id && $addLineItems) { |
e577770c | 331 | CRM_Contribute_BAO_ContributionRecur::addRecurLineItems($objects['contributionRecur']->id, $contribution); |
6a488035 TO |
332 | } |
333 | ||
8381af80 | 334 | //add new soft credit against current $contribution and |
6357981e | 335 | //copy initial contribution custom fields for recurring contributions |
a7488080 | 336 | if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id) { |
e577770c EM |
337 | CRM_Contribute_BAO_ContributionRecur::addrecurSoftCredit($objects['contributionRecur']->id, $contribution->id); |
338 | CRM_Contribute_BAO_ContributionRecur::copyCustomValues($objects['contributionRecur']->id, $contribution->id); | |
6357981e PJ |
339 | } |
340 | ||
0bad10e7 | 341 | if (empty($input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'])) { |
6a488035 TO |
342 | if (!empty($memberships)) { |
343 | foreach ($memberships as $membership) { | |
56c7d914 MWMC |
344 | if ($membership) { |
345 | $this->cancelMembership($membership, $membership->status_id); | |
6a488035 TO |
346 | } |
347 | } | |
348 | } | |
d63f4fc3 | 349 | |
6a488035 | 350 | if ($participant) { |
56c7d914 | 351 | $this->cancelParticipant($participant->id); |
6a488035 TO |
352 | } |
353 | } | |
354 | $transaction->commit(); | |
e44c82e1 | 355 | Civi::log()->debug("Setting contribution status to Cancelled"); |
6a488035 TO |
356 | return TRUE; |
357 | } | |
358 | ||
6c786a9b | 359 | /** |
1d86918a EM |
360 | * Rollback unhandled outcomes. |
361 | * | |
3aaa68fb | 362 | * @param array $objects |
363 | * @param CRM_Core_Transaction $transaction | |
6c786a9b EM |
364 | * |
365 | * @return bool | |
366 | */ | |
00be9182 | 367 | public function unhandled(&$objects, &$transaction) { |
6a488035 | 368 | $transaction->rollback(); |
e44c82e1 | 369 | Civi::log()->debug("Returning since contribution status is not handled"); |
2d8851f6 | 370 | echo "Failure: contribution status is not handled<p>"; |
6a488035 TO |
371 | return FALSE; |
372 | } | |
373 | ||
56c7d914 MWMC |
374 | /** |
375 | * Logic to cancel a participant record when the related contribution changes to failed/cancelled. | |
376 | * @todo This is part of a bigger refactor for dev/core/issues/927 - "duplicate" functionality exists in CRM_Contribute_BAO_Contribution::cancel() | |
377 | * | |
378 | * @param $participantID | |
379 | * | |
380 | * @throws \CiviCRM_API3_Exception | |
381 | */ | |
382 | private function cancelParticipant($participantID) { | |
383 | // @fixme https://lab.civicrm.org/dev/core/issues/927 Cancelling membership etc is not desirable for all use-cases and we should be able to disable it | |
384 | $participantParams['id'] = $participantID; | |
385 | $participantParams['status_id'] = 'Cancelled'; | |
386 | civicrm_api3('Participant', 'create', $participantParams); | |
387 | } | |
388 | ||
389 | /** | |
390 | * Logic to cancel a membership record when the related contribution changes to failed/cancelled. | |
391 | * @todo This is part of a bigger refactor for dev/core/issues/927 - "duplicate" functionality exists in CRM_Contribute_BAO_Contribution::cancel() | |
392 | * @param \CRM_Member_BAO_Membership $membership | |
393 | * @param int $membershipStatusID | |
394 | * @param boolean $onlyCancelPendingMembership | |
395 | * Do we only cancel pending memberships? OR memberships in any status? (see CRM-18688) | |
396 | * @fixme Historically failed() cancelled membership in any status, cancelled() cancelled only pending memberships so we retain that behaviour for now. | |
397 | * | |
398 | */ | |
399 | private function cancelMembership($membership, $membershipStatusID, $onlyCancelPendingMembership = TRUE) { | |
400 | // @fixme https://lab.civicrm.org/dev/core/issues/927 Cancelling membership etc is not desirable for all use-cases and we should be able to disable it | |
401 | // Cancel only Pending memberships | |
402 | $pendingMembershipStatusId = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Pending'); | |
403 | if (($membershipStatusID == $pendingMembershipStatusId) || ($onlyCancelPendingMembership == FALSE)) { | |
404 | $cancelledMembershipStatusId = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Cancelled'); | |
405 | ||
406 | $membership->status_id = $cancelledMembershipStatusId; | |
407 | $membership->save(); | |
408 | ||
409 | $params = ['status_id' => $cancelledMembershipStatusId]; | |
410 | CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $params); | |
411 | ||
412 | // @todo Convert the above to API | |
413 | // $membershipParams = [ | |
414 | // 'id' => $membership->id, | |
415 | // 'status_id' => $cancelledMembershipStatusId, | |
416 | // ]; | |
417 | // civicrm_api3('Membership', 'create', $membershipParams); | |
418 | // CRM_Member_BAO_Membership::updateRelatedMemberships($membershipParams['id'], ['status_id' => $cancelledMembershipStatusId]); | |
419 | } | |
420 | ||
421 | } | |
422 | ||
6c786a9b | 423 | /** |
4a1ba425 | 424 | * @deprecated |
425 | * | |
3ccde016 | 426 | * Jumbled up function. |
1d86918a | 427 | * |
3ccde016 EM |
428 | * The purpose of this function is to transition a pending transaction to Completed including updating any |
429 | * related entities. | |
430 | * | |
431 | * It has been overloaded to also add recurring transactions to the database, cloning the original transaction and | |
432 | * updating related entities. | |
433 | * | |
434 | * It is recommended to avoid calling this function directly and call the api functions: | |
435 | * - contribution.completetransaction | |
436 | * - contribution.repeattransaction | |
437 | * | |
438 | * These functions are the focus of testing efforts and more accurately reflect the division of roles | |
439 | * (the job of the IPN class is to determine the outcome, transaction id, invoice id & to validate the source | |
440 | * and from there it should be possible to pass off transaction management.) | |
441 | * | |
442 | * This function has been problematic for some time but there are now several tests via the api_v3_Contribution test | |
443 | * and the Paypal & Authorize.net IPN tests so any refactoring should be done in conjunction with those. | |
444 | * | |
5ca657dd | 445 | * This function needs to have the 'body' moved to the CRM_Contribute_BAO_Contribute class and to undergo |
3ccde016 EM |
446 | * refactoring to separate the complete transaction and repeat transaction functionality into separate functions with |
447 | * a shared function that updates related components. | |
448 | * | |
449 | * Note that it is not necessary payment processor extension to implement an IPN class now. In general the code on the | |
450 | * IPN class is better accessed through the api which de-jumbles it a bit. | |
451 | * | |
452 | * e.g the payment class can have a function like (based on Omnipay extension): | |
453 | * | |
454 | * public function handlePaymentNotification() { | |
455 | * $response = $this->getValidatedOutcome(); | |
456 | * if ($response->isSuccessful()) { | |
457 | * try { | |
458 | * // @todo check if it is a repeat transaction & call repeattransaction instead. | |
459 | * civicrm_api3('contribution', 'completetransaction', array('id' => $this->transaction_id)); | |
460 | * } | |
461 | * catch (CiviCRM_API3_Exception $e) { | |
462 | * if (!stristr($e->getMessage(), 'Contribution already completed')) { | |
463 | * $this->handleError('error', $this->transaction_id . $e->getMessage(), 'ipn_completion', 9000, 'An error may | |
464 | * have occurred. Please check your receipt is correct'); | |
465 | * $this->redirectOrExit('success'); | |
466 | * } | |
467 | * elseif ($this->transaction_id) { | |
468 | * civicrm_api3('contribution', 'create', array('id' => $this->transaction_id, 'contribution_status_id' => | |
469 | * 'Failed')); | |
470 | * } | |
471 | * | |
472 | * @param array $input | |
473 | * @param array $ids | |
474 | * @param array $objects | |
3aaa68fb | 475 | * @param CRM_Core_Transaction $transaction |
6c786a9b | 476 | * @param bool $recur |
e44c82e1 MWMC |
477 | * |
478 | * @throws \CRM_Core_Exception | |
479 | * @throws \CiviCRM_API3_Exception | |
6c786a9b | 480 | */ |
00be9182 | 481 | public function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE) { |
6a488035 | 482 | $contribution = &$objects['contribution']; |
a284891b | 483 | |
4086637a | 484 | CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, $recur, $contribution); |
6a488035 TO |
485 | } |
486 | ||
6c786a9b | 487 | /** |
1d86918a EM |
488 | * Get site billing ID. |
489 | * | |
490 | * @param array $ids | |
6c786a9b EM |
491 | * |
492 | * @return bool | |
493 | */ | |
00be9182 | 494 | public function getBillingID(&$ids) { |
b576d770 | 495 | $ids['billing'] = CRM_Core_BAO_LocationType::getBilling(); |
6a488035 | 496 | if (!$ids['billing']) { |
be2fb01f | 497 | CRM_Core_Error::debug_log_message(ts('Please set a location type of %1', [1 => 'Billing'])); |
6a488035 TO |
498 | echo "Failure: Could not find billing location type<p>"; |
499 | return FALSE; | |
500 | } | |
501 | return TRUE; | |
502 | } | |
503 | ||
c490a46a | 504 | /** |
db59bb73 EM |
505 | * @deprecated |
506 | * | |
6626a693 | 507 | * @todo confirm this function is not being used by any payment processor outside core & remove. |
508 | * | |
1d86918a | 509 | * Note that the compose message part has been moved to contribution |
6a488035 TO |
510 | * In general LoadObjects is called first to get the objects but the composeMessageArray function now calls it |
511 | * | |
6a0b768e TO |
512 | * @param array $input |
513 | * Incoming data from Payment processor. | |
514 | * @param array $ids | |
515 | * Related object IDs. | |
3aaa68fb | 516 | * @param array $objects |
6a0b768e TO |
517 | * @param array $values |
518 | * Values related to objects that have already been loaded. | |
519 | * @param bool $recur | |
520 | * Is it part of a recurring contribution. | |
521 | * @param bool $returnMessageText | |
522 | * Should text be returned instead of sent. This. | |
16b10e64 | 523 | * is because the function is also used to generate pdfs |
6c786a9b | 524 | * |
c490a46a | 525 | * @return array |
e44c82e1 MWMC |
526 | * @throws \CRM_Core_Exception |
527 | * @throws \CiviCRM_API3_Exception | |
6c786a9b | 528 | */ |
00be9182 | 529 | public function sendMail(&$input, &$ids, &$objects, &$values, $recur = FALSE, $returnMessageText = FALSE) { |
6626a693 | 530 | return CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, |
3425da09 | 531 | $returnMessageText); |
6a488035 TO |
532 | } |
533 | ||
b2b0530a | 534 | } |