Skip to content

Commit

Permalink
Merge pull request #274 from compucorp/CIWEMB-257-hide-mandate-fornondd
Browse files Browse the repository at this point in the history
CIWEMB-257: Only show 'use new mandate' action on manual direct debit payment plans
  • Loading branch information
omarabuhussein authored Jun 7, 2023
2 parents 4f2040e + 5600a19 commit 4ef1aa3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CRM/ManualDirectDebit/Hook/Links/LinkProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public function __construct(&$links) {
* @param $recurringContributionId
*/
public function alterRecurContributionLinks(&$values, $recurringContributionId) {
if (!$this->isAlreadyLinkedToMandate($recurringContributionId)) {
return;
}

$contactId = CRM_Utils_Request::retrieve('cid', 'Integer');
$contactType = $this->getContactType($contactId);

Expand All @@ -37,6 +41,16 @@ public function alterRecurContributionLinks(&$values, $recurringContributionId)
$values['updatedRecId'] = $recurringContributionId;
}

private function isAlreadyLinkedToMandate($recurringContributionId) {
CRM_ManualDirectDebit_Common_DirectDebitDataProvider::isPaymentMethodDirectDebit($this->contributionRecurDao->payment_instrument_id);
$linkedMandateId = CRM_ManualDirectDebit_BAO_RecurrMandateRef::getMandateIdForRecurringContribution($recurringContributionId);
if (empty($linkedMandateId)) {
return FALSE;
}

return TRUE;
}

private function getContactType($contactId) {
return civicrm_api3('Contact', 'getvalue', [
'return' => 'contact_type',
Expand Down

0 comments on commit 4ef1aa3

Please sign in to comment.