diff --git a/CRM/Financial/DAO/PaymentProcessor.php b/CRM/Financial/DAO/PaymentProcessor.php index 48676c59918f..5ac44e667a42 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 7230d340df86..203ecd6a1587 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:53099eb7a742c6c3f4921806e3dc76f1) */ /** @@ -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 */ @@ -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', @@ -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', @@ -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/CRM/Upgrade/Incremental/sql/5.20.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.20.alpha1.mysql.tpl index 26b73a833bcc..1faf76c35bf3 100644 --- a/CRM/Upgrade/Incremental/sql/5.20.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.20.alpha1.mysql.tpl @@ -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; diff --git a/Civi/Api4/Action/PaymentProcessor/Create.php b/Civi/Api4/Action/PaymentProcessor/Create.php new file mode 100644 index 000000000000..aeaba093bdcb --- /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 000000000000..30345529eab4 --- /dev/null +++ b/Civi/Api4/Action/PaymentProcessor/Save.php @@ -0,0 +1,43 @@ +getFieldByName('domain_id')->setRequired(FALSE)->setDefaultValue('current_domain'); + $financial_account_id = new FieldSpec('financial_account_id', 'PaymentProcessor', 'Integer'); + $financial_account_id + ->setTitle('Financial Account ID') + ->setDescription('The financial account that this payment processor is linked to') + ->setRequired(FALSE) + ->setDefaultValue(\CRM_Financial_BAO_PaymentProcessor::getDefaultFinancialAccountID()); + $spec->addFieldSpec($financial_account_id); + } + + /** + * @inheritDoc + */ + public function applies($entity, $action) { + return $entity === 'PaymentProcessor' && in_array($action, ['create']); + } + +} diff --git a/Civi/Api4/Service/Spec/Provider/PaymentProcessorTypeCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/PaymentProcessorTypeCreationSpecProvider.php new file mode 100644 index 000000000000..f0ed1edf8767 --- /dev/null +++ b/Civi/Api4/Service/Spec/Provider/PaymentProcessorTypeCreationSpecProvider.php @@ -0,0 +1,56 @@ +getFieldByName('payment_instrument_id')->setRequired(FALSE)->setDefaultValue(1); + } + + /** + * @inheritDoc + */ + public function applies($entity, $action) { + return $entity === 'PaymentProcessorType' && in_array($action, ['create']); + } + +} diff --git a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php index 7aaab9e7fcf9..d75d94a048f9 100644 --- a/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php +++ b/tests/phpunit/CRM/Financial/BAO/PaymentProcessorTypeTest.php @@ -43,6 +43,7 @@ public function testCreate() { 'name' => 'Test_Payment_Processor', 'title' => 'Test Payment Processor', 'billing_mode' => 1, + 'class_name' => 'Payment_Dummy', ]; $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params); $result = $this->assertDBNotNull( @@ -63,6 +64,7 @@ public function testRetrieve() { 'name' => 'Test_Retrieve_Payment_Processor', 'title' => 'Test Retrieve Payment Processor', 'billing_mode' => 1, + 'class_name' => 'Payment_Dummy', ]; $defaults = []; CRM_Financial_BAO_PaymentProcessorType::create($params); @@ -79,6 +81,7 @@ public function testSetIsActive() { 'title' => 'Test Set Payment Processor', 'billing_mode' => 1, 'is_active' => 1, + 'class_name' => 'Payment_Dummy', ]; $paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params); @@ -116,6 +119,7 @@ public function testDel() { 'title' => 'Test Del Payment Processor', 'billing_mode' => 1, 'is_active' => 1, + 'class_name' => 'Payment_Dummy', ]; $defaults = []; diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index 6c54af7867b3..50a4583f2792 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -32,7 +32,6 @@ */ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { protected $_paymentProcessorType; - protected $_apiversion = 3; protected $_params; /** @@ -64,6 +63,7 @@ public function setUp() { /** * Check with no name. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorCreateWithoutName() { $payProcParams = [ @@ -74,6 +74,7 @@ public function testPaymentProcessorCreateWithoutName() { /** * Create payment processor. + * @dataProvider versionThreeAndFour * * @throws \Exception */ @@ -95,6 +96,7 @@ public function testPaymentProcessorCreate() { /** * Update payment processor. + * @dataProvider versionThreeAndFour * * @throws \CRM_Core_Exception */ @@ -140,6 +142,7 @@ public function testPaymentProcessorCreateExample() { /** * Check payment processor delete. + * @dataProvider versionThreeAndFour * * @throws \CRM_Core_Exception */ @@ -154,6 +157,7 @@ public function testPaymentProcessorDelete() { /** * Check with valid params array. + * @dataProvider versionThreeAndFour * * @throws \CRM_Core_Exception */ diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index 7913770d5de7..d5c5379e29a4 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 76d1ef13bed1..35f7f61c427d 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 3e5de5268217..b33bea6f9528 100644 --- a/xml/schema/Financial/PaymentProcessorType.xml +++ b/xml/schema/Financial/PaymentProcessorType.xml @@ -22,16 +22,18 @@ Payment Processor variable name to be used in code varchar 64 - Payment Processor Name. + Payment Processor Type Name. 1.8 + true title - Payment Processor Title + Payment Processor Type Title varchar 127 - Payment Processor Name. + Payment Processor Type Title. 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