diff --git a/checknumberpaymentmethod.php b/checknumberpaymentmethod.php index 266ada5..e517dc3 100644 --- a/checknumberpaymentmethod.php +++ b/checknumberpaymentmethod.php @@ -239,7 +239,10 @@ function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) { */ function checknumberpaymentmethod_civicrm_pre($op, $objectName, $id, &$params) { if ($objectName == 'Contribution' && in_array($op, ['create', 'edit'])) { - if (!CRM_Utils_System::isNull($params['check_number']) || !empty($_POST['check_number'])) { + if (!CRM_Utils_System::isNull($params['check_number']) + || !empty($_POST['check_number']) + || !empty($params['payment_instrument_check_number']) + ) { $paymentInstrumentId = !empty($params['payment_instrument_id']) ? $params['payment_instrument_id'] : $params['prevContribution']->payment_instrument_id; $paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [ 'name' => 'check_payment_instrument_ids', @@ -250,6 +253,9 @@ function checknumberpaymentmethod_civicrm_pre($op, $objectName, $id, &$params) { if (!CRM_Utils_System::isNull($params['check_number'])) { $params['check_number'] = $params['check_number']; } + elseif (!empty($params['payment_instrument_check_number'])) { + $params['check_number'] = $params['payment_instrument_check_number']; + } else { $params['check_number'] = $_POST['check_number']; } @@ -277,3 +283,14 @@ function _checknumberpaymentmethod_alterpayments(&$payments) { } } } + +/** + * Implements hook_civicrm_pre(). + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre + */ +function checknumberpaymentmethod_civicrm_apiWrappers(&$wrappers, $apiRequest) { + if ($apiRequest['entity'] == 'Contribution' && $apiRequest['action'] == 'create') { + $wrappers[] = new CRM_Contribute_CheckAPIWrapper(); + } +}