[#10] protect against SEPA double termination

This commit is contained in:
B. Endres 2019-11-15 11:12:54 +01:00
commit c6cb61905a

View file

@ -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,