/**
* This class contains payment processor related functions.
*/
-class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor {
+class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor implements \Civi\Test\HookInterface {
/**
* Static holder for the default payment processor
* @var object
* 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', [
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 int|null $paymentProcessorID
* @return array
*/
public static function getCreditCards($paymentProcessorID = NULL) {
* Delete payment processor.
*
* @param int $paymentProcessorID
- *
- * @return null
+ * @deprecated
*/
public static function del($paymentProcessorID) {
if (!$paymentProcessorID) {
throw new CRM_Core_Exception(ts('Invalid value passed to delete function.'));
}
+ static::deleteRecord(['id' => $paymentProcessorID]);
+ }
- $dao = new CRM_Financial_DAO_PaymentProcessor();
- $dao->id = $paymentProcessorID;
- if (!$dao->find(TRUE)) {
- return NULL;
- }
-
- $testDAO = new CRM_Financial_DAO_PaymentProcessor();
- $testDAO->name = $dao->name;
- $testDAO->is_test = 1;
- $testDAO->delete();
+ /**
+ * Callback for hook_civicrm_post().
+ * @param \Civi\Core\Event\PostEvent $event
+ */
+ public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) {
+ if ($event->action === 'delete') {
+ // When a paymentProcessor is deleted, delete the associated test processor
+ $testDAO = new CRM_Financial_DAO_PaymentProcessor();
+ $testDAO->name = $event->object->name;
+ $testDAO->is_test = 1;
+ $testDAO->delete();
- $dao->delete();
- Civi\Payment\System::singleton()->flushProcessors();
+ Civi\Payment\System::singleton()->flushProcessors();
+ }
}
/**
* 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];
}
/**
* Get all payment processors as an array of objects.
*
- * @param string|NULL $mode
+ * @param string|null $mode
* only return this mode - test|live or NULL for all
* @param bool $reset
* @param bool $isCurrentDomainOnly
* Do we only want to load payment processors associated with the current domain.
- * @param bool|NULL $isActive
+ * @param bool|null $isActive
* Do we only want active processors, only inactive (FALSE) or all processors (NULL)
*
* @throws CiviCRM_API3_Exception
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;
}
}
// 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;
}
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
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_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
$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]);
}