Handled for Payment edit form
This commit is contained in:
		
							
								
								
									
										32
									
								
								CRM/Contribute/CheckAPIWrapper.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								CRM/Contribute/CheckAPIWrapper.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CRM_Contribute_CheckAPIWrapper implements API_Wrapper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * the wrapper contains a method that allows you to alter the parameters of the api request (including the action and the entity)
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function fromApiInput($apiRequest) {
 | 
				
			||||||
 | 
					    if ($apiRequest['entity'] == 'Contribution' && !empty($apiRequest['params']['check_number'])) {
 | 
				
			||||||
 | 
					      $apiRequest['params']['payment_instrument_check_number'] = $apiRequest['params']['check_number'];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ($apiRequest['entity'] == 'FinancialTrxn' && empty($apiRequest['params']['check_number'])) {
 | 
				
			||||||
 | 
					      $numberOfCalls = CRM_Core_Smarty::singleton()->get_template_vars('payment_instrument_check_number_numberOfCalls');
 | 
				
			||||||
 | 
					      if ($numberOfCalls) {
 | 
				
			||||||
 | 
					        if ($numberOfCalls == 1) {
 | 
				
			||||||
 | 
					          $apiRequest['params']['check_number'] = CRM_Core_Smarty::singleton()->get_template_vars('payment_instrument_check_number');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        $numberOfCalls--;
 | 
				
			||||||
 | 
					        CRM_Core_Smarty::singleton()->assign('payment_instrument_check_number_numberOfCalls', $numberOfCalls);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return $apiRequest;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * alter the result before returning it to the caller.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function toApiOutput($apiRequest, $result) {
 | 
				
			||||||
 | 
					    return $result;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -223,6 +223,20 @@ function checknumberpaymentmethod_civicrm_buildForm($formName, &$form) {
 | 
				
			|||||||
    $paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
 | 
					    $paymentInstrumentsFromSettings = civicrm_api3('Setting', 'getvalue', [
 | 
				
			||||||
      'name' => 'check_payment_instrument_ids',
 | 
					      'name' => 'check_payment_instrument_ids',
 | 
				
			||||||
    ]);
 | 
					    ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ($form->_flagSubmitted && isset($form->_submitValues['check_number'])
 | 
				
			||||||
 | 
					      && in_array($form->_submitValues['payment_instrument_id'], $paymentInstrumentsFromSettings)
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
 | 
					      $values = $form->getVar('_values');
 | 
				
			||||||
 | 
					      $numberOfCalls = 1;
 | 
				
			||||||
 | 
					      if ($form->_submitValues['payment_instrument_id'] != $values['payment_instrument_id']) {
 | 
				
			||||||
 | 
					        $numberOfCalls = 2;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      CRM_Core_Smarty::singleton()->assign('payment_instrument_check_number_numberOfCalls', $numberOfCalls);
 | 
				
			||||||
 | 
					      CRM_Core_Smarty::singleton()->assign('payment_instrument_check_number', $form->_submitValues['check_number']);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $paymentInstrumentsFromSettings[] = (string) CRM_Core_PseudoConstant::getKey(
 | 
					    $paymentInstrumentsFromSettings[] = (string) CRM_Core_PseudoConstant::getKey(
 | 
				
			||||||
      'CRM_Contribute_BAO_Contribution',
 | 
					      'CRM_Contribute_BAO_Contribution',
 | 
				
			||||||
      'payment_instrument_id',
 | 
					      'payment_instrument_id',
 | 
				
			||||||
@@ -290,7 +304,7 @@ function _checknumberpaymentmethod_alterpayments(&$payments) {
 | 
				
			|||||||
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre
 | 
					 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function checknumberpaymentmethod_civicrm_apiWrappers(&$wrappers, $apiRequest) {
 | 
					function checknumberpaymentmethod_civicrm_apiWrappers(&$wrappers, $apiRequest) {
 | 
				
			||||||
  if ($apiRequest['entity'] == 'Contribution' && $apiRequest['action'] == 'create') {
 | 
					  if (in_array($apiRequest['entity'], ['Contribution', 'FinancialTrxn']) && $apiRequest['action'] == 'create') {
 | 
				
			||||||
    $wrappers[] = new CRM_Contribute_CheckAPIWrapper();
 | 
					    $wrappers[] = new CRM_Contribute_CheckAPIWrapper();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user