X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FEvent%2FForm%2FTask%2FBatch.php;h=6acd8c742a94274f6b62fb5f68f7ea757a8cb5f9;hb=7e9e8871fab6ef8220dffbe418460ebc9c61ed33;hp=6b9179dacb476d8c177b29b2c048e910ad06a98c;hpb=23049f2786d83845f95f6e28f5866c550874c189;p=civicrm-core.git diff --git a/CRM/Event/Form/Task/Batch.php b/CRM/Event/Form/Task/Batch.php index 6b9179dacb..6acd8c742a 100644 --- a/CRM/Event/Form/Task/Batch.php +++ b/CRM/Event/Form/Task/Batch.php @@ -1,7 +1,7 @@ 'Event', 'contribution_id' => $contributionId, 'contribution_status_id' => $contributionStatusId, - 'skipComponentSync' => 1, + 'IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved' => 1, ); //change related contribution status. - $updatedStatusId = CRM_Core_Payment_BaseIPN::updateContributionStatus($params); + $updatedStatusId = self::updateContributionStatus($params); return $updatedStatusId; } + /** + * Update contribution status. + * + * @deprecated + * This is only called from one place in the code & + * it is unclear whether it is a function on the way in or on the way out + * + * @param array $params + * + * @return NULL|int + */ + public static function updateContributionStatus($params) { + // get minimum required values. + $statusId = CRM_Utils_Array::value('contribution_status_id', $params); + $componentId = CRM_Utils_Array::value('component_id', $params); + $componentName = CRM_Utils_Array::value('componentName', $params); + $contributionId = CRM_Utils_Array::value('contribution_id', $params); + + if (!$contributionId || !$componentId || !$componentName || !$statusId) { + return NULL; + } + + $input = $ids = $objects = array(); + + //get the required ids. + $ids['contribution'] = $contributionId; + + if (!$ids['contact'] = CRM_Utils_Array::value('contact_id', $params)) { + $ids['contact'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', + $contributionId, + 'contact_id' + ); + } + + if ($componentName == 'Event') { + $name = 'event'; + $ids['participant'] = $componentId; + + if (!$ids['event'] = CRM_Utils_Array::value('event_id', $params)) { + $ids['event'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', + $componentId, + 'event_id' + ); + } + } + + if ($componentName == 'Membership') { + $name = 'contribute'; + $ids['membership'] = $componentId; + } + $ids['contributionPage'] = NULL; + $ids['contributionRecur'] = NULL; + $input['component'] = $name; + + $baseIPN = new CRM_Core_Payment_BaseIPN(); + $transaction = new CRM_Core_Transaction(); + + // reset template values. + $template = CRM_Core_Smarty::singleton(); + $template->clearTemplateVars(); + + if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) { + CRM_Core_Error::fatal(); + } + + $contribution = &$objects['contribution']; + + $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array( + 'labelColumn' => 'name', + 'flip' => 1, + )); + $input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'] = CRM_Utils_Array::value('IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved', $params); + if ($statusId == $contributionStatuses['Cancelled']) { + $baseIPN->cancelled($objects, $transaction, $input); + $transaction->commit(); + return $statusId; + } + elseif ($statusId == $contributionStatuses['Failed']) { + $baseIPN->failed($objects, $transaction, $input); + $transaction->commit(); + return $statusId; + } + + // status is not pending + if ($contribution->contribution_status_id != $contributionStatuses['Pending']) { + $transaction->commit(); + return; + } + + //set values for ipn code. + foreach (array( + 'fee_amount', + 'check_number', + 'payment_instrument_id', + ) as $field) { + if (!$input[$field] = CRM_Utils_Array::value($field, $params)) { + $input[$field] = $contribution->$field; + } + } + if (!$input['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params)) { + $input['trxn_id'] = $contribution->invoice_id; + } + if (!$input['amount'] = CRM_Utils_Array::value('total_amount', $params)) { + $input['amount'] = $contribution->total_amount; + } + $input['is_test'] = $contribution->is_test; + $input['net_amount'] = $contribution->net_amount; + if (!empty($input['fee_amount']) && !empty($input['amount'])) { + $input['net_amount'] = $input['amount'] - $input['fee_amount']; + } + + //complete the contribution. + $baseIPN->completeTransaction($input, $ids, $objects, $transaction, FALSE); + + // reset template values before processing next transactions + $template->clearTemplateVars(); + + return $statusId; + } + }