Add ApplePay preview in admin settings.

This commit is contained in:
Pedro Silva 2023-11-03 10:30:31 +00:00
parent eb956d9db6
commit 118e49cfde
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
10 changed files with 343 additions and 19 deletions

View file

@ -89,6 +89,8 @@ class ApplepayModule implements ModuleInterface {
$module->render_buttons( $c, $apple_payment_method );
$apple_payment_method->bootstrap_ajax_request();
$module->load_admin_assets( $c, $apple_payment_method );
}
);
@ -180,6 +182,43 @@ class ApplepayModule implements ModuleInterface {
);
}
/**
* Registers and enqueues the assets.
*
* @param ContainerInterface $c The container.
* @param ApplePayButton $button The button.
* @return void
*/
public function load_admin_assets( ContainerInterface $c, ApplePayButton $button ): void {
// Enqueue backend scripts.
add_action(
'admin_enqueue_scripts',
static function () use ( $c, $button ) {
if ( ! is_admin() ) {
return;
}
/**
* Should add this to the ButtonInterface.
*
* @psalm-suppress UndefinedInterfaceMethod
*/
$button->enqueue_admin();
}
);
// Adds ApplePay component to the backend button preview settings.
add_action(
'woocommerce_paypal_payments_admin_gateway_settings',
function( array $settings ) use ( $c ): array {
if ( is_array( $settings['components'] ) ) {
$settings['components'][] = 'applepay';
}
return $settings;
}
);
}
/**
* Renders the Apple Pay buttons in the enabled places.
*