Skip to content

Commit

Permalink
Merge pull request #24759 from colemanw/skPaymentProcessor
Browse files Browse the repository at this point in the history
AdminUI - Convert "Administer Payment Processors" to SearchKit
mattwire authored Oct 18, 2022

Verified

This commit was signed with the committer’s verified signature.
KyleFromNVIDIA Kyle Edwards
2 parents 5c89057 + 497f3bd commit 64ee023
Showing 13 changed files with 334 additions and 33 deletions.
9 changes: 8 additions & 1 deletion CRM/Admin/Form/PaymentProcessor.php
Original file line number Diff line number Diff line change
@@ -106,6 +106,9 @@ public function setDeleteMessage() {
* @throws \CRM_Core_Exception
*/
public function preProcess() {
CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
$this->set('BAOName', 'CRM_Financial_BAO_PaymentProcessor');

parent::preProcess();

$this->setPaymentProcessorTypeID();
@@ -507,7 +510,11 @@ protected function setPaymentProcessorTypeID(): void {
$this->set('pp', $this->_paymentProcessorType);
}
else {
$this->_paymentProcessorType = CRM_Utils_Request::retrieve('pp', 'String', $this, TRUE, NULL);
$paymentProcessorTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_PaymentProcessor', 'payment_processor_type_id', array(
'labelColumn' => 'name',
'flip' => 1,
));
$this->_paymentProcessorType = CRM_Utils_Request::retrieve('pp', 'String', $this, FALSE, $paymentProcessorTypes['PayPal']);
}
}

38 changes: 16 additions & 22 deletions CRM/Admin/Page/PaymentProcessor.php
Original file line number Diff line number Diff line change
@@ -47,30 +47,30 @@ public function getBAOName() {
*/
public function &links() {
if (!(self::$_links)) {
self::$_links = array(
CRM_Core_Action::UPDATE => array(
self::$_links = [
CRM_Core_Action::UPDATE => [
'name' => ts('Edit'),
'url' => 'civicrm/admin/paymentProcessor',
'url' => 'civicrm/admin/paymentProcessor/edit',
'qs' => 'action=update&id=%%id%%&reset=1',
'title' => ts('Edit Payment Processor'),
),
CRM_Core_Action::DISABLE => array(
],
CRM_Core_Action::DISABLE => [
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Payment Processor'),
),
CRM_Core_Action::ENABLE => array(
],
CRM_Core_Action::ENABLE => [
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Payment Processor'),
),
CRM_Core_Action::DELETE => array(
],
CRM_Core_Action::DELETE => [
'name' => ts('Delete'),
'url' => 'civicrm/admin/paymentProcessor',
'url' => 'civicrm/admin/paymentProcessor/edit',
'qs' => 'action=delete&id=%%id%%',
'title' => ts('Delete Payment Processor'),
),
);
],
];
}
return self::$_links;
}
@@ -85,20 +85,14 @@ public function &links() {
public function run() {
// set title and breadcrumb
CRM_Utils_System::setTitle(ts('Settings - Payment Processor'));
//CRM-15546
$paymentProcessorTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_PaymentProcessor', 'payment_processor_type_id', array(
'labelColumn' => 'name',
'flip' => 1,
));
$this->assign('defaultPaymentProcessorType', $paymentProcessorTypes['PayPal']);
$breadCrumb = array(
array(
$breadCrumb = [
[
'title' => ts('Administration'),
'url' => CRM_Utils_System::url('civicrm/admin',
'reset=1'
),
),
);
],
];
CRM_Utils_System::appendBreadCrumb($breadCrumb);
return parent::run();
}
4 changes: 4 additions & 0 deletions CRM/Core/xml/Menu/Admin.xml
Original file line number Diff line number Diff line change
@@ -460,6 +460,10 @@
<weight>30</weight>
<access_arguments>administer payment processors</access_arguments>
</item>
<item>
<path>civicrm/admin/paymentProcessor/edit</path>
<page_callback>CRM_Admin_Form_PaymentProcessor</page_callback>
</item>
<item>
<path>civicrm/admin/setting/mapping</path>
<title>Mapping and Geocoding</title>
13 changes: 12 additions & 1 deletion CRM/Financial/DAO/PaymentProcessor.php
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Financial/PaymentProcessor.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:1046252e760c45a6fddafcf26931ace2)
* (GenCodeChecksum:2f84f05644f9b359fd9c70e8ebe3363a)
*/

/**
@@ -31,6 +31,17 @@ class CRM_Financial_DAO_PaymentProcessor extends CRM_Core_DAO {
*/
public static $_log = FALSE;

/**
* Paths for accessing this entity in the UI.
*
* @var string[]
*/
protected static $_paths = [
'add' => 'civicrm/admin/paymentProcessor/edit?action=add&reset=1',
'update' => 'civicrm/admin/paymentProcessor/edit?action=update&id=[id]&reset=1',
'delete' => 'civicrm/admin/paymentProcessor/edit?action=delete&id=[id]&reset=1',
];

/**
* Payment Processor ID
*
1 change: 0 additions & 1 deletion Civi/Api4/PaymentProcessor.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
*
* @see https://docs.civicrm.org/sysadmin/en/latest/setup/payment-processors/
*
* @searchable none
* @since 5.23
* @package Civi\Api4
*/
9 changes: 9 additions & 0 deletions Civi/Api4/Service/Spec/SpecFormatter.php
Original file line number Diff line number Diff line change
@@ -172,6 +172,15 @@ public static function getOptions($spec, $values, $returnFormat, $checkPermissio
self::addOptionProps($options, $spec, $bao, $fieldName, $values, $returnFormat);
}
}
// Special 'current_domain' option
if ($spec->getFkEntity() === 'Domain') {
array_unshift($options, [
'id' => 'current_domain',
'name' => 'current_domain',
'label' => ts('Current Domain'),
'icon' => 'fa-sign-in',
]);
}
return $options;
}

30 changes: 24 additions & 6 deletions Civi/Api4/Utils/FormattingUtil.php
Original file line number Diff line number Diff line change
@@ -89,7 +89,29 @@ public static function formatWriteParams(&$params, $fields) {
*/
public static function formatInputValue(&$value, ?string $fieldName, array $fieldSpec, array $params = [], &$operator = NULL, $index = NULL) {
// Evaluate pseudoconstant suffix
$suffix = strpos(($fieldName ?? ''), ':');
$suffix = str_replace(':', '', strstr(($fieldName ?? ''), ':'));
$fk = $fieldSpec['name'] == 'id' ? $fieldSpec['entity'] : $fieldSpec['fk_entity'] ?? NULL;

// Handle special 'current_domain' option. See SpecFormatter::getOptions
$currentDomain = ($fk === 'Domain' && in_array('current_domain', (array) $value, TRUE));
if ($currentDomain) {
// If the fieldName uses a suffix, convert
$domainKey = $suffix ?: 'id';
$domainValue = \CRM_Core_BAO_Domain::getDomain()->$domainKey;
// If the value is an array, only convert the current_domain item
if (is_array($value)) {
foreach ($value as $idx => $val) {
if ($val === 'current_domain') {
$value[$idx] = $domainValue;
}
}
}
else {
$value = $domainValue;
}
}

// Convert option list suffix to value
if ($suffix) {
$options = self::getPseudoconstantList($fieldSpec, $fieldName, $params, $operator ? 'get' : 'create');
$value = self::replacePseudoconstant($options, $value, TRUE);
@@ -102,12 +124,8 @@ public static function formatInputValue(&$value, ?string $fieldName, array $fiel
}
return;
}
$fk = $fieldSpec['name'] == 'id' ? $fieldSpec['entity'] : $fieldSpec['fk_entity'] ?? NULL;

if ($fk === 'Domain' && $value === 'current_domain') {
$value = \CRM_Core_Config::domainID();
}

// Special handling for 'current_user' and user lookups
if ($fk === 'Contact' && !is_numeric($value)) {
$value = \_civicrm_api3_resolve_contactID($value);
if ('unknown-user' === $value) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div af-fieldset="">
<div class="af-markup">
<div class="help">
{{:: ts('You can configure one or more Payment Processors for your CiviCRM installation. You must then assign an active Payment Processor to each Online Contribution Page and each paid Event.') }}
<a href="https://docs.civicrm.org/user/en/latest/contributions/payment-processors/" target="_blank" class="crm-doc-link no-popup">{{:: ts('Learn more...') }}</a>
</div>
</div>
<crm-search-display-table search-name="Administer_Payment_Processors" display-name="Administer_Payment_Processors_Table"></crm-search-display-table>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "search",
"title": "Administer Payment Processors",
"icon": "fa-list-alt",
"server_route": "civicrm/admin/paymentProcessor",
"permission": "administer payment processors"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<?php
use CRM_CivicrmAdminUi_ExtensionUtil as E;

return [
[
'name' => 'SavedSearch_Administer_Payment_Processors',
'entity' => 'SavedSearch',
'cleanup' => 'always',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Administer_Payment_Processors',
'label' => E::ts('Administer Payment Processors'),
'api_entity' => 'PaymentProcessor',
'api_params' => [
'version' => 4,
'select' => [
'id',
'name',
'title',
'description',
'payment_processor_type_id:label',
'is_active',
'is_default',
'PaymentProcessor_EntityFinancialAccount_FinancialAccount_01.name',
],
'orderBy' => [],
'where' => [
[
'is_test',
'=',
FALSE,
],
[
'domain_id:name',
'=',
'current_domain',
],
],
'groupBy' => [],
'join' => [
[
'FinancialAccount AS PaymentProcessor_EntityFinancialAccount_FinancialAccount_01',
'LEFT',
'EntityFinancialAccount',
[
'id',
'=',
'PaymentProcessor_EntityFinancialAccount_FinancialAccount_01.entity_id',
],
[
'PaymentProcessor_EntityFinancialAccount_FinancialAccount_01.entity_table',
'=',
"'civicrm_payment_processor'",
],
],
],
'having' => [],
],
'expires_date' => NULL,
'description' => NULL,
],
],
],
[
'name' => 'SavedSearch_Administer_Payment_Processors_SearchDisplay_Administer_Payment_Processors_Table',
'entity' => 'SearchDisplay',
'cleanup' => 'always',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Administer_Payment_Processors_Table',
'label' => E::ts('Administer Payment Processors'),
'saved_search_id.name' => 'Administer_Payment_Processors',
'type' => 'table',
'settings' => [
'actions' => FALSE,
'limit' => 50,
'classes' => [
'table',
'table-striped',
],
'pager' => [],
'placeholder' => 5,
'sort' => [],
'columns' => [
[
'type' => 'field',
'key' => 'id',
'dataType' => 'Integer',
'label' => E::ts('ID'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'name',
'dataType' => 'String',
'label' => E::ts('Name'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'title',
'dataType' => 'String',
'label' => E::ts('Title'),
'sortable' => TRUE,
'editable' => TRUE,
],
[
'type' => 'field',
'key' => 'description',
'dataType' => 'String',
'label' => E::ts('Description'),
'sortable' => TRUE,
'editable' => TRUE,
],
[
'type' => 'field',
'key' => 'payment_processor_type_id:label',
'dataType' => 'Integer',
'label' => E::ts('Type'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'PaymentProcessor_EntityFinancialAccount_FinancialAccount_01.name',
'dataType' => 'String',
'label' => E::ts('Financial Account'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'is_active',
'dataType' => 'Boolean',
'label' => E::ts('Enabled'),
'sortable' => TRUE,
'editable' => TRUE,
],
[
'type' => 'field',
'key' => 'is_default',
'dataType' => 'Boolean',
'label' => E::ts('Default'),
'sortable' => TRUE,
'rewrite' => ' ',
'icons' => [
[
'icon' => 'fa-check-square-o',
'side' => 'left',
'if' => [
'is_default',
'=',
TRUE,
],
],
],
],
[
'size' => 'btn-xs',
'links' => [
[
'entity' => 'PaymentProcessor',
'action' => 'update',
'join' => '',
'target' => 'crm-popup',
'icon' => 'fa-pencil',
'text' => E::ts('Edit'),
'style' => 'default',
'path' => '',
'condition' => [],
],
[
'entity' => 'PaymentProcessor',
'action' => 'delete',
'join' => '',
'target' => 'crm-popup',
'icon' => 'fa-trash',
'text' => E::ts('Delete'),
'style' => 'danger',
'path' => '',
'condition' => [],
],
],
'type' => 'buttons',
'alignment' => 'text-right',
],
],
'addButton' => [
'path' => 'civicrm/admin/paymentProcessor/edit?action=add&reset=1',
'text' => E::ts('Add Payment Processor'),
'icon' => 'fa-plus',
],
'cssRules' => [
[
'disabled',
'is_active',
'=',
FALSE,
],
],
],
'acl_bypass' => FALSE,
],
],
],
];
4 changes: 2 additions & 2 deletions templates/CRM/Admin/Page/PaymentProcessor.tpl
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@

{if $action ne 1 and $action ne 2}
<div class="action-link">
{crmButton q="action=add&reset=1&pp=$defaultPaymentProcessorType" id="newPaymentProcessor" icon="plus-circle"}{ts}Add Payment Processor{/ts}{/crmButton}
{crmButton p='civicrm/admin/paymentProcessor/edit' q="action=add&reset=1" id="newPaymentProcessor" icon="plus-circle"}{ts}Add Payment Processor{/ts}{/crmButton}
</div>
{/if}
</div>
@@ -62,7 +62,7 @@
{ts}There are no Payment Processors entered.{/ts}
</div>
<div class="action-link">
{crmButton p='civicrm/admin/paymentProcessor' q="action=add&reset=1&pp=$defaultPaymentProcessorType" id="newPaymentProcessor" icon="plus-circle"}{ts}Add Payment Processor{/ts}{/crmButton}
{crmButton p='civicrm/admin/paymentProcessor/edit' q="action=add&reset=1" id="newPaymentProcessor" icon="plus-circle"}{ts}Add Payment Processor{/ts}{/crmButton}
</div>
{/if}
</div>
30 changes: 30 additions & 0 deletions tests/phpunit/api/v4/Entity/DomainTest.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@

use api\v4\Api4TestBase;
use Civi\Api4\Domain;
use Civi\Api4\WordReplacement;
use Civi\Test\TransactionalInterface;

/**
@@ -32,6 +33,10 @@ public function testActiveDomain() {
->addValue('name', 'Not current')
->addValue('version', \CRM_Utils_System::version())
->execute();
Domain::create(FALSE)
->addValue('name', 'Also not current')
->addValue('version', \CRM_Utils_System::version())
->execute();

Domain::update(FALSE)
->addValue('name', 'Currently the current domain')
@@ -50,6 +55,31 @@ public function testActiveDomain() {

$this->assertTrue($getAll['Currently the current domain']['is_active']);
$this->assertFalse($getAll['Not current']['is_active']);
$this->assertFalse($getAll['Also not current']['is_active']);

$getNotCurrent = Domain::get(FALSE)
->addWhere('id', '!=', 'current_domain')
->execute()->column('name');

$this->assertContains('Not current', $getNotCurrent);
$this->assertContains('Also not current', $getNotCurrent);
$this->assertNotContains('Currently the current domain', $getNotCurrent);

$wordReplacements = $this->saveTestRecords('WordReplacement', [
'records' => [
['find_word' => 'One', 'replace_word' => 'First'],
['find_word' => 'Two', 'replace_word' => 'Second', 'domain_id:name' => 'Not current'],
['find_word' => 'Three', 'replace_word' => 'Third', 'domain_id:name' => 'Also not current'],
],
])->column('id');

$fromTwoDomains = WordReplacement::get(FALSE)
->addWhere('domain_id:name', 'IN', ['current_domain', 'Not current'])
->execute()->column('id');

$this->assertContains($wordReplacements[0], $fromTwoDomains);
$this->assertContains($wordReplacements[1], $fromTwoDomains);
$this->assertNotContains($wordReplacements[2], $fromTwoDomains);
}

}
5 changes: 5 additions & 0 deletions xml/schema/Financial/PaymentProcessor.xml
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@
<name>civicrm_payment_processor</name>
<add>1.8</add>
<component>CiviContribute</component>
<paths>
<add>civicrm/admin/paymentProcessor/edit?action=add&amp;reset=1</add>
<update>civicrm/admin/paymentProcessor/edit?action=update&amp;id=[id]&amp;reset=1</update>
<delete>civicrm/admin/paymentProcessor/edit?action=delete&amp;id=[id]&amp;reset=1</delete>
</paths>
<field>
<name>id</name>
<title>Payment Processor ID</title>

0 comments on commit 64ee023

Please sign in to comment.