From bc9baea6f2c117d24e3f46557adfef719889a7c4 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 22 Jan 2020 12:51:15 +0100 Subject: [PATCH] [#5] Add a setting for differentiating membership types depending on donation rhythm --- CRM/Twingle/Form/Profile.php | 8 +++++++ CRM/Twingle/Profile.php | 2 ++ README.md | 33 +++++++++++++------------- api/v3/TwingleDonation/Submit.php | 8 ++++++- templates/CRM/Twingle/Form/Profile.tpl | 4 ++++ 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index fae3b0a..6dced9e 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -325,6 +325,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { FALSE, // is not required array('class' => 'crm-select2 huge') ); + $this->add( + 'select', // field type + 'membership_type_id_recur', // field name + E::ts('Create membership of type (recurring)'), // field label + array('' => E::ts('- none -')) + static::getMembershipTypes(), // list of options + FALSE, // is not required + array('class' => 'crm-select2 huge') + ); $this->add( 'text', // field type diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index fafe07e..5301cd6 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -214,6 +214,7 @@ class CRM_Twingle_Profile { 'contribution_source', 'custom_field_mapping', 'membership_type_id', + 'membership_type_id_recur', ), // Add payment methods. array_keys(static::paymentInstruments()), @@ -283,6 +284,7 @@ class CRM_Twingle_Profile { 'contribution_source' => NULL, 'custom_field_mapping' => NULL, 'membership_type_id' => NULL, + 'membership_type_id_recur' => NULL, ) // Add contribution status for all payment methods. + array_fill_keys(array_map(function($attribute) { diff --git a/README.md b/README.md index aa169f9..dd5113d 100644 --- a/README.md +++ b/README.md @@ -41,22 +41,23 @@ The *default* profile is used whenever the plugin cannot match the Twingle project ID from any other profile. Therefore the default profile will be used for all newly created Twingle projects. -| Label | Description | -|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Profile name | Internal name, used inside the extension. | -| Project IDs | Twingle project IDs. Separate multiple IDs with commas. | -| Location type | Specify how the address data sent by the form should be categorised in CiviCRM. The list is based on your CiviCRM configuration. | -| Location type for organisations | Specify how the address data sent by the form should be categorised in CiviCRM for organisational donations. The list is based on your CiviCRM configuration. | -| Financial type | Specify which financial type incoming one-time donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | -| Financial type (recurring) | Specify which financial type incoming recurring donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | -| CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. | -| Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. | -| Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. | -| Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. | -| Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. | -| Create membership of type | A membership of the selected type will be created for the Individual contact. If no membership type is selected, no membership will be created. | -| Contribution source | The configured value will be set as the "Source" field for the contribution. | -| Custom field mapping | Additional field values may be set to CiviCRM custom fields using a mapping. See the option's help text for the exact format. | +| Label | Description | +|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Profile name | Internal name, used inside the extension. | +| Project IDs | Twingle project IDs. Separate multiple IDs with commas. | +| Location type | Specify how the address data sent by the form should be categorised in CiviCRM. The list is based on your CiviCRM configuration. | +| Location type for organisations | Specify how the address data sent by the form should be categorised in CiviCRM for organisational donations. The list is based on your CiviCRM configuration. | +| Financial type | Specify which financial type incoming one-time donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | +| Financial type (recurring) | Specify which financial type incoming recurring donations should be recorded with in CiviCRM. The list is based on your CiviCRM configuration. | +| CiviSEPA creditor | When enabled to integrate with CiviSEPA, specify the CiviSEPA creditor to use. | +| Gender options | Specify which CiviCRM gender option the incoming Twingle gender value should be mapped to. The list is based on your CiviCRM configuration. | +| Record *Payment method* as | Specifiy the payment methods mapping for incoming donations for each Twingle payment method. | +| Sign up for groups | Whenever the donor checked the newsletter/postal mailing/donation receipt checkbox on the Twingle form, the contact will be added to the groups listed here. | +| Assign donation to campaign | The donation will be assigned to the selected campaign. If a campaign ID is being submitted using the `campaign_id` parameter, this setting will be overridden with the submitted value. | +| Create membership of type | A membership of the selected type will be created for the Individual contact for incoming one-time donations. If no membership type is selected, no membership will be created. | +| Create membership of type (recurring) | A membership of the selected type will be created for the Individual contact for incoming recurring donations. If no membership type is selected, no membership will be created. | +| Contribution source | The configured value will be set as the "Source" field for the contribution. | +| Custom field mapping | Additional field values may be set to CiviCRM custom fields using a mapping. See the option's help text for the exact format. | ## API documentation diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 2bc3d3a..0d5ed43 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -648,7 +648,13 @@ function civicrm_api3_twingle_donation_Submit($params) { } // Create membership if a membership type is configured within the profile. - if (!empty($membership_type_id = $profile->getAttribute('membership_type_id'))) { + if ($params['donation_rhythm'] != 'one_time') { + $membership_type_id = $profile->getAttribute('membership_type_id_recur'); + } + else { + $membership_type_id = $profile->getAttribute('membership_type_id'); + } + if (!empty($membership_type_id)) { $membership = civicrm_api3('Membership', 'create', array( 'contact_id' => $contact_id, 'membership_type_id' => $membership_type_id, diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 05cd32e..c0b444f 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -211,6 +211,10 @@ {$form.membership_type_id.label} {$form.membership_type_id.html} + + {$form.membership_type_id_recur.label} + {$form.membership_type_id_recur.html} + {$form.contribution_source.label}