[#13] SEPA Code depedency (merged dev_13)
This commit is contained in:
commit
d6b90dcec2
5 changed files with 90 additions and 35 deletions
|
@ -94,17 +94,32 @@ function civicrm_api3_twingle_donation_Cancel($params) {
|
|||
$contribution_type = 'ContributionRecur';
|
||||
}
|
||||
|
||||
// End SEPA mandate if applicable.
|
||||
if (
|
||||
CRM_Twingle_Submission::civiSepaEnabled()
|
||||
&& CRM_Sepa_Logic_Settings::isSDD($contribution)
|
||||
&& CRM_Twingle_Tools::isSDD($contribution['payment_instrument_id'])
|
||||
) {
|
||||
$mandate_id = CRM_Sepa_Logic_Settings::getMandateFor($contribution['id']);
|
||||
// End SEPA mandate if applicable.
|
||||
$mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']);
|
||||
if (!$mandate) {
|
||||
throw new CiviCRM_API3_Exception(
|
||||
E::ts("SEPA Mandate for contribution [%1 not found.", [1 => $contribution['id']]),
|
||||
'api_error'
|
||||
);
|
||||
}
|
||||
$mandate_id = (int) $mandate['id'];
|
||||
|
||||
// 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 = date_create_from_format('YmdHis', $params['cancelled_at']);
|
||||
if ($end_date) {
|
||||
// Mandates can not be terminated in the past:
|
||||
$end_date = date('Ymd', max(
|
||||
time(),
|
||||
$end_date->getTimestamp()));
|
||||
} else {
|
||||
// end date couldn't be parsed, use 'now'
|
||||
$end_date = date('Ymd');
|
||||
}
|
||||
|
||||
if (!CRM_Sepa_BAO_SEPAMandate::terminateMandate(
|
||||
$mandate_id,
|
||||
$end_date,
|
||||
|
@ -122,6 +137,7 @@ function civicrm_api3_twingle_donation_Cancel($params) {
|
|||
));
|
||||
}
|
||||
else {
|
||||
// regular contribution
|
||||
CRM_Twingle_Tools::$protection_suspended = TRUE;
|
||||
$contribution = civicrm_api3($contribution_type, 'create', array(
|
||||
'id' => $contribution['id'],
|
||||
|
|
|
@ -76,22 +76,36 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
|
|||
$contribution = civicrm_api3('ContributionRecur', 'getsingle', array(
|
||||
'trxn_id' => $default_profile->getTransactionID($params['trx_id']),
|
||||
));
|
||||
|
||||
// End SEPA mandate (which ends the associated recurring contribution) or
|
||||
// recurring contributions.
|
||||
if (
|
||||
CRM_Twingle_Submission::civiSepaEnabled()
|
||||
&& CRM_Sepa_Logic_Settings::isSDD($contribution)
|
||||
&& 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('Ymd', max(
|
||||
time(),
|
||||
date_create_from_format('Ymd', $params['cancelled_at'])->getTimestamp()
|
||||
));
|
||||
// END SEPA MANDATE
|
||||
$mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']);
|
||||
if (!$mandate) {
|
||||
throw new CiviCRM_API3_Exception(
|
||||
E::ts("SEPA Mandate for recurring contribution [%1 not found.", [1 => $contribution['id']]),
|
||||
'api_error'
|
||||
);
|
||||
}
|
||||
|
||||
$mandate_id = $mandate['id'];
|
||||
$end_date = date_create_from_format('YmdHis', $params['ended_at']);
|
||||
if ($end_date) {
|
||||
// Mandates can not be terminated in the past:
|
||||
$end_date = date('Ymd', max(
|
||||
time(),
|
||||
$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]);
|
||||
if ($mandate_status != 'FRST' && $mandate_status != 'RCUR') {
|
||||
if ($mandate['status'] != 'FRST' && $mandate['status'] != 'RCUR') {
|
||||
throw new CiviCRM_API3_Exception(
|
||||
E::ts("SEPA Mandate [%1] already terminated.", [1 => $mandate_id]),
|
||||
'api_error'
|
||||
|
@ -113,11 +127,12 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
|
|||
));
|
||||
}
|
||||
else {
|
||||
// END RECURRING CONTRIBUTION
|
||||
CRM_Twingle_Tools::$protection_suspended = TRUE;
|
||||
$contribution = civicrm_api3('ContributionRecur', 'create', array(
|
||||
'id' => $contribution['id'],
|
||||
'end_date' => $params['ended_at'],
|
||||
'contribution_status_id' => CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED,
|
||||
'id' => $contribution['id'],
|
||||
'end_date' => $params['ended_at'],
|
||||
'contribution_status_id' => CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED,
|
||||
));
|
||||
CRM_Twingle_Tools::$protection_suspended = FALSE;
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ function _civicrm_api3_twingle_donation_Submit_spec(&$params) {
|
|||
);
|
||||
$params['user_email'] = array(
|
||||
'name' => 'user_email',
|
||||
'title' => E::ts('E-mail address'),
|
||||
'title' => E::ts('Email address'),
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'api.required' => 0,
|
||||
'description' => E::ts('The e-mail address of the contact.'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue