[#10] only terminate 'live' mandates

This commit is contained in:
B. Endres 2019-11-15 09:16:07 +01:00
parent 33c81951fc
commit 98ff2f4550

View file

@ -87,6 +87,16 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
time(), time(),
date_create_from_format('Ymd', $params['cancelled_at'])->getTimestamp() 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( if (!CRM_Sepa_BAO_SEPAMandate::terminateMandate(
$mandate_id, $mandate_id,
$end_date, $end_date,