From 102eb33937a541878e3ca35f169b4e1543ef4d33 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 24 Mar 2023 15:28:47 +1300 Subject: [PATCH] Fix form to stop messing name field for test processor --- CRM/Admin/Form/PaymentProcessor.php | 25 ++++++++++--------------- CRM/Core/Payment.php | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CRM/Admin/Form/PaymentProcessor.php b/CRM/Admin/Form/PaymentProcessor.php index 046fb6dec2..641dac4c5a 100644 --- a/CRM/Admin/Form/PaymentProcessor.php +++ b/CRM/Admin/Form/PaymentProcessor.php @@ -42,7 +42,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { /** * Set entity fields to be assigned to the form. */ - protected function setEntityFields() { + protected function setEntityFields(): void { $this->entityFields = [ 'payment_processor_type_id' => [ 'name' => 'payment_processor_type_id', @@ -103,7 +103,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { } else { $refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor/edit', - "reset=1&action=add", + 'reset=1&action=add', FALSE, NULL, FALSE ); } @@ -402,11 +402,10 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { $this->_paymentProcessorDAO->id = $values['payment_processor_type_id']; $this->_paymentProcessorDAO->find(TRUE); } - $this->updatePaymentProcessor($values, $domainID, FALSE); $this->updatePaymentProcessor($values, $domainID, TRUE); - - $processor = civicrm_api3('payment_processor', 'getsingle', ['name' => $values['name'], 'is_test' => 0]); - $errors = Civi\Payment\System::singleton()->checkProcessorConfig($processor); + $paymentProcessorID = $this->updatePaymentProcessor($values, $domainID, FALSE); + $processor = Civi\Payment\System::singleton()->getById($paymentProcessorID); + $errors = $processor->checkConfig(); if ($errors) { CRM_Core_Session::setStatus($errors, ts('Payment processor configuration invalid'), 'error'); Civi::log()->error('Payment processor configuration invalid: ' . $errors); @@ -426,7 +425,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { * * @throws \CRM_Core_Exception */ - public function updatePaymentProcessor(&$values, $domainID, $test) { + public function updatePaymentProcessor($values, $domainID, $test) { if ($test) { foreach (['user_name', 'password', 'signature', 'url_site', 'url_recur', 'url_api', 'url_button', 'subject'] as $field) { $values[$field] = empty($values["test_{$field}"]) ? CRM_Utils_Array::value($field, $values) : $values["test_{$field}"]; @@ -443,9 +442,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { } $creditCards = json_encode($creditCards); } - else { - $creditCards = "NULL"; - } + $params = array_merge([ 'id' => $test ? $this->_testID : $this->_id, 'domain_id' => $domainID, @@ -458,14 +455,12 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { 'payment_type' => $this->_paymentProcessorDAO->payment_type, 'payment_instrument_id' => $this->_paymentProcessorDAO->payment_instrument_id, 'financial_account_id' => $values['financial_account_id'], - 'accepted_credit_cards' => $creditCards, + 'accepted_credit_cards' => $creditCards ?? NULL, ], $values); - $result = civicrm_api4('PaymentProcessor', 'save', [ + return civicrm_api4('PaymentProcessor', 'save', [ 'records' => [$params], - ]); - // Pass autogenerated name back - $values['name'] = $result->single()['name']; + ])->first()['id']; } /** diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 10afed4e59..b8f80dd8a9 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1511,7 +1511,7 @@ abstract class CRM_Core_Payment { * @return string * the error message if any */ - abstract protected function checkConfig(); + abstract public function checkConfig(); /** * Redirect for paypal. -- 2.25.1