Skip to content

Commit

Permalink
Implement PaymentProcessor and PaymentProcessorType APIv4 Entities
Browse files Browse the repository at this point in the history
Move default values to spec as per Coleman

Fix class name in tests and fix default values on tables

Mock financial_account_id field
  • Loading branch information
seamuslee001 committed Oct 29, 2019
1 parent 66d736a commit ea5e4e9
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CRM/Financial/DAO/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Financial/PaymentProcessor.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:6d3b0b9b13fae223bc45c6c1e4ce7b94)
* (GenCodeChecksum:1f57ba8617085cdc968ce42aeaca15ec)
*/

/**
Expand Down Expand Up @@ -280,6 +280,7 @@ public static function &fields() {
'name' => 'payment_processor_type_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Payment Processor Type ID'),
'required' => TRUE,
'where' => 'civicrm_payment_processor.payment_processor_type_id',
'table_name' => 'civicrm_payment_processor',
'entity' => 'PaymentProcessor',
Expand All @@ -298,6 +299,7 @@ public static function &fields() {
'title' => ts('Processor is Active?'),
'description' => ts('Is this processor active?'),
'where' => 'civicrm_payment_processor.is_active',
'default' => '1',
'table_name' => 'civicrm_payment_processor',
'entity' => 'PaymentProcessor',
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
Expand All @@ -309,6 +311,7 @@ public static function &fields() {
'title' => ts('Processor Is Default?'),
'description' => ts('Is this processor the default?'),
'where' => 'civicrm_payment_processor.is_default',
'default' => '0',
'table_name' => 'civicrm_payment_processor',
'entity' => 'PaymentProcessor',
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
Expand All @@ -320,6 +323,7 @@ public static function &fields() {
'title' => ts('Is Test Processor?'),
'description' => ts('Is this processor for a test site?'),
'where' => 'civicrm_payment_processor.is_test',
'default' => '0',
'table_name' => 'civicrm_payment_processor',
'entity' => 'PaymentProcessor',
'bao' => 'CRM_Financial_BAO_PaymentProcessor',
Expand Down
17 changes: 11 additions & 6 deletions CRM/Financial/DAO/PaymentProcessorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Financial/PaymentProcessorType.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:65231e0b77bcce22bd505b89ace63506)
* (GenCodeChecksum:53099eb7a742c6c3f4921806e3dc76f1)
*/

/**
Expand Down Expand Up @@ -36,14 +36,14 @@ class CRM_Financial_DAO_PaymentProcessorType extends CRM_Core_DAO {
public $id;

/**
* Payment Processor Name.
* Payment Processor Type Name.
*
* @var string
*/
public $name;

