[#13] fixed end date issues

This commit is contained in:
B. Endres 2019-11-23 08:46:23 +01:00
parent 383e392ff0
commit 24d93ed1f1

View file

@ -83,11 +83,16 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
&& CRM_Twingle_Tools::isSDD($contribution['payment_instrument_id'])
) {
$mandate_id = CRM_Sepa_Logic_Settings::getMandateFor($contribution['id']);
// Mandates can not be terminated in the past.
$end_date = date_create_from_format('Ymd', $params['ended_at']);
if ($end_date) {
// Mandates can not be terminated in the past:
$end_date = date('Ymd', max(
time(),
date_create_from_format('Ymd', $params['cancelled_at'])->getTimestamp()
));
$end_date->getTimestamp()));
} else {
// end date couldn't be parsed, use 'now'
$end_date = date('Ymd');
}
// verify that the mandate has not been terminated in the past
$mandate_status = civicrm_api3('SepaMandate', 'getvalue', ['return' => 'status', 'id' => $mandate_id]);