Skip to content

Commit

Permalink
Merge pull request #16279 from seamuslee001/ref_payment_processor_ins…
Browse files Browse the repository at this point in the history
…trument

[REF] Move handling of default payment instrument for a payment proc…
  • Loading branch information
colemanw authored Jan 11, 2020
2 parents c4a019b + 5de5c50 commit 0a5024a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CRM/Financial/BAO/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 0 additions & 6 deletions api/v3/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/api/v3/PaymentProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function setUp() {
'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'];
Expand Down Expand Up @@ -71,6 +72,7 @@ public function testPaymentProcessorCreate() {
'frequency_interval' => 1,
]);
$this->getAndCheck($params, $result['id'], 'PaymentProcessor');
$this->assertEquals(2, $result['values'][$result['id']]['payment_instrument_id']);
}

/**
Expand All @@ -80,6 +82,7 @@ public function testPaymentProcessorCreate() {
*/
public function testPaymentProcessorUpdate() {
$params = $this->_params;
$params['payment_instrument_id'] = 1;
$result = $this->callAPISuccess('payment_processor', 'create', $params);
$this->assertNotNull($result['id']);

Expand Down

0 comments on commit 0a5024a

Please sign in to comment.