swissChili | f0cbdc3 | 2023-01-05 17:21:38 -0500 | [diff] [blame] | 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | /** |
| 7 | * Admin page for UPE Customize Express Checkouts. |
| 8 | * |
| 9 | * @since 5.4.1 |
| 10 | */ |
| 11 | class WC_Stripe_Payment_Requests_Controller { |
| 12 | public function __construct() { |
| 13 | add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] ); |
| 14 | add_action( 'wc_stripe_gateway_admin_options_wrapper', [ $this, 'admin_options' ] ); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Load admin scripts. |
| 19 | */ |
| 20 | public function admin_scripts() { |
| 21 | // Webpack generates an assets file containing a dependencies array for our built JS file. |
| 22 | $script_asset_path = WC_STRIPE_PLUGIN_PATH . '/build/payment_requests_settings.asset.php'; |
| 23 | $asset_metadata = file_exists( $script_asset_path ) |
| 24 | ? require $script_asset_path |
| 25 | : [ |
| 26 | 'dependencies' => [], |
| 27 | 'version' => WC_STRIPE_VERSION, |
| 28 | ]; |
| 29 | wp_register_script( |
| 30 | 'wc-stripe-payment-request-settings', |
| 31 | plugins_url( 'build/payment_requests_settings.js', WC_STRIPE_MAIN_FILE ), |
| 32 | $asset_metadata['dependencies'], |
| 33 | $asset_metadata['version'], |
| 34 | true |
| 35 | ); |
| 36 | wp_set_script_translations( |
| 37 | 'wc-stripe-payment-request-settings', |
| 38 | 'woocommerce-gateway-stripe' |
| 39 | ); |
| 40 | wp_enqueue_script( 'wc-stripe-payment-request-settings' ); |
| 41 | |
| 42 | wp_register_style( |
| 43 | 'wc-stripe-payment-request-settings', |
| 44 | plugins_url( 'build/payment_requests_settings.css', WC_STRIPE_MAIN_FILE ), |
| 45 | [ 'wc-components' ], |
| 46 | $asset_metadata['version'] |
| 47 | ); |
| 48 | wp_enqueue_style( 'wc-stripe-payment-request-settings' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Prints the admin options for the gateway. |
| 53 | * Remove this action once we're fully migrated to UPE and move the wrapper in the `admin_options` method of the UPE gateway. |
| 54 | */ |
| 55 | public function admin_options() { |
| 56 | global $hide_save_button; |
| 57 | $hide_save_button = true; |
| 58 | echo '<h2>' . __( 'Customize express checkouts', 'woocommerce-gateway-stripe' ); |
| 59 | wc_back_link( __( 'Return to Stripe', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
| 60 | echo '</h2>'; |
| 61 | echo '<div class="wrap"><div id="wc-stripe-payment-request-settings-container"></div></div>'; |
| 62 | } |
| 63 | } |