diff --git a/CRM/Upgrade/Incremental/sql/5.23.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.23.alpha1.mysql.tpl index 31f83f66408e..54cb0a387166 100644 --- a/CRM/Upgrade/Incremental/sql/5.23.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.23.alpha1.mysql.tpl @@ -1 +1,11 @@ {* file to handle db changes in 5.23.alpha1 during upgrade *} +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..f364f305914b --- /dev/null +++ b/Civi/Api4/Action/PaymentProcessor/Create.php @@ -0,0 +1,24 @@ +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..f56e2bf3c8fd --- /dev/null +++ b/Civi/Api4/Action/PaymentProcessor/Save.php @@ -0,0 +1,23 @@ +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()) + ->setFkEntity('FinancialAccount'); + $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/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index e3c8a713d72f..0ed3b303a824 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -47,6 +47,7 @@ public function setUp() { /** * Check create with no name specified. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorCreateWithoutName() { $this->callAPIFailure('payment_processor', 'create', ['is_active' => 1]); @@ -54,6 +55,7 @@ public function testPaymentProcessorCreateWithoutName() { /** * Create payment processor. + * @dataProvider versionThreeAndFour * * @throws \CRM_Core_Exception */ @@ -75,6 +77,7 @@ public function testPaymentProcessorCreate() { /** * Update payment processor. + * @dataProvider versionThreeAndFour * * @throws \CRM_Core_Exception */ @@ -120,6 +123,7 @@ public function testPaymentProcessorCreateExample() { /** * Check payment processor delete. + * @dataProvider versionThreeAndFour * * @throws \CRM_Core_Exception */ @@ -134,6 +138,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 9cbd9e5326ab..79cfbd2a6729 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -22,7 +22,6 @@ public function setUp() { parent::setUp(); $this->useTransaction(TRUE); - $this->_apiversion = 3; } // function tearDown() { @@ -37,6 +36,7 @@ public function setUp() { /** * Check with no name. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeCreateWithoutName() { $payProcParams = [ @@ -50,6 +50,7 @@ public function testPaymentProcessorTypeCreateWithoutName() { /** * Create payment processor type. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeCreate() { $params = [ @@ -84,6 +85,7 @@ public function testPaymentProcessorTypeCreateExample() { /** * Check with empty array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDeleteEmpty() { $params = []; @@ -92,6 +94,7 @@ public function testPaymentProcessorTypeDeleteEmpty() { /** * Check if required fields are not passed. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDeleteWithoutRequired() { $params = [ @@ -106,6 +109,7 @@ public function testPaymentProcessorTypeDeleteWithoutRequired() { /** * Check with incorrect required fields. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDeleteWithIncorrectData() { $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']); @@ -113,6 +117,7 @@ public function testPaymentProcessorTypeDeleteWithIncorrectData() { /** * Check payment processor type delete. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeDelete() { $payProcType = $this->paymentProcessorTypeCreate(); @@ -127,6 +132,7 @@ public function testPaymentProcessorTypeDelete() { /** * Check with empty array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeUpdateEmpty() { $params = []; @@ -136,6 +142,7 @@ public function testPaymentProcessorTypeUpdateEmpty() { /** * Check with all parameters. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypeUpdate() { // create sample payment processor type. @@ -161,6 +168,7 @@ public function testPaymentProcessorTypeUpdate() { /** * Check with empty array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypesGetEmptyParams() { $results = $this->callAPISuccess('payment_processor_type', 'get', []); @@ -192,6 +200,7 @@ public function testPaymentProcessorTypesGetEmptyParams() { /** * Check with valid params array. + * @dataProvider versionThreeAndFour */ public function testPaymentProcessorTypesGet() { $firstRelTypeParams = [