From 98ff2f45509665ccd5229f459acaa0dfef938485 Mon Sep 17 00:00:00 2001 From: "B. Endres" Date: Fri, 15 Nov 2019 09:16:07 +0100 Subject: [PATCH] [#10] only terminate 'live' mandates --- api/v3/TwingleDonation/Endrecurring.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/v3/TwingleDonation/Endrecurring.php b/api/v3/TwingleDonation/Endrecurring.php index 005b6c9..83f20e0 100644 --- a/api/v3/TwingleDonation/Endrecurring.php +++ b/api/v3/TwingleDonation/Endrecurring.php @@ -87,6 +87,16 @@ function civicrm_api3_twingle_donation_endrecurring($params) { time(), date_create_from_format('Ymd', $params['cancelled_at'])->getTimestamp() )); + + // verify that the mandate has not been terminated in the past + $mandate_status = civicrm_api3('SepaMandate', 'getvalue', ['return' => 'status', 'id' => $mandate_id]); + if ($mandate_status != 'FRST' && $mandate_status != 'RCUR') { + throw new CiviCRM_API3_Exception( + E::ts("SEPA Mandate [%1] already terminated.", [1 => $mandate_id]), + 'api_error' + ); + } + if (!CRM_Sepa_BAO_SEPAMandate::terminateMandate( $mandate_id, $end_date,