Unverified Commit 0f0b0ad2 authored by Monish Deb's avatar Monish Deb Committed by GitHub

Merge pull request #13181 from eileenmcnaughton/financial_type_id_default

Set default financial_type_id for creating new payment processors (form & api)
parents 5270e282 8563c1ce
......@@ -327,6 +327,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
if ($this->_paymentProcessorType) {
$defaults['payment_processor_type_id'] = $this->_paymentProcessorType;
}
$defaults['financial_account_id'] = CRM_Financial_BAO_PaymentProcessor::getDefaultFinancialAccountID();
return $defaults;
}
$domainID = CRM_Core_Config::domainID();
......
......@@ -597,4 +597,16 @@ INNER JOIN civicrm_contribution con ON ( mp.contribution_id = con.id )
}
}
/**
* Get the default financial account id for payment processor accounts.
*
* Note that there is only a 'name' field & no label field. If people customise
* name then this won't work. This is new best-effort functionality so that's non-regressive.
*
* The fix for that is to add a label value to the financial account table.
*/
public static function getDefaultFinancialAccountID() {
return CRM_Core_PseudoConstant::getKey('CRM_Financial_DAO_EntityFinancialAccount', 'financial_account_id', 'Payment Processor Account');
}
}
......@@ -62,6 +62,9 @@ function _civicrm_api3_payment_processor_create_spec(&$params) {
$params['is_default']['api.default'] = 0;
$params['is_test']['api.default'] = 0;
$params['domain_id']['api.default'] = CRM_Core_Config::domainID();
$params['financial_account_id']['api.default'] = CRM_Financial_BAO_PaymentProcessor::getDefaultFinancialAccountID();
$params['financial_account_id']['api.required'] = TRUE;
$params['financial_account_id']['title'] = ts('Financial Account for Processor');
}
/**
......
......@@ -73,9 +73,8 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
public function testPaymentProcessorCreate() {
$params = $this->_params;
$result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['id']);
$this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
return $result['id'];
$this->callAPISuccessGetSingle('EntityFinancialAccount', ['entity_table' => 'civicrm_payment_processor', 'entity_id' => $result['id']]);
$this->getAndCheck($params, $result['id'], 'PaymentProcessor');
}
/**
......@@ -124,9 +123,9 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
* Check payment processor delete.
*/
public function testPaymentProcessorDelete() {
$id = $this->testPaymentProcessorCreate();
$result = $this->callAPISuccess('payment_processor', 'create', $this->_params);
$params = array(
'id' => $id,
'id' => $result['id'],
);
$this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment