Remove all plugins / install base theme
This commit is contained in:
@@ -1,181 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
|
||||
use Automattic\WooCommerce\Blocks\Package;
|
||||
use Automattic\WooCommerce\Blocks\Payments\Integrations\BankTransfer;
|
||||
use Automattic\WooCommerce\Blocks\Payments\Integrations\CashOnDelivery;
|
||||
use Automattic\WooCommerce\Blocks\Payments\Integrations\Cheque;
|
||||
use Automattic\WooCommerce\Blocks\Payments\Integrations\PayPal;
|
||||
|
||||
/**
|
||||
* The Api class provides an interface to payment method registration.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
class Api {
|
||||
/**
|
||||
* Reference to the PaymentMethodRegistry instance.
|
||||
*
|
||||
* @var PaymentMethodRegistry
|
||||
*/
|
||||
private $payment_method_registry;
|
||||
|
||||
/**
|
||||
* Reference to the AssetDataRegistry instance.
|
||||
*
|
||||
* @var AssetDataRegistry
|
||||
*/
|
||||
private $asset_registry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param PaymentMethodRegistry $payment_method_registry An instance of Payment Method Registry.
|
||||
* @param AssetDataRegistry $asset_registry Used for registering data to pass along to the request.
|
||||
*/
|
||||
public function __construct( PaymentMethodRegistry $payment_method_registry, AssetDataRegistry $asset_registry ) {
|
||||
$this->payment_method_registry = $payment_method_registry;
|
||||
$this->asset_registry = $asset_registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize class features.
|
||||
*/
|
||||
public function init() {
|
||||
add_action( 'init', array( $this->payment_method_registry, 'initialize' ), 5 );
|
||||
add_filter( 'woocommerce_blocks_register_script_dependencies', array( $this, 'add_payment_method_script_dependencies' ), 10, 2 );
|
||||
add_action( 'woocommerce_blocks_checkout_enqueue_data', array( $this, 'add_payment_method_script_data' ) );
|
||||
add_action( 'woocommerce_blocks_cart_enqueue_data', array( $this, 'add_payment_method_script_data' ) );
|
||||
add_action( 'woocommerce_blocks_payment_method_type_registration', array( $this, 'register_payment_method_integrations' ) );
|
||||
add_action( 'wp_print_scripts', array( $this, 'verify_payment_methods_dependencies' ), 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add payment method script handles as script dependencies.
|
||||
*
|
||||
* @param array $dependencies Array of script dependencies.
|
||||
* @param string $handle Script handle.
|
||||
* @return array
|
||||
*/
|
||||
public function add_payment_method_script_dependencies( $dependencies, $handle ) {
|
||||
if ( ! in_array( $handle, [ 'wc-checkout-block', 'wc-checkout-block-frontend', 'wc-cart-block', 'wc-cart-block-frontend' ], true ) ) {
|
||||
return $dependencies;
|
||||
}
|
||||
return array_merge( $dependencies, $this->payment_method_registry->get_all_active_payment_method_script_dependencies() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the payment gateway is enabled.
|
||||
*
|
||||
* @param object $gateway Payment gateway.
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_payment_gateway_enabled( $gateway ) {
|
||||
return filter_var( $gateway->enabled, FILTER_VALIDATE_BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add payment method data to Asset Registry.
|
||||
*/
|
||||
public function add_payment_method_script_data() {
|
||||
// Enqueue the order of enabled gateways.
|
||||
if ( ! $this->asset_registry->exists( 'paymentMethodSortOrder' ) ) {
|
||||
// We use payment_gateways() here to get the sort order of all enabled gateways. Some may be
|
||||
// programmatically disabled later on, but we still need to know where the enabled ones are in the list.
|
||||
$payment_gateways = WC()->payment_gateways->payment_gateways();
|
||||
$enabled_gateways = array_filter( $payment_gateways, array( $this, 'is_payment_gateway_enabled' ) );
|
||||
$this->asset_registry->add( 'paymentMethodSortOrder', array_keys( $enabled_gateways ) );
|
||||
}
|
||||
|
||||
// Enqueue all registered gateway data (settings/config etc).
|
||||
$script_data = $this->payment_method_registry->get_all_registered_script_data();
|
||||
foreach ( $script_data as $asset_data_key => $asset_data_value ) {
|
||||
if ( ! $this->asset_registry->exists( $asset_data_key ) ) {
|
||||
$this->asset_registry->add( $asset_data_key, $asset_data_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register payment method integrations bundled with blocks.
|
||||
*
|
||||
* @param PaymentMethodRegistry $payment_method_registry Payment method registry instance.
|
||||
*/
|
||||
public function register_payment_method_integrations( PaymentMethodRegistry $payment_method_registry ) {
|
||||
$payment_method_registry->register(
|
||||
Package::container()->get( Cheque::class )
|
||||
);
|
||||
$payment_method_registry->register(
|
||||
Package::container()->get( PayPal::class )
|
||||
);
|
||||
$payment_method_registry->register(
|
||||
Package::container()->get( BankTransfer::class )
|
||||
);
|
||||
$payment_method_registry->register(
|
||||
Package::container()->get( CashOnDelivery::class )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify all dependencies of registered payment methods have been registered.
|
||||
* If not, remove that payment method script from the list of dependencies
|
||||
* of Cart and Checkout block scripts so it doesn't break the blocks and show
|
||||
* an error in the admin.
|
||||
*/
|
||||
public function verify_payment_methods_dependencies() {
|
||||
// Check that the wc-blocks script is registered before continuing. Some extensions may cause this function to run
|
||||
// before the payment method scripts' dependencies are registered.
|
||||
if ( ! wp_script_is( 'wc-blocks', 'registered' ) ) {
|
||||
return;
|
||||
}
|
||||
$wp_scripts = wp_scripts();
|
||||
$payment_method_scripts = $this->payment_method_registry->get_all_active_payment_method_script_dependencies();
|
||||
|
||||
foreach ( $payment_method_scripts as $payment_method_script ) {
|
||||
if (
|
||||
! array_key_exists( $payment_method_script, $wp_scripts->registered ) ||
|
||||
! property_exists( $wp_scripts->registered[ $payment_method_script ], 'deps' )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
$deps = $wp_scripts->registered[ $payment_method_script ]->deps;
|
||||
foreach ( $deps as $dep ) {
|
||||
if ( ! wp_script_is( $dep, 'registered' ) ) {
|
||||
$error_handle = $dep . '-dependency-error';
|
||||
$error_message = sprintf(
|
||||
'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-blocks/blob/060f63c04f0f34f645200b5d4da9212125c49177/docs/third-party-developers/extensibility/checkout-payment-methods/payment-method-integration.md#registering-assets',
|
||||
esc_html( $payment_method_script ),
|
||||
esc_html( $dep )
|
||||
);
|
||||
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
|
||||
error_log( $error_message );
|
||||
|
||||
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter,WordPress.WP.EnqueuedResourceParameters.MissingVersion
|
||||
wp_register_script( $error_handle, '' );
|
||||
wp_enqueue_script( $error_handle );
|
||||
wp_add_inline_script(
|
||||
$error_handle,
|
||||
sprintf( 'console.error( "%s" );', $error_message )
|
||||
);
|
||||
|
||||
$cart_checkout_scripts = [ 'wc-cart-block', 'wc-cart-block-frontend', 'wc-checkout-block', 'wc-checkout-block-frontend' ];
|
||||
foreach ( $cart_checkout_scripts as $script_handle ) {
|
||||
if (
|
||||
! array_key_exists( $script_handle, $wp_scripts->registered ) ||
|
||||
! property_exists( $wp_scripts->registered[ $script_handle ], 'deps' )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// Remove payment method script from dependencies.
|
||||
$wp_scripts->registered[ $script_handle ]->deps = array_diff(
|
||||
$wp_scripts->registered[ $script_handle ]->deps,
|
||||
[ $payment_method_script ]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments\Integrations;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodTypeInterface;
|
||||
|
||||
/**
|
||||
* AbstractPaymentMethodType class.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
abstract class AbstractPaymentMethodType implements PaymentMethodTypeInterface {
|
||||
/**
|
||||
* Payment method name defined by payment methods extending this class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* Settings from the WP options table
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $settings = [];
|
||||
|
||||
/**
|
||||
* Get a setting from the settings array if set.
|
||||
*
|
||||
* @param string $name Setting name.
|
||||
* @param mixed $default Value that is returned if the setting does not exist.
|
||||
* @return mixed
|
||||
*/
|
||||
protected function get_setting( $name, $default = '' ) {
|
||||
return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the payment method.
|
||||
*/
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_active() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of script handles to enqueue for this payment method in
|
||||
* the frontend context
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_payment_method_script_handles() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of script handles to enqueue for this payment method in
|
||||
* the admin context
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_payment_method_script_handles_for_admin() {
|
||||
return $this->get_payment_method_script_handles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of supported features.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_supported_features() {
|
||||
return [ 'products' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of key, value pairs of data made available to payment methods
|
||||
* client side.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_data() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of script handles to enqueue in the frontend context.
|
||||
*
|
||||
* Alias of get_payment_method_script_handles. Defined by IntegrationInterface.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_script_handles() {
|
||||
return $this->get_payment_method_script_handles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of script handles to enqueue in the admin context.
|
||||
*
|
||||
* Alias of get_payment_method_script_handles_for_admin. Defined by IntegrationInterface.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_editor_script_handles() {
|
||||
return $this->get_payment_method_script_handles_for_admin();
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of key, value pairs of data made available to the block on the client side.
|
||||
*
|
||||
* Alias of get_payment_method_data. Defined by IntegrationInterface.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_script_data() {
|
||||
return $this->get_payment_method_data();
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments\Integrations;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Assets\Api;
|
||||
|
||||
/**
|
||||
* Bank Transfer (BACS) payment method integration
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
final class BankTransfer extends AbstractPaymentMethodType {
|
||||
/**
|
||||
* Payment method name/id/slug (matches id in WC_Gateway_BACS in core).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'bacs';
|
||||
|
||||
/**
|
||||
* An instance of the Asset Api
|
||||
*
|
||||
* @var Api
|
||||
*/
|
||||
private $asset_api;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Api $asset_api An instance of Api.
|
||||
*/
|
||||
public function __construct( Api $asset_api ) {
|
||||
$this->asset_api = $asset_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the payment method type.
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->settings = get_option( 'woocommerce_bacs_settings', [] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_active() {
|
||||
return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of scripts/handles to be registered for this payment method.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_script_handles() {
|
||||
$this->asset_api->register_script(
|
||||
'wc-payment-method-bacs',
|
||||
'assets/client/blocks/wc-payment-method-bacs.js'
|
||||
);
|
||||
return [ 'wc-payment-method-bacs' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of key=>value pairs of data made available to the payment methods script.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_data() {
|
||||
return [
|
||||
'title' => $this->get_setting( 'title' ),
|
||||
'description' => $this->get_setting( 'description' ),
|
||||
'supports' => $this->get_supported_features(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments\Integrations;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Assets\Api;
|
||||
|
||||
/**
|
||||
* Cash on Delivery (COD) payment method integration
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
final class CashOnDelivery extends AbstractPaymentMethodType {
|
||||
/**
|
||||
* Payment method name/id/slug (matches id in WC_Gateway_COD in core).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cod';
|
||||
|
||||
/**
|
||||
* An instance of the Asset Api
|
||||
*
|
||||
* @var Api
|
||||
*/
|
||||
private $asset_api;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Api $asset_api An instance of Api.
|
||||
*/
|
||||
public function __construct( Api $asset_api ) {
|
||||
$this->asset_api = $asset_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the payment method type.
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->settings = get_option( 'woocommerce_cod_settings', [] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_active() {
|
||||
return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return enable_for_virtual option.
|
||||
*
|
||||
* @return boolean True if store allows COD payment for orders containing only virtual products.
|
||||
*/
|
||||
private function get_enable_for_virtual() {
|
||||
return filter_var( $this->get_setting( 'enable_for_virtual', false ), FILTER_VALIDATE_BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return enable_for_methods option.
|
||||
*
|
||||
* @return array Array of shipping methods (string ids) that allow COD. (If empty, all support COD.)
|
||||
*/
|
||||
private function get_enable_for_methods() {
|
||||
$enable_for_methods = $this->get_setting( 'enable_for_methods', [] );
|
||||
if ( '' === $enable_for_methods ) {
|
||||
return [];
|
||||
}
|
||||
return $enable_for_methods;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of scripts/handles to be registered for this payment method.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_script_handles() {
|
||||
$this->asset_api->register_script(
|
||||
'wc-payment-method-cod',
|
||||
'assets/client/blocks/wc-payment-method-cod.js'
|
||||
);
|
||||
return [ 'wc-payment-method-cod' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of key=>value pairs of data made available to the payment methods script.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_data() {
|
||||
return [
|
||||
'title' => $this->get_setting( 'title' ),
|
||||
'description' => $this->get_setting( 'description' ),
|
||||
'enableForVirtual' => $this->get_enable_for_virtual(),
|
||||
'enableForShippingMethods' => $this->get_enable_for_methods(),
|
||||
'supports' => $this->get_supported_features(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments\Integrations;
|
||||
|
||||
use Exception;
|
||||
use Automattic\WooCommerce\Blocks\Assets\Api;
|
||||
|
||||
/**
|
||||
* Cheque payment method integration
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
final class Cheque extends AbstractPaymentMethodType {
|
||||
/**
|
||||
* Payment method name defined by payment methods extending this class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cheque';
|
||||
|
||||
/**
|
||||
* An instance of the Asset Api
|
||||
*
|
||||
* @var Api
|
||||
*/
|
||||
private $asset_api;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Api $asset_api An instance of Api.
|
||||
*/
|
||||
public function __construct( Api $asset_api ) {
|
||||
$this->asset_api = $asset_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the payment method type.
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->settings = get_option( 'woocommerce_cheque_settings', [] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_active() {
|
||||
return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of scripts/handles to be registered for this payment method.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_script_handles() {
|
||||
$this->asset_api->register_script(
|
||||
'wc-payment-method-cheque',
|
||||
'assets/client/blocks/wc-payment-method-cheque.js'
|
||||
);
|
||||
return [ 'wc-payment-method-cheque' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of key=>value pairs of data made available to the payment methods script.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_data() {
|
||||
return [
|
||||
'title' => $this->get_setting( 'title' ),
|
||||
'description' => $this->get_setting( 'description' ),
|
||||
'supports' => $this->get_supported_features(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments\Integrations;
|
||||
|
||||
use WC_Gateway_Paypal;
|
||||
use Automattic\WooCommerce\Blocks\Assets\Api;
|
||||
|
||||
/**
|
||||
* PayPal Standard payment method integration
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
final class PayPal extends AbstractPaymentMethodType {
|
||||
/**
|
||||
* Payment method name defined by payment methods extending this class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'paypal';
|
||||
|
||||
/**
|
||||
* An instance of the Asset Api
|
||||
*
|
||||
* @var Api
|
||||
*/
|
||||
private $asset_api;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Api $asset_api An instance of Api.
|
||||
*/
|
||||
public function __construct( Api $asset_api ) {
|
||||
$this->asset_api = $asset_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the payment method type.
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->settings = get_option( 'woocommerce_paypal_settings', [] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_active() {
|
||||
return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of scripts/handles to be registered for this payment method.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_script_handles() {
|
||||
$this->asset_api->register_script(
|
||||
'wc-payment-method-paypal',
|
||||
'assets/client/blocks/wc-payment-method-paypal.js'
|
||||
);
|
||||
return [ 'wc-payment-method-paypal' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of key=>value pairs of data made available to the payment methods script.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_data() {
|
||||
return [
|
||||
'title' => $this->get_setting( 'title' ),
|
||||
'description' => $this->get_setting( 'description' ),
|
||||
'supports' => $this->get_supported_features(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of supported features.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_supported_features() {
|
||||
$gateway = new WC_Gateway_Paypal();
|
||||
$features = array_filter( $gateway->supports, array( $gateway, 'supports' ) );
|
||||
|
||||
/**
|
||||
* Filter to control what features are available for each payment gateway.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @example See docs/examples/payment-gateways-features-list.md
|
||||
*
|
||||
* @param array $features List of supported features.
|
||||
* @param string $name Gateway name.
|
||||
* @return array Updated list of supported features.
|
||||
*/
|
||||
return apply_filters( '__experimental_woocommerce_blocks_payment_gateway_features_list', $features, $this->get_name() );
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry;
|
||||
|
||||
/**
|
||||
* Class used for interacting with payment method types.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
final class PaymentMethodRegistry extends IntegrationRegistry {
|
||||
/**
|
||||
* Integration identifier is used to construct hook names and is given when the integration registry is initialized.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $registry_identifier = 'payment_method_type';
|
||||
|
||||
/**
|
||||
* Retrieves all registered payment methods that are also active.
|
||||
*
|
||||
* @return PaymentMethodTypeInterface[]
|
||||
*/
|
||||
public function get_all_active_registered() {
|
||||
return array_filter(
|
||||
$this->get_all_registered(),
|
||||
function( $payment_method ) {
|
||||
return $payment_method->is_active();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of all registered payment method script handles, but only for active payment methods.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_all_active_payment_method_script_dependencies() {
|
||||
$script_handles = [];
|
||||
$payment_methods = $this->get_all_active_registered();
|
||||
|
||||
foreach ( $payment_methods as $payment_method ) {
|
||||
$script_handles = array_merge(
|
||||
$script_handles,
|
||||
is_admin() ? $payment_method->get_payment_method_script_handles_for_admin() : $payment_method->get_payment_method_script_handles()
|
||||
);
|
||||
}
|
||||
|
||||
return array_unique( array_filter( $script_handles ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of all registered payment method script data, but only for active payment methods.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_all_registered_script_data() {
|
||||
$script_data = [];
|
||||
$payment_methods = $this->get_all_active_registered();
|
||||
|
||||
foreach ( $payment_methods as $payment_method ) {
|
||||
$script_data[ $payment_method->get_name() ] = $payment_method->get_payment_method_data();
|
||||
}
|
||||
|
||||
return array( 'paymentMethodData' => array_filter( $script_data ) );
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
namespace Automattic\WooCommerce\Blocks\Payments;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface;
|
||||
|
||||
interface PaymentMethodTypeInterface extends IntegrationInterface {
|
||||
/**
|
||||
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_active();
|
||||
|
||||
/**
|
||||
* Returns an array of script handles to enqueue for this payment method in
|
||||
* the frontend context
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_payment_method_script_handles();
|
||||
|
||||
/**
|
||||
* Returns an array of script handles to enqueue for this payment method in
|
||||
* the admin context
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_payment_method_script_handles_for_admin();
|
||||
|
||||
/**
|
||||
* An array of key, value pairs of data made available to payment methods
|
||||
* client side.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_data();
|
||||
|
||||
/**
|
||||
* Get array of supported features.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_supported_features();
|
||||
}
|
||||
Reference in New Issue
Block a user