[WIP] TwingleDonation.Submit API action for SEPA mandates.
This commit is contained in:
parent
3856ef6170
commit
42c40e8c00
5 changed files with 285 additions and 113 deletions
|
@ -129,6 +129,28 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
TRUE // is required
|
||||
);
|
||||
|
||||
$this->add(
|
||||
'select',
|
||||
'gender_male',
|
||||
E::ts('Gender option for submitted value "male"'),
|
||||
$this->getGenderOptions(),
|
||||
TRUE
|
||||
);
|
||||
$this->add(
|
||||
'select',
|
||||
'gender_female',
|
||||
E::ts('Gender option for submitted value "female"'),
|
||||
$this->getGenderOptions(),
|
||||
TRUE
|
||||
);
|
||||
$this->add(
|
||||
'select',
|
||||
'gender_other',
|
||||
E::ts('Gender option for submitted value "other"'),
|
||||
$this->getGenderOptions(),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$payment_instruments = CRM_Twingle_Profile::paymentInstruments();
|
||||
$this->assign('payment_instruments', $payment_instruments);
|
||||
foreach ($payment_instruments as $pi_name => $pi_label) {
|
||||
|
@ -141,6 +163,16 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
);
|
||||
}
|
||||
|
||||
if (CRM_Twingle_Submission::civiSepaEnabled()) {
|
||||
$this->add(
|
||||
'select',
|
||||
'sepa_creditor_id',
|
||||
E::ts('CiviSEPA creditor'),
|
||||
$this->getSepaCreditors(),
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
$this->add(
|
||||
'select', // field type
|
||||
'newsletter_groups', // field name
|
||||
|
@ -282,17 +314,42 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
* Retrieves campaigns present within the system as options for select form
|
||||
* elements.
|
||||
*/
|
||||
public function getCampaigns() {
|
||||
$campaigns = array('' => E::ts("no campaign"));
|
||||
$query = civicrm_api3('Campaign', 'get', array(
|
||||
public function getGenderOptions() {
|
||||
$genders = array();
|
||||
$query = civicrm_api3('OptionValue', 'get', array(
|
||||
'option_group_id' => 'gender',
|
||||
'is_active' => 1,
|
||||
'option.limit' => 0,
|
||||
'return' => 'id,title'
|
||||
'return' => array(
|
||||
'value',
|
||||
'label',
|
||||
),
|
||||
));
|
||||
foreach ($query['values'] as $campaign) {
|
||||
$campaigns[$campaign['id']] = $campaign['title'];
|
||||
foreach ($query['values'] as $gender) {
|
||||
$genders[$gender['value']] = $gender['label'];
|
||||
}
|
||||
return $campaigns;
|
||||
return $genders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves CiviSEPA creditors as options for select form elements.
|
||||
*
|
||||
* @return array
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public function getSepaCreditors() {
|
||||
$creditors = array();
|
||||
|
||||
if (CRM_Twingle_Submission::civiSepaEnabled()) {
|
||||
$result = civicrm_api3('SepaCreditor', 'get', array(
|
||||
'option.limit' => 0,
|
||||
));
|
||||
foreach ($result['values'] as $sepa_creditor) {
|
||||
$creditors[$sepa_creditor['id']] = $sepa_creditor['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $creditors;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,7 +366,21 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
'return' => 'value,label'
|
||||
));
|
||||
foreach ($query['values'] as $payment_instrument) {
|
||||
self::$_paymentInstruments[$payment_instrument['value']] = $payment_instrument['label'];
|
||||
// Do not include CiviSEPA payment instruments, but add a SEPA option if
|
||||
// enabled.
|
||||
if (
|
||||
CRM_Twingle_Submission::civiSepaEnabled()
|
||||
&& CRM_Sepa_Logic_Settings::isSDD(array(
|
||||
'payment_instrument_id' => $payment_instrument['value'],
|
||||
))
|
||||
) {
|
||||
if (!isset(self::$_paymentInstruments['sepa'])) {
|
||||
self::$_paymentInstruments['sepa'] = E::ts('CiviSEPA');
|
||||
}
|
||||
}
|
||||
else {
|
||||
self::$_paymentInstruments[$payment_instrument['value']] = $payment_instrument['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return self::$_paymentInstruments;
|
||||
|
@ -338,7 +409,23 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
}
|
||||
}
|
||||
else {
|
||||
$groups[''] = E::ts('No newsletter groups available');
|
||||
$groups[''] = E::ts('No mailing lists available');
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves active groups as options for select form elements.
|
||||
*/
|
||||
public function getGroups() {
|
||||
$groups = array();
|
||||
$query = civicrm_api3('Group', 'get', array(
|
||||
'is_active' => 1,
|
||||
'option.limit' => 0,
|
||||
'return' => 'id,name'
|
||||
));
|
||||
foreach ($query['values'] as $group) {
|
||||
$groups[$group['id']] = $group['name'];
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
@ -348,27 +435,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
* options for select form elements.
|
||||
*/
|
||||
public function getPostinfoGroups() {
|
||||
$groups = array();
|
||||
$group_types = civicrm_api3('OptionValue', 'get', array(
|
||||
'option_group_id' => 'group_type',
|
||||
'name' => CRM_Twingle_Submission::GROUP_TYPE_POSTINFO,
|
||||
));
|
||||
if ($group_types['count'] > 0) {
|
||||
$group_type = reset($group_types['values']);
|
||||
$query = civicrm_api3('Group', 'get', array(
|
||||
'is_active' => 1,
|
||||
'group_type' => array('LIKE' => '%' . CRM_Utils_Array::implodePadded($group_type['value']) . '%'),
|
||||
'option.limit' => 0,
|
||||
'return' => 'id,name'
|
||||
));
|
||||
foreach ($query['values'] as $group) {
|
||||
$groups[$group['id']] = $group['name'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$groups[''] = E::ts('No postal mailing groups available');
|
||||
}
|
||||
return $groups;
|
||||
return $this->getGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -376,27 +443,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
* system as options for select form elements.
|
||||
*/
|
||||
public function getDonationReceiptGroups() {
|
||||
$groups = array();
|
||||
$group_types = civicrm_api3('OptionValue', 'get', array(
|
||||
'option_group_id' => 'group_type',
|
||||
'name' => CRM_Twingle_Submission::GROUP_TYPE_DONATION_RECEIPT,
|
||||
));
|
||||
if ($group_types['count'] > 0) {
|
||||
$group_type = reset($group_types['values']);
|
||||
$query = civicrm_api3('Group', 'get', array(
|
||||
'is_active' => 1,
|
||||
'group_type' => array('LIKE' => '%' . CRM_Utils_Array::implodePadded($group_type['value']) . '%'),
|
||||
'option.limit' => 0,
|
||||
'return' => 'id,name'
|
||||
));
|
||||
foreach ($query['values'] as $group) {
|
||||
$groups[$group['id']] = $group['name'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$groups[''] = E::ts('No donation receipt groups available');
|
||||
}
|
||||
return $groups;
|
||||
return $this->getGroups();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -180,6 +180,10 @@ class CRM_Twingle_Profile {
|
|||
'pi_paydirekt',
|
||||
'pi_applepay',
|
||||
'pi_googlepay',
|
||||
'sepa_creditor_id',
|
||||
'gender_male',
|
||||
'gender_female',
|
||||
'gender_other',
|
||||
'newsletter_groups',
|
||||
'postinfo_groups',
|
||||
'donation_receipt_groups'
|
||||
|
@ -221,19 +225,23 @@ class CRM_Twingle_Profile {
|
|||
'location_type_id' => CRM_Twingle_Submission::LOCATION_TYPE_ID_WORK,
|
||||
'financial_type_id' => 1, // "Donation"
|
||||
'pi_banktransfer' => 5, // "EFT"
|
||||
'pi_debit_manual' => '', // TODO: SEPA
|
||||
'pi_debit_manual' => NULL,
|
||||
'pi_debit_automatic' => 3, // Debit
|
||||
'pi_creditcard' => 1, // "Credit Card"
|
||||
'pi_mobilephone_germany' => '',
|
||||
'pi_paypal' => '',
|
||||
'pi_sofortueberweisung' => '',
|
||||
'pi_amazonpay' => '',
|
||||
'pi_paydirekt' => '',
|
||||
'pi_applepay' => '',
|
||||
'pi_googlepay' => '',
|
||||
'newsletter_groups' => '',
|
||||
'postinfo_groups' => '',
|
||||
'donation_receipt_groups' => '',
|
||||
'pi_mobilephone_germany' => NULL,
|
||||
'pi_paypal' => NULL,
|
||||
'pi_sofortueberweisung' => NULL,
|
||||
'pi_amazonpay' => NULL,
|
||||
'pi_paydirekt' => NULL,
|
||||
'pi_applepay' => NULL,
|
||||
'pi_googlepay' => NULL,
|
||||
'sepa_creditor_id' => NULL,
|
||||
'gender_male' => 2,
|
||||
'gender_female' => 1,
|
||||
'gender_other' => 3,
|
||||
'newsletter_groups' => NULL,
|
||||
'postinfo_groups' => NULL,
|
||||
'donation_receipt_groups' => NULL,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -27,16 +27,6 @@ class CRM_Twingle_Submission {
|
|||
*/
|
||||
const GROUP_TYPE_NEWSLETTER = 'Mailing List';
|
||||
|
||||
/**
|
||||
* The option value name of the group type for postal mailing subscribers.
|
||||
*/
|
||||
const GROUP_TYPE_POSTINFO = ''; // TODO.
|
||||
|
||||
/**
|
||||
* The option value name of the group type for donation receipt requesters.
|
||||
*/
|
||||
const GROUP_TYPE_DONATION_RECEIPT = ''; // TODO.
|
||||
|
||||
/**
|
||||
* The default ID of the "Employer of" relationship type.
|
||||
*/
|
||||
|
@ -100,7 +90,7 @@ class CRM_Twingle_Submission {
|
|||
|
||||
// Get the gender ID defined within the profile, or return an error if none
|
||||
// matches (i.e. an unknown gender was submitted).
|
||||
if (!$gender_id = $profile->getAttribute('gender_' . $params['user_gender'])) {
|
||||
if (!empty($params['user_gender']) && !$gender_id = $profile->getAttribute('gender_' . $params['user_gender'])) {
|
||||
throw new CiviCRM_API3_Exception(
|
||||
E::ts('Gender could not be matched to existing gender.'),
|
||||
'invalid_format'
|
||||
|
@ -249,4 +239,60 @@ class CRM_Twingle_Submission {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the CiviSEPA extension is installed and CiviSEPA
|
||||
* functionality is activated within the Twingle extension settings.
|
||||
*
|
||||
* @return bool
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public static function civiSepaEnabled() {
|
||||
$sepa_extension = civicrm_api3('Extension', 'get', array(
|
||||
'full_name' => 'org.project60.sepa',
|
||||
'is_active' => 1,
|
||||
));
|
||||
return
|
||||
CRM_Core_BAO_Setting::getItem(
|
||||
'de.systopia.twingle',
|
||||
'twingle_use_sepa'
|
||||
)
|
||||
&& $sepa_extension['count'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves recurring contribution frequency attributes for a given donation
|
||||
* rhythm parameter value, according to a static mapping.
|
||||
*
|
||||
* @param string $donation_rhythm
|
||||
* The submitted "donation_rhythm" paramter according to the API action
|
||||
* specification.
|
||||
*
|
||||
* @return array
|
||||
* An array with "frequency_unit" and "frequency_interval" keys, to be added
|
||||
* to contribution parameter arrays.
|
||||
*/
|
||||
public static function getFrequencyMapping($donation_rhythm) {
|
||||
$mapping = array(
|
||||
'halfyearly' => array(
|
||||
'frequency_unit' => 'month',
|
||||
'frequency_interval' => 6,
|
||||
),
|
||||
'quarterly' => array(
|
||||
'frequency_unit' => 'month',
|
||||
'frequency_interval' => 3,
|
||||
),
|
||||
'yearly' => array(
|
||||
'frequency_unit' => 'year',
|
||||
'frequency_interval' => 1,
|
||||
),
|
||||
'monthly' => array(
|
||||
'frequency_unit' => 'month',
|
||||
'frequency_interval' => 1,
|
||||
),
|
||||
'one_time' => array(),
|
||||
);
|
||||
|
||||
return $mapping[$donation_rhythm];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue