compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

CIWEMB-102: Allow deleting a payment scheme. #472

Closed erawat closed 1 year ago

erawat commented 1 year ago

Overview

This PR adds the ability to delete a payment scheme that has not been linked to any recurring contribution.

Before

Delete link did not work.

After

Screencast shows a payment scheme cannot be deleted if it has been linked to a recurring contribution(s). The error toast message will display if the payment scheme cannot be deleted.

screencast to delete payment scheme.webm

Screencast shows payment scheme was deleted successfully.

screencast-compucorp.atlassian.net-2023.06.06-14_31_21.webm

Technical Details

In this PR, I updated the existing class CRM_MembershipExtras_Form_PaymentScheme in process deletion in delete and add the logic to validate if payment scheme is linked to any recurring contribution by using ContributionRecur API v4 to check.

 \Civi\Api4\ContributionRecur::get()
      ->selectRowCount()
      ->addWhere('payment_plan_extra_attributes.payment_scheme_id', '=', $this->id)
      ->execute()->count();

In the smarty template, I also added the condition to display delete warning message by checking if the action equals to 8 which aligns with constant in Civi Action class