[#6] Make contribution status configurable per payment method
This commit is contained in:
parent
17589ef616
commit
7ff6381ad8
4 changed files with 64 additions and 3 deletions
|
@ -44,6 +44,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
*/
|
||||
protected static $_paymentInstruments = NULL;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* A static cache of retrieved contribution statuses found within
|
||||
* static::getContributionStatusOptions().
|
||||
*/
|
||||
protected static $_contributionStatusOptions = NULL;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
|
@ -238,6 +246,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
static::getPaymentInstruments(), // list of options
|
||||
TRUE // is required
|
||||
);
|
||||
|
||||
$this->add(
|
||||
'select',
|
||||
$pi_name . '_status',
|
||||
E::ts('Record %1 donations with contribution status', array(1 => $pi_label)),
|
||||
static::getContributionStatusOptions(),
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
if (CRM_Twingle_Submission::civiSepaEnabled()) {
|
||||
|
@ -613,6 +629,36 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
return self::$_paymentInstruments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves contribution statuses as options for select form elements.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public static function getContributionStatusOptions() {
|
||||
if (!isset(self::$_contributionStatusOptions)) {
|
||||
$query = civicrm_api3(
|
||||
'OptionValue',
|
||||
'get',
|
||||
array(
|
||||
'option.limit' => 0,
|
||||
'option_group_id' => 'contribution_status',
|
||||
'return' => array(
|
||||
'value',
|
||||
'label',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($query['values'] as $contribution_status) {
|
||||
self::$_contributionStatusOptions[$contribution_status['value']] = $contribution_status['label'];
|
||||
}
|
||||
}
|
||||
|
||||
return self::$_contributionStatusOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves active groups used as mailing lists within the system as options
|
||||
* for select form elements.
|
||||
|
|
|
@ -201,7 +201,12 @@ class CRM_Twingle_Profile {
|
|||
'membership_type_id',
|
||||
),
|
||||
// Add payment methods.
|
||||
array_keys(static::paymentInstruments())
|
||||
array_keys(static::paymentInstruments()),
|
||||
|
||||
// Add contribution status for all payment methods.
|
||||
array_map(function ($attribute) {
|
||||
return $attribute . '_status';
|
||||
}, array_keys(static::paymentInstruments()))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -263,7 +268,11 @@ class CRM_Twingle_Profile {
|
|||
'contribution_source' => NULL,
|
||||
'custom_field_mapping' => NULL,
|
||||
'membership_type_id' => NULL,
|
||||
));
|
||||
)
|
||||
// Add contribution status for all payment methods.
|
||||
+ array_fill_keys(array_map(function($attribute) {
|
||||
return $attribute . '_status';
|
||||
}, array_keys(static::paymentInstruments())), CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -632,7 +632,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
|||
|
||||
// Create contribution.
|
||||
$contribution_data += array(
|
||||
'contribution_status_id' => CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED,
|
||||
'contribution_status_id' => $profile->getAttribute($params['payment_instrument_id'] . '_status', CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED),
|
||||
'receive_date' => $params['confirmed_at'],
|
||||
);
|
||||
$contribution = civicrm_api3('Contribution', 'create', $contribution_data);
|
||||
|
|
|
@ -151,8 +151,14 @@
|
|||
<table class="form-layout-compressed">
|
||||
{foreach key=pi_name item=pi_label from=$payment_instruments}
|
||||
<tr class="crm-section {cycle values="odd,even"}">
|
||||
|
||||
<td class="label">{$form.$pi_name.label}</td>
|
||||
<td class="content">{$form.$pi_name.html}</td>
|
||||
|
||||
{capture assign="pi_contribution_status"}{$pi_name}_status{/capture}
|
||||
<td class="label">{$form.$pi_contribution_status.label}</td>
|
||||
<td class="content">{$form.$pi_contribution_status.html}</td>
|
||||
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue