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

Commit

Permalink
Feature gate PaymentApi (#4176)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Aljullu authored May 10, 2021
1 parent 4f34e6d commit 0de2e53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/blocks/feature-flags-and-experimental-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ We also have individual features or code blocks behind a feature flag, this is a
### Feature plugin flag

- Draft order and cleanup process ([PHP flag](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/e167b2c99c68e8113b4e371fefdd6f9a356ed2e8/src/Domain/Services/DraftOrders.php#L42-L51)).
- 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)).
- ⚛️ 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)).
- ⚛️ 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)).
- 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)).
Expand Down
22 changes: 13 additions & 9 deletions src/Domain/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ protected function init() {
$this->container->get( DraftOrders::class )->init();
$this->container->get( CreateAccount::class )->init();
$this->container->get( ExtendRestApi::class );
$this->container->get( PaymentsApi::class );
$this->container->get( RestApi::class );
$this->container->get( GoogleAnalytics::class );
$this->container->get( BlockTypesController::class );
if ( $this->package->feature()->is_feature_plugin_build() ) {
$this->container->get( PaymentsApi::class );
}
}

/**
Expand Down Expand Up @@ -169,14 +171,6 @@ function( Container $container ) {
return new PaymentMethodRegistry();
}
);
$this->container->register(
PaymentsApi::class,
function ( Container $container ) {
$payment_method_registry = $container->get( PaymentMethodRegistry::class );
$asset_data_registry = $container->get( AssetDataRegistry::class );
return new PaymentsApi( $payment_method_registry, $asset_data_registry );
}
);
$this->container->register(
RestApi::class,
function ( Container $container ) {
Expand Down Expand Up @@ -248,6 +242,16 @@ function( Container $container ) {
return new GoogleAnalytics( $asset_api );
}
);
if ( $this->package->feature()->is_feature_plugin_build() ) {
$this->container->register(
PaymentsApi::class,
function ( Container $container ) {
$payment_method_registry = $container->get( PaymentMethodRegistry::class );
$asset_data_registry = $container->get( AssetDataRegistry::class );
return new PaymentsApi( $payment_method_registry, $asset_data_registry );
}
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function verify_payment_methods_dependencies() {
if ( ! wp_script_is( $dep, 'registered' ) ) {
$error_handle = $dep . '-dependency-error';
$error_message = sprintf(
'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',
'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',
esc_html( $payment_method_script ),
esc_html( $dep )
);
Expand Down

0 comments on commit 0de2e53

Please sign in to comment.