The failed action has no discernable difference from the no-longer-used cancel action. The cancel action had some minor refactoring
done to work through the conclusion that the call to addRecurLineItems was never reached in a meaningful way
but I think we can skip all that & see that fail is not functionally different to cancel & just deprecate the function.
At this point we are very close to simply removing the last core handling for failed & cance & making the extension visible.
The only thing I can see that still needs checking in the 2 functions still to be removed is the handling of
is_override & override_date is tested - which I will do as a follow up
*
* @param array $objects
*
+ * @deprecated use the api.
+ *
* @return bool
* @throws \CiviCRM_API3_Exception|\CRM_Core_Exception
*/
public function failed($objects) {
+ CRM_Core_Error::deprecatedFunctionWarning('use the api');
$contribution = &$objects['contribution'];
$memberships = [];
if (!empty($objects['membership'])) {
/**
* Main function.
*
- * @throws \CRM_Core_Exception
+ * @throws \API_Exception
* @throws \CiviCRM_API3_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
public function main() {
try {
$status = $input['paymentStatus'];
if ($status === 'Denied' || $status === 'Failed' || $status === 'Voided') {
- $this->failed($objects);
+ Contribution::update(FALSE)->setValues([
+ 'cancel_date' => 'now',
+ 'contribution_status_id:name' => 'Failed',
+ ])->addWhere('id', '=', $contributionID)->execute();
+ Civi::log()->debug("Setting contribution status to Failed");
return;
}
if ($status === 'Pending') {
* @param bool $first
*
* @return void
+ * @throws \API_Exception
*/
public function single($input, $ids, $objects, $recur = FALSE, $first = FALSE) {
$contribution = &$objects['contribution'];
$status = $input['paymentStatus'];
if ($status === 'Denied' || $status === 'Failed' || $status === 'Voided') {
- $this->failed($objects);
+ Contribution::update(FALSE)->setValues([
+ 'cancel_date' => 'now',
+ 'contribution_status_id:name' => 'Failed',
+ ])->addWhere('id', '=', $contribution->id)->execute();
+ Civi::log()->debug("Setting contribution status to Failed");
return;
}
if ($status === 'Pending') {
*
* This enacts the following
* - find and cancel any related pending memberships
- * - (not yet implemented) find and cancel any related pending participant records
- * - (not yet implemented) find any related pledge payment records. Remove the contribution id.
+ * - (not yet implemented) find and cancel any related pending participant
+ * records
+ * - (not yet implemented) find any related pledge payment records. Remove the
+ * contribution id.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws \API_Exception
*/
function contributioncancelactions_civicrm_post($op, $objectName, $objectId, $objectRef) {
if ($op === 'edit' && $objectName === 'Contribution') {
- if ('Cancelled' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $objectRef->contribution_status_id)) {
+ if (in_array(CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $objectRef->contribution_status_id),
+ ['Cancelled', 'Failed']
+ )) {
contributioncancelactions_cancel_related_pending_memberships((int) $objectId);
contributioncancelactions_cancel_related_pending_participant_records((int) $objectId);
contributioncancelactions_update_related_pledge((int) $objectId, (int) $objectRef->contribution_status_id);
$this->assertEquals(2, $cancelledActivatesCount['count']);
}
- public function testThatFailedEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() {
+ /**
+ * Test that related pending participant records are cancelled.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
+ */
+ public function testThatFailedEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities(): void {
$this->_setUpParticipantObjects('Pending from incomplete transaction');
- $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$additionalParticipantId = $this->participantCreate([
'event_id' => $this->_eventId,
'registered_by_id' => $this->_participantId,
'status_id' => 'Pending from incomplete transaction',
]);
- $this->IPN->failed($this->objects);
+ Contribution::update(FALSE)->setValues([
+ 'cancel_date' => 'now',
+ 'contribution_status_id:name' => 'Failed',
+ ])->addWhere('id', '=', $this->ids['contribution'])->execute();
$cancelledParticipantsCount = civicrm_api3('Participant', 'get', [
'sequential' => 1,
*
* @throws \CRM_Core_Exception
*/
- public function _setUpParticipantObjects($participantStatus = 'Attended') {
+ public function _setUpParticipantObjects($participantStatus = 'Attended'): void {
$event = $this->eventCreate(['is_email_confirm' => 1]);
$this->_eventId = $event['id'];
$contribution->id = $this->_contributionId;
$contribution->find();
$this->objects['contribution'] = $contribution;
+ $this->ids['contribution'] = $contribution->id;
$this->input = [
'component' => 'event',
'total_amount' => 150.00,