From 3c3333d2a4755568bc0107b9b63fee9b7c574dd1 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 27 Oct 2019 13:07:57 +1100 Subject: [PATCH] Implement PaymentProcessor and PaymentProcessorType APIv4 Entities --- CRM/Case/DAO/Case.php | 2 +- CRM/Financial/DAO/PaymentProcessor.php | 6 +- CRM/Financial/DAO/PaymentProcessorType.php | 7 +- Civi/Api4/Action/PaymentProcessor/Create.php | 43 ++++++++++++ .../PaymentProcessorSaveTrait.php | 65 +++++++++++++++++++ Civi/Api4/Action/PaymentProcessor/Save.php | 43 ++++++++++++ .../Action/PaymentProcessorType/Create.php | 43 ++++++++++++ .../PaymentProcessorTypeSaveTrait.php | 57 ++++++++++++++++ .../Api4/Action/PaymentProcessorType/Save.php | 43 ++++++++++++ Civi/Api4/PaymentProcessor.php | 61 +++++++++++++++++ Civi/Api4/PaymentProcessorType.php | 61 +++++++++++++++++ tests/phpunit/api/v3/PaymentProcessorTest.php | 6 +- .../api/v3/PaymentProcessorTypeTest.php | 12 +++- xml/schema/Financial/PaymentProcessor.xml | 4 ++ xml/schema/Financial/PaymentProcessorType.xml | 5 ++ 15 files changed, 453 insertions(+), 5 deletions(-) create mode 100644 Civi/Api4/Action/PaymentProcessor/Create.php create mode 100644 Civi/Api4/Action/PaymentProcessor/PaymentProcessorSaveTrait.php create mode 100644 Civi/Api4/Action/PaymentProcessor/Save.php create mode 100644 Civi/Api4/Action/PaymentProcessorType/Create.php create mode 100644 Civi/Api4/Action/PaymentProcessorType/PaymentProcessorTypeSaveTrait.php create mode 100644 Civi/Api4/Action/PaymentProcessorType/Save.php create mode 100644 Civi/Api4/PaymentProcessor.php create mode 100644 Civi/Api4/PaymentProcessorType.php diff --git a/CRM/Case/DAO/Case.php b/CRM/Case/DAO/Case.php index d1fbdc8cf8b..c60cc3da40c 100644 --- a/CRM/Case/DAO/Case.php +++ b/CRM/Case/DAO/Case.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Case/Case.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:c5896e4b577b32d8a2c62d3cba65119d) + * (GenCodeChecksum:4fa22b57b48574c5e6643b13964140d4) */ /** diff --git a/CRM/Financial/DAO/PaymentProcessor.php b/CRM/Financial/DAO/PaymentProcessor.php index 48676c59918..5ac44e667a4 100644 --- a/CRM/Financial/DAO/PaymentProcessor.php +++ b/CRM/Financial/DAO/PaymentProcessor.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Financial/PaymentProcessor.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:6d3b0b9b13fae223bc45c6c1e4ce7b94) + * (GenCodeChecksum:1f57ba8617085cdc968ce42aeaca15ec) */ /** @@ -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', @@ -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', @@ -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', @@ -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', diff --git a/CRM/Financial/DAO/PaymentProcessorType.php b/CRM/Financial/DAO/PaymentProcessorType.php index 7230d340df8..f53676e43f2 100644 --- a/CRM/Financial/DAO/PaymentProcessorType.php +++ b/CRM/Financial/DAO/PaymentProcessorType.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Financial/PaymentProcessorType.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:65231e0b77bcce22bd505b89ace63506) + * (GenCodeChecksum:c48a828ea82a92860f9f6dc5817c3230) */ /** @@ -196,6 +196,7 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Payment Processor variable name to be used in code'), 'description' => ts('Payment Processor Name.'), + 'required' => TRUE, 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, 'where' => 'civicrm_payment_processor_type.name', @@ -209,6 +210,7 @@ public static function &fields() { 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Payment Processor Title'), 'description' => ts('Payment Processor Name.'), + 'required' => TRUE, 'maxlength' => 127, 'size' => CRM_Utils_Type::HUGE, 'where' => 'civicrm_payment_processor_type.title', @@ -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', @@ -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', @@ -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', diff --git a/Civi/Api4/Action/PaymentProcessor/Create.php b/Civi/Api4/Action/PaymentProcessor/Create.php new file mode 100644 index 00000000000..aeaba093bdc --- /dev/null +++ b/Civi/Api4/Action/PaymentProcessor/Create.php @@ -0,0 +1,43 @@ +addWhere('id', '=', $item['payment_processor_type_id'])->execute(); + foreach ($paymentProcessorTypes as $paymentProcessorType) { + $item['payment_instrument_id'] = $paymentProcessorType['payment_instrument_id']; + } + } + } + return parent::writeObjects($items); + } + +} diff --git a/Civi/Api4/Action/PaymentProcessor/Save.php b/Civi/Api4/Action/PaymentProcessor/Save.php new file mode 100644 index 00000000000..30345529eab --- /dev/null +++ b/Civi/Api4/Action/PaymentProcessor/Save.php @@ -0,0 +1,43 @@ +_params; @@ -88,6 +89,7 @@ public function testPaymentProcessorCreate() { /** * Update payment processor. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorUpdate() { $params = $this->_params; @@ -131,6 +133,7 @@ public function testPaymentProcessorCreateExample() { /** * Check payment processor delete. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorDelete() { $result = $this->callAPISuccess('payment_processor', 'create', $this->_params); @@ -143,6 +146,7 @@ public function testPaymentProcessorDelete() { /** * Check with valid params array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorsGet() { $params = $this->_params; diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index 7913770d5de..d5c5379e29a 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -38,7 +38,6 @@ public function setUp() { parent::setUp(); $this->useTransaction(TRUE); - $this->_apiversion = 3; } // function tearDown() { @@ -53,6 +52,7 @@ public function setUp() { /** * Check with no name. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeCreateWithoutName() { $payProcParams = [ @@ -66,6 +66,7 @@ public function testPaymentProcessorTypeCreateWithoutName() { /** * Create payment processor type. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeCreate() { $params = [ @@ -100,6 +101,7 @@ public function testPaymentProcessorTypeCreateExample() { /** * Check with empty array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDeleteEmpty() { $params = []; @@ -108,6 +110,7 @@ public function testPaymentProcessorTypeDeleteEmpty() { /** * Check with No array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDeleteParamsNotArray() { $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string'); @@ -115,6 +118,7 @@ public function testPaymentProcessorTypeDeleteParamsNotArray() { /** * Check if required fields are not passed. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDeleteWithoutRequired() { $params = [ @@ -129,6 +133,7 @@ public function testPaymentProcessorTypeDeleteWithoutRequired() { /** * Check with incorrect required fields. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDeleteWithIncorrectData() { $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']); @@ -136,6 +141,7 @@ public function testPaymentProcessorTypeDeleteWithIncorrectData() { /** * Check payment processor type delete. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDelete() { $payProcType = $this->paymentProcessorTypeCreate(); @@ -150,6 +156,7 @@ public function testPaymentProcessorTypeDelete() { /** * Check with empty array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeUpdateEmpty() { $params = []; @@ -167,6 +174,7 @@ public function testPaymentProcessorTypeUpdateParamsNotArray() { /** * Check with all parameters. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeUpdate() { // create sample payment processor type. @@ -192,6 +200,7 @@ public function testPaymentProcessorTypeUpdate() { /** * Check with empty array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypesGetEmptyParams() { $results = $this->callAPISuccess('payment_processor_type', 'get', []); @@ -223,6 +232,7 @@ public function testPaymentProcessorTypesGetEmptyParams() { /** * Check with valid params array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypesGet() { $firstRelTypeParams = [ diff --git a/xml/schema/Financial/PaymentProcessor.xml b/xml/schema/Financial/PaymentProcessor.xml index 76d1ef13bed..35f7f61c427 100644 --- a/xml/schema/Financial/PaymentProcessor.xml +++ b/xml/schema/Financial/PaymentProcessor.xml @@ -86,6 +86,7 @@ 10 4.3 + true payment_processor_type_id @@ -99,6 +100,7 @@ boolean Is this processor active? 1.8 + 1 is_default @@ -106,6 +108,7 @@ boolean Is this processor the default? 1.8 + 0 is_test @@ -113,6 +116,7 @@ boolean Is this processor for a test site? 1.8 + 0 UI_name_test_domain_id diff --git a/xml/schema/Financial/PaymentProcessorType.xml b/xml/schema/Financial/PaymentProcessorType.xml index 3e5de526821..84d9871cb7c 100644 --- a/xml/schema/Financial/PaymentProcessorType.xml +++ b/xml/schema/Financial/PaymentProcessorType.xml @@ -24,6 +24,7 @@ 64 Payment Processor Name. 1.8 + true title @@ -32,6 +33,7 @@ 127 Payment Processor Name. 1.8 + true description @@ -47,6 +49,7 @@ boolean Is this processor active? 1.8 + 1 is_default @@ -54,6 +57,7 @@ boolean Is this processor the default? 1.8 + 0 UI_name @@ -95,6 +99,7 @@ varchar 255 1.8 + true url_site_default