Skip to content
Snippets Groups Projects
Unverified Commit 0a5024aa authored by colemanw's avatar colemanw Committed by GitHub
Browse files

Merge pull request #16279 from seamuslee001/ref_payment_processor_instrument

[REF] Move handling of default payment instrument for a payment proc…
parents c4a019bd 5de5c50e
Branches
Tags
No related merge requests found
......@@ -35,6 +35,13 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
* @throws Exception
*/
public static function create($params) {
// If we are creating a new PaymentProcessor and have not specified the payment instrument to use, get the default from the Payment Processor Type.
if (empty($params['id']) && empty($params['payment_instrument_id'])) {
$params['payment_instrument_id'] = civicrm_api3('PaymentProcessorType', 'getvalue', [
'id' => $params['payment_processor_type_id'],
'return' => 'payment_instrument_id',
]);
}
$processor = new CRM_Financial_DAO_PaymentProcessor();
$processor->copyValues($params);
......
......@@ -24,12 +24,6 @@
* API result array
*/
function civicrm_api3_payment_processor_create($params) {
if (empty($params['id']) && empty($params['payment_instrument_id'])) {
$params['payment_instrument_id'] = civicrm_api3('PaymentProcessorType', 'getvalue', [
'id' => $params['payment_processor_type_id'],
'return' => 'payment_instrument_id',
]);
}
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'PaymentProcessor');
}
......
......@@ -33,6 +33,7 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
'class_name' => 'CRM_Core_Payment_APITest',
'billing_mode' => 'form',
'is_recur' => 0,
'payment_instrument_id' => 2,
];
$result = $this->callAPISuccess('payment_processor_type', 'create', $params);
$this->_paymentProcessorType = $result['id'];
......@@ -71,6 +72,7 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
'frequency_interval' => 1,
]);
$this->getAndCheck($params, $result['id'], 'PaymentProcessor');
$this->assertEquals(2, $result['values'][$result['id']]['payment_instrument_id']);
}
/**
......@@ -80,6 +82,7 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
*/
public function testPaymentProcessorUpdate() {
$params = $this->_params;
$params['payment_instrument_id'] = 1;
$result = $this->callAPISuccess('payment_processor', 'create', $params);
$this->assertNotNull($result['id']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment