Skip to content

Commit

Permalink
[NFC] Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 23, 2021
1 parent 3593fea commit 94178a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
35 changes: 15 additions & 20 deletions CRM/Financial/BAO/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
* Parameters for Processor entity.
*
* @return CRM_Financial_DAO_PaymentProcessor
* @throws Exception
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function create($params) {
public static function create(array $params): CRM_Financial_DAO_PaymentProcessor {
// 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', [
Expand Down Expand Up @@ -88,16 +90,9 @@ public static function create($params) {
return $processor;
}

/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
}

/**
* Retrieve array of allowed credit cards for this payment processor.
* @param interger|null $paymentProcessorID id of processor.
* @param integer|null $paymentProcessorID id of processor.
* @return array
*/
public static function getCreditCards($paymentProcessorID = NULL) {
Expand Down Expand Up @@ -227,7 +222,7 @@ public static function del($paymentProcessorID) {
* associated array with payment processor related fields
*/
public static function getPayment($paymentProcessorID, $mode = 'based_on_id') {
$capabilities = ($mode == 'test') ? ['TestMode'] : [];
$capabilities = ($mode === 'test') ? ['TestMode'] : [];
$processors = self::getPaymentProcessors($capabilities, [$paymentProcessorID]);
return $processors[$paymentProcessorID];
}
Expand Down Expand Up @@ -305,10 +300,10 @@ public static function getAllPaymentProcessors($mode = 'all', $reset = FALSE, $i
if ($isCurrentDomainOnly) {
$retrievalParameters['domain_id'] = CRM_Core_Config::domainID();
}
if ($mode == 'test') {
if ($mode === 'test') {
$retrievalParameters['is_test'] = 1;
}
elseif ($mode == 'live') {
elseif ($mode === 'live') {
$retrievalParameters['is_test'] = 0;
}

Expand Down Expand Up @@ -417,7 +412,7 @@ public static function getPaymentProcessors($capabilities = [], $ids = FALSE) {
}
// Invalid processors will store a null value in 'object' (e.g. if not all required config fields are present).
// This is determined by calling when loading the processor via the $processorObject->checkConfig() function.
if (!$processor['object'] instanceof \CRM_Core_Payment) {
if (!$processor['object'] instanceof CRM_Core_Payment) {
unset($processors[$index]);
continue;
}
Expand Down Expand Up @@ -504,7 +499,7 @@ public static function getProcessorForEntity($entityID, $component = 'contribute
return $result;
}

if ($component == 'membership') {
if ($component === 'membership') {
$sql = "
SELECT cr.payment_processor_id as ppID1, cp.payment_processor as ppID2, con.is_test
FROM civicrm_membership mem
Expand All @@ -514,15 +509,15 @@ public static function getProcessorForEntity($entityID, $component = 'contribute
LEFT JOIN civicrm_contribution_page cp ON ( con.contribution_page_id = cp.id )
WHERE mp.membership_id = %1";
}
elseif ($component == 'contribute') {
elseif ($component === 'contribute') {
$sql = "
SELECT cr.payment_processor_id as ppID1, cp.payment_processor as ppID2, con.is_test
FROM civicrm_contribution con
LEFT JOIN civicrm_contribution_recur cr ON ( con.contribution_recur_id = cr.id )
LEFT JOIN civicrm_contribution_page cp ON ( con.contribution_page_id = cp.id )
WHERE con.id = %1";
}
elseif ($component == 'recur') {
elseif ($component === 'recur') {
// @deprecated - use getPaymentProcessorForRecurringContribution.
$sql = "
SELECT cr.payment_processor_id as ppID1, NULL as ppID2, cr.is_test
Expand All @@ -544,13 +539,13 @@ public static function getProcessorForEntity($entityID, $component = 'contribute

$ppID = (isset($dao->ppID1) && $dao->ppID1) ? $dao->ppID1 : ($dao->ppID2 ?? NULL);
$mode = (isset($dao->is_test) && $dao->is_test) ? 'test' : 'live';
if (!$ppID || $type == 'id') {
if (!$ppID || $type === 'id') {
$result = $ppID;
}
elseif ($type == 'info') {
elseif ($type === 'info') {
$result = self::getPayment($ppID, $mode);
}
elseif ($type == 'obj' && is_numeric($ppID)) {
elseif ($type === 'obj' && is_numeric($ppID)) {
try {
$paymentProcessor = civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $ppID]);
}
Expand Down
8 changes: 6 additions & 2 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,13 @@ public function testCreateContributionWithFee() {
}

/**
* Function tests that additional financial records are created when online contribution is created.
* Function tests that additional financial records are created when online
* contribution is created.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testCreateContributionOnline() {
public function testCreateContributionOnline(): void {
CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams);
$contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
$this->assertAPISuccess($contributionPage);
Expand Down

0 comments on commit 94178a8

Please sign in to comment.