Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 0de2e53

Browse files
authored
Feature gate PaymentApi (#4176)
* Feature gate PaymentApi * Improve payment method missing dependencies error message so it's clear it only affects blocks * Add PaymentApi feature flags to list of feature flags in docs
1 parent 4f34e6d commit 0de2e53

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

docs/blocks/feature-flags-and-experimental-interfaces.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ We also have individual features or code blocks behind a feature flag, this is a
3434
### Feature plugin flag
3535

3636
- Draft order and cleanup process ([PHP flag](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/e167b2c99c68e8113b4e371fefdd6f9a356ed2e8/src/Domain/Services/DraftOrders.php#L42-L51)).
37+
- Payment API ([PHP flag 1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/07387889ec3a03769eb490821ee608d4e741e942/src/Domain/Bootstrap.php#L92-L94) | [PHP flag 2](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/07387889ec3a03769eb490821ee608d4e741e942/src/Domain/Bootstrap.php#L245-L254)).
3738
- ⚛️ Product Price new controls ([JS flag 1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/price/attributes.js#L13-L44) | [JS flag 2-1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/8d2f0ad8ade2c7217769b431f93de76d6cfacf6e/assets/js/atomic/blocks/product-elements/price/block.js#L116) | [JS flag 2-2](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/8d2f0ad8ade2c7217769b431f93de76d6cfacf6e/assets/js/atomic/blocks/product-elements/price/block.js#L114) | [JS flag 2-3](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/8d2f0ad8ade2c7217769b431f93de76d6cfacf6e/assets/js/atomic/blocks/product-elements/price/block.js#L91) | [JS flag 2-4](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/8d2f0ad8ade2c7217769b431f93de76d6cfacf6e/assets/js/atomic/blocks/product-elements/price/block.js#L95) | [JS flag 2-5](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/8d2f0ad8ade2c7217769b431f93de76d6cfacf6e/assets/js/atomic/blocks/product-elements/price/block.js#L106) | [JS flag 3-1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/price/edit.js#L59-L108) | [JS flag 3-2](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/price/edit.js#L114-L131)).
3839
- ⚛️ Product Title new controls ([JS flag 1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/title/attributes.js#L21-L40) | [JS flag 2-1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/title/block.js#L70-L72) | [JS flag 2-2](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/title/block.js#L94-L95) | [JS flag 2-3](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/title/block.js#L104) | [JS flag 3-1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/title/edit.js#L47-L54) | [JS flag 3-2](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/title/edit.js#L77-L107) | [JS flag 3-3](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b3a9753d8b7dae18b36025d09fbff835b8365de0/assets/js/atomic/blocks/product-elements/title/edit.js#L116-L129)).
3940
- Utility function to pass styles to a block ([JS flag](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/9ebddbc5d21eb3cc67fedddbccbd86453313eb64/assets/js/atomic/utils/block-styling.js#L6-L12)).

src/Domain/Bootstrap.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ protected function init() {
8686
$this->container->get( DraftOrders::class )->init();
8787
$this->container->get( CreateAccount::class )->init();
8888
$this->container->get( ExtendRestApi::class );
89-
$this->container->get( PaymentsApi::class );
9089
$this->container->get( RestApi::class );
9190
$this->container->get( GoogleAnalytics::class );
9291
$this->container->get( BlockTypesController::class );
92+
if ( $this->package->feature()->is_feature_plugin_build() ) {
93+
$this->container->get( PaymentsApi::class );
94+
}
9395
}
9496

9597
/**
@@ -169,14 +171,6 @@ function( Container $container ) {
169171
return new PaymentMethodRegistry();
170172
}
171173
);
172-
$this->container->register(
173-
PaymentsApi::class,
174-
function ( Container $container ) {
175-
$payment_method_registry = $container->get( PaymentMethodRegistry::class );
176-
$asset_data_registry = $container->get( AssetDataRegistry::class );
177-
return new PaymentsApi( $payment_method_registry, $asset_data_registry );
178-
}
179-
);
180174
$this->container->register(
181175
RestApi::class,
182176
function ( Container $container ) {
@@ -248,6 +242,16 @@ function( Container $container ) {
248242
return new GoogleAnalytics( $asset_api );
249243
}
250244
);
245+
if ( $this->package->feature()->is_feature_plugin_build() ) {
246+
$this->container->register(
247+
PaymentsApi::class,
248+
function ( Container $container ) {
249+
$payment_method_registry = $container->get( PaymentMethodRegistry::class );
250+
$asset_data_registry = $container->get( AssetDataRegistry::class );
251+
return new PaymentsApi( $payment_method_registry, $asset_data_registry );
252+
}
253+
);
254+
}
251255
}
252256

253257
/**

src/Payments/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function verify_payment_methods_dependencies() {
198198
if ( ! wp_script_is( $dep, 'registered' ) ) {
199199
$error_handle = $dep . '-dependency-error';
200200
$error_message = sprintf(
201-
'Payment gateway with handle \'%1$s\' has been deactivated because its dependency \'%2$s\' is not registered. Read the docs about registering assets for payment methods: https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/trunk/docs/extensibility/payment-method-integration.md#registering-assets',
201+
'Payment gateway with handle \'%1$s\' has been deactivated in Cart and Checkout blocks because its dependency \'%2$s\' is not registered. Read the docs about registering assets for payment methods: https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/trunk/docs/extensibility/payment-method-integration.md#registering-assets',
202202
esc_html( $payment_method_script ),
203203
esc_html( $dep )
204204
);

0 commit comments

Comments
 (0)