[#19] implementing membership postprocess call (WIP)
This commit is contained in:
parent
8a2f91f34a
commit
33ced7bbc3
5 changed files with 107 additions and 3 deletions
|
@ -379,6 +379,13 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
||||||
FALSE, // is not required
|
FALSE, // is not required
|
||||||
array('class' => 'crm-select2 huge')
|
array('class' => 'crm-select2 huge')
|
||||||
);
|
);
|
||||||
|
$this->add(
|
||||||
|
'text',
|
||||||
|
'membership_postprocess_call',
|
||||||
|
E::ts('API Call for Membership Postprocessing'),
|
||||||
|
FALSE
|
||||||
|
);
|
||||||
|
$this->addRule('membership_postprocess_call', E::ts("The API call must have the form 'Entity.Action'."), 'regex', '/^[A-Za-z_]+[.][A-Za-z_]+$/');
|
||||||
|
|
||||||
$this->add(
|
$this->add(
|
||||||
'text', // field type
|
'text', // field type
|
||||||
|
|
|
@ -219,6 +219,7 @@ class CRM_Twingle_Profile {
|
||||||
'custom_field_mapping',
|
'custom_field_mapping',
|
||||||
'membership_type_id',
|
'membership_type_id',
|
||||||
'membership_type_id_recur',
|
'membership_type_id_recur',
|
||||||
|
'membership_postprocess_call',
|
||||||
),
|
),
|
||||||
// Add payment methods.
|
// Add payment methods.
|
||||||
array_keys(static::paymentInstruments()),
|
array_keys(static::paymentInstruments()),
|
||||||
|
|
|
@ -670,8 +670,48 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
||||||
'contact_id' => $contact_id,
|
'contact_id' => $contact_id,
|
||||||
'membership_type_id' => $membership_type_id,
|
'membership_type_id' => $membership_type_id,
|
||||||
));
|
));
|
||||||
|
|
||||||
$result_values['membership'] = $membership;
|
$result_values['membership'] = $membership;
|
||||||
|
|
||||||
|
// call the postprocess API
|
||||||
|
$postprocess_call = $profile->getAttribute('membership_postprocess_call');
|
||||||
|
if (!empty($postprocess_call)) {
|
||||||
|
list($pp_entity, $pp_action) = explode('.', $postprocess_call, 1);
|
||||||
|
try {
|
||||||
|
// gather the contribution IDs
|
||||||
|
$recurring_contribution_id = $contribution_id = '';
|
||||||
|
if (isset($mandate)) {
|
||||||
|
if ($mandate['type'] == 'RCUR') {
|
||||||
|
$recurring_contribution_id = $mandate['entity_id'];
|
||||||
|
} elseif ($mandate['type'] == 'OOFF') {
|
||||||
|
$contribution_id = $mandate['entity_id'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset($contribution_recur['id'])) {
|
||||||
|
$recurring_contribution_id = $contribution_recur['id'];
|
||||||
|
}
|
||||||
|
if (isset($contribution['id'])) {
|
||||||
|
$contribution_id = $contribution['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the call
|
||||||
|
civicrm_api3($pp_entity, $pp_action, [
|
||||||
|
'membership_id' => $membership['id'],
|
||||||
|
'contact_id' => $contact_id,
|
||||||
|
'organization_id' => isset($organisation_id) ? $organisation_id : '',
|
||||||
|
'contribution_id' => $contribution_id,
|
||||||
|
'recurring_contribution_id' => $recurring_contribution_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// refresh membership data
|
||||||
|
$result_values['membership'] = civicrm_api3('Membership', 'getsingle', $membership['id']);
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
// TODO: more error handling?
|
||||||
|
Civi::log()->debug("Twingle membership postprocessing call {$pp_entity}.{$pp_action} has failed: " . $ex->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = civicrm_api3_create_success($result_values);
|
$result = civicrm_api3_create_success($result_values);
|
||||||
|
|
|
@ -38,6 +38,17 @@
|
||||||
{ts domain="de.systopia.twingle"}Select which financial type to use for recurring contributions.{/ts}
|
{ts domain="de.systopia.twingle"}Select which financial type to use for recurring contributions.{/ts}
|
||||||
{/htxt}
|
{/htxt}
|
||||||
|
|
||||||
|
{htxt id='id-membership-postprocessing-call'}
|
||||||
|
{ts domain="de.systopia.twingle"}Some organisations have specific conventions on how a membership should be created. Since the Twingle-API can only create a "bare bone" membership object, you can enter a API Call (as 'Entity.Action') to adjust any newly created membership to your organisation's needs.{/ts}
|
||||||
|
{ts domain="de.systopia.twingle"}The API call would receive the following parameters:<ul>
|
||||||
|
<li><code>membership_id</code>: The ID of the newly created membership</li>
|
||||||
|
<li><code>contact_id</code>: The ID of the contact involved</li>
|
||||||
|
<li><code>organization_id</code>: The ID of the contact's organisation, potentially empty</li>
|
||||||
|
<li><code>contribution_id</code>: The ID contribution received, potentially empty</li>
|
||||||
|
<li><code>recurring_contribution_id</code>: The ID of the recurring contribution. If empty, this was only a one-off donation.</li>
|
||||||
|
</ul>{/ts}
|
||||||
|
{/htxt}
|
||||||
|
|
||||||
{htxt id='id-custom_field_mapping'}
|
{htxt id='id-custom_field_mapping'}
|
||||||
{ts domain="de.systopia.twingle"}<p>Map Twingle custom fields to CiviCRM custom fields using the following format (each assignment in a separate line):</p>
|
{ts domain="de.systopia.twingle"}<p>Map Twingle custom fields to CiviCRM custom fields using the following format (each assignment in a separate line):</p>
|
||||||
<pre>twingle_field_1=custom_123<br />twingle_field_2=custom_789</pre>
|
<pre>twingle_field_1=custom_123<br />twingle_field_2=custom_789</pre>
|
||||||
|
|
|
@ -236,6 +236,27 @@
|
||||||
<td class="label">{$form.membership_type_id_recur.label}</td>
|
<td class="label">{$form.membership_type_id_recur.label}</td>
|
||||||
<td class="content">{$form.membership_type_id_recur.html}</td>
|
<td class="content">{$form.membership_type_id_recur.html}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="crm-section twingle-postprocess-call">
|
||||||
|
<td class="label">
|
||||||
|
{$form.membership_postprocess_call.label}
|
||||||
|
<a
|
||||||
|
onclick='
|
||||||
|
CRM.help(
|
||||||
|
"{ts domain="de.systopia.twingle"}Membership Postprocessing{/ts}",
|
||||||
|
{literal}{
|
||||||
|
"id": "id-membership-postprocessing-call",
|
||||||
|
"file": "CRM\/Twingle\/Form\/Profile"
|
||||||
|
}{/literal}
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
'
|
||||||
|
href="#"
|
||||||
|
title="{ts domain="de.systopia.twingle"}Help{/ts}"
|
||||||
|
class="helpicon"
|
||||||
|
></a>
|
||||||
|
</td>
|
||||||
|
<td class="content">{$form.membership_postprocess_call.html}</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr class="crm-section">
|
<tr class="crm-section">
|
||||||
<td class="label">{$form.contribution_source.label}</td>
|
<td class="label">{$form.contribution_source.label}</td>
|
||||||
|
@ -286,3 +307,27 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{literal}
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Update the form fields based on whether membership creation is currently active
|
||||||
|
*/
|
||||||
|
function twingle_membership_active_changed() {
|
||||||
|
let active = cj('#membership_type_id').val() || cj('#membership_type_id_recur').val();
|
||||||
|
if (active) {
|
||||||
|
cj('#membership_postprocess_call').parent().parent().show();
|
||||||
|
} else {
|
||||||
|
cj('#membership_postprocess_call').val(''); // empty to avoid hidden validation fail
|
||||||
|
cj('#membership_postprocess_call').parent().parent().hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// register events and run once
|
||||||
|
cj(document).ready(function (){
|
||||||
|
cj('#membership_type_id').change(twingle_membership_active_changed);
|
||||||
|
cj('#membership_type_id_recur').change(twingle_membership_active_changed);
|
||||||
|
});
|
||||||
|
twingle_membership_active_changed();
|
||||||
|
</script>
|
||||||
|
{/literal}
|
Loading…
Add table
Add a link
Reference in a new issue