/**
* Payment Processor Name.
* Payment Processor Type Title.
*
* @var string
*/
Expand Down Expand Up @@ -195,7 +195,8 @@ public static function &fields() {
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Payment Processor variable name to be used in code'),
'description' => ts('Payment Processor Name.'),
'description' => ts('Payment Processor Type Name.'),
'required' => TRUE,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'where' => 'civicrm_payment_processor_type.name',
Expand All @@ -207,8 +208,9 @@ public static function &fields() {
'title' => [
'name' => 'title',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Payment Processor Title'),
'description' => ts('Payment Processor Name.'),
'title' => ts('Payment Processor Type Title'),
'description' => ts('Payment Processor Type Title.'),
'required' => TRUE,
'maxlength' => 127,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_payment_processor_type.title',
Expand Down Expand Up @@ -236,6 +238,7 @@ public static function &fields() {
'title' => ts('Processor Type Is Active?'),
'description' => ts('Is this processor active?'),
'where' => 'civicrm_payment_processor_type.is_active',
'default' => '1',
'table_name' => 'civicrm_payment_processor_type',
'entity' => 'PaymentProcessorType',
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
Expand All @@ -247,6 +250,7 @@ public static function &fields() {
'title' => ts('Processor Type is Default?'),
'description' => ts('Is this processor the default?'),
'where' => 'civicrm_payment_processor_type.is_default',
'default' => '0',
'table_name' => 'civicrm_payment_processor_type',
'entity' => 'PaymentProcessorType',
'bao' => 'CRM_Financial_BAO_PaymentProcessorType',
Expand Down Expand Up @@ -304,6 +308,7 @@ public static function &fields() {
'name' => 'class_name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Suffix for PHP class name implementation'),
'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_payment_processor_type.class_name',
Expand Down
11 changes: 11 additions & 0 deletions CRM/Upgrade/Incremental/sql/5.20.alpha1.mysql.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{* file to handle db changes in 5.20.alpha1 during upgrade *}

UPDATE civicrm_navigation SET url = "civicrm/api3" WHERE url = "civicrm/api" AND domain_id = {$domainID};

UPDATE civicrm_payment_processor SET is_default = 0 WHERE is_default IS NULL;
UPDATE civicrm_payment_processor SET is_active = 1 WHERE is_active IS NULL;
UPDATE civicrm_payment_processor SET is_test = 0 WHERE is_test IS NULL;
UPDATE civicrm_payment_processor_type SET is_active = 1 WHERE is_active IS NULL;
UPDATE civicrm_payment_processor_type SET is_default = 0 WHERE is_default IS NULL;
ALTER TABLE civicrm_payment_processor ALTER COLUMN is_default SET DEFAULT 0;
ALTER TABLE civicrm_payment_processor ALTER COLUMN is_active SET DEFAULT 1;
ALTER TABLE civicrm_payment_processor ALTER COLUMN is_test SET DEFAULT 0;
ALTER TABLE civicrm_payment_processor_type ALTER COLUMN is_active SET DEFAULT 1;
ALTER TABLE civicrm_payment_processor_type ALTER COLUMN is_default SET DEFAULT 0;
43 changes: 43 additions & 0 deletions Civi/Api4/Action/PaymentProcessor/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
* $Id$
*
*/


namespace Civi\Api4\Action\PaymentProcessor;

class Create extends \Civi\Api4\Generic\DAOCreateAction {
use PaymentProcessorSaveTrait;

}
62 changes: 62 additions & 0 deletions Civi/Api4/Action/PaymentProcessor/PaymentProcessorSaveTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
* $Id$
*
*/

namespace Civi\Api4\Action\PaymentProcessor;

/**
* @inheritDoc
*/
trait PaymentProcessorSaveTrait {

/**
* @inheritDoc
*/
protected function writeObjects($items) {
foreach ($items as &$item) {
if (empty($item['financial_account_id'])) {
$item['financial_account_id'] = \CRM_Financial_BAO_PaymentProcessor::getDefaultFinancialAccountID();
}
if (empty($item['payment_instrument_id'])) {
$paymentProcessorTypes = \Civi\Api4\PaymentProcessorType::get()->addWhere('id', '=', $item['payment_processor_type_id'])->execute();
foreach ($paymentProcessorTypes as $paymentProcessorType) {
$item['payment_instrument_id'] = $paymentProcessorType['payment_instrument_id'];
}
}
}
return parent::writeObjects($items);
}

}
43 changes: 43 additions & 0 deletions Civi/Api4/Action/PaymentProcessor/Save.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
* $Id$
*
*/


namespace Civi\Api4\Action\PaymentProcessor;

class Save extends \Civi\Api4\Generic\DAOSaveAction {
use PaymentProcessorSaveTrait;

}
61 changes: 61 additions & 0 deletions Civi/Api4/PaymentProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
* $Id$
*
*/


namespace Civi\Api4;

/**
* Relationship entity.
*
* @package Civi\Api4
*/
class PaymentProcessor extends Generic\DAOEntity {

/**
* @return \Civi\Api4\Action\PaymentProcessor\Create
*/
public static function create() {
return new \Civi\Api4\Action\PaymentProcessor\Create(__CLASS__, __FUNCTION__);
}

/**
* @return \Civi\Api4\Action\PaymentProcessor\Save
*/
public static function save() {
return new \Civi\Api4\Action\PaymentProcessor\Save(__CLASS__, __FUNCTION__);
}

}
47 changes: 47 additions & 0 deletions Civi/Api4/PaymentProcessorType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
* $Id$
*
*/


namespace Civi\Api4;

/**
* Relationship entity.
*
* @package Civi\Api4
*/
class PaymentProcessorType extends Generic\DAOEntity {

}
Loading

0 comments on commit ea5e4e9

Please sign in to comment.