From 54e5ed22e761ef8b45f4757c55ccc4bef1bce364 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Mon, 17 Oct 2022 00:17:35 +0200 Subject: [PATCH] Supply the Card Element instead of the Card from Stripe Payment Elements --- client/checkout/blocks/fields.js | 27 ++++++++++++++----- ...lass-wc-payments-blocks-payment-method.php | 15 +---------- ...-wc-payments-upe-blocks-payment-method.php | 5 ++-- includes/class-wc-payments.php | 9 +------ .../class-upe-payment-gateway.php | 3 +++ 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/client/checkout/blocks/fields.js b/client/checkout/blocks/fields.js index 08a0f08a808..d0c0f9e5d9a 100644 --- a/client/checkout/blocks/fields.js +++ b/client/checkout/blocks/fields.js @@ -7,6 +7,7 @@ import { CardElement, } from '@stripe/react-stripe-js'; import { useEffect, useState } from '@wordpress/element'; +import { getConfig } from 'utils/checkout'; /** * Internal dependencies @@ -30,6 +31,17 @@ const WCPayFields = ( { shouldSavePayment, } ) => { const [ errorMessage, setErrorMessage ] = useState( null ); + const testMode = getConfig( 'testMode' ); + const testCopy = ( +

+ Test mode: use the test VISA card 4242424242424242 + with any expiry date and CVC, or any test card numbers listed{ ' ' } + + here + + . +

+ ); // When it's time to process the payment, generate a Stripe payment method object. useEffect( @@ -86,12 +98,15 @@ const WCPayFields = ( { }; return ( -
- -
+ <> + { testMode ? testCopy : '' } +
+ +
+ ); }; diff --git a/includes/class-wc-payments-blocks-payment-method.php b/includes/class-wc-payments-blocks-payment-method.php index acc80df8aa7..b5fcf81fa35 100644 --- a/includes/class-wc-payments-blocks-payment-method.php +++ b/includes/class-wc-payments-blocks-payment-method.php @@ -83,19 +83,7 @@ public function get_payment_method_data() { ]; } - // return array_merge( - // [ - // 'title' => $this->gateway->get_option( 'title', '' ), - // 'description' => $this->gateway->get_option( 'description', '' ), - // 'is_admin' => is_admin(), // Used to display payment method preview in wp-admin. - // ], - // $platform_checkout_config, - // $this->gateway->get_payment_fields_js_config() - // ); -//harris TODO: revert this change after debugging - $config = $this->gateway->get_payment_fields_js_config(); - - $result = array_merge( + return array_merge( [ 'title' => $this->gateway->get_option( 'title', '' ), 'description' => $this->gateway->get_option( 'description', '' ), @@ -104,6 +92,5 @@ public function get_payment_method_data() { $platform_checkout_config, $this->gateway->get_payment_fields_js_config() ); - return $result; } } diff --git a/includes/class-wc-payments-upe-blocks-payment-method.php b/includes/class-wc-payments-upe-blocks-payment-method.php index 0a5ebcbd4c0..91466dbf875 100644 --- a/includes/class-wc-payments-upe-blocks-payment-method.php +++ b/includes/class-wc-payments-upe-blocks-payment-method.php @@ -15,6 +15,7 @@ class WC_Payments_UPE_Blocks_Payment_Method extends WC_Payments_Blocks_Payment_M * @return string[] A list of script handles. */ public function get_payment_method_script_handles() { + $classic_blocks_scripts = parent::get_payment_method_script_handles(); wp_enqueue_style( 'wc-blocks-checkout-style', plugins_url( 'dist/upe-blocks-checkout.css', WCPAY_PLUGIN_FILE ), @@ -31,7 +32,7 @@ public function get_payment_method_script_handles() { ); wp_register_script( - 'WCPAY_BLOCKS_CHECKOUT', + 'WCPAY_BLOCKS_UPE_CHECKOUT', plugins_url( 'dist/upe-blocks-checkout.js', WCPAY_PLUGIN_FILE ), [ 'stripe' ], '1.0.1', @@ -39,6 +40,6 @@ public function get_payment_method_script_handles() { ); wp_set_script_translations( 'WCPAY_BLOCKS_CHECKOUT', 'woocommerce-payments' ); - return [ 'WCPAY_BLOCKS_CHECKOUT' ]; + return array_merge( $classic_blocks_scripts, [ 'WCPAY_BLOCKS_UPE_CHECKOUT' ] ); } } diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index f90c19fa6b0..50b256d11b5 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -948,14 +948,7 @@ public static function register_checkout_gateway( $payment_method_registry ) { require_once __DIR__ . '/class-wc-payments-blocks-payment-method.php'; if ( WC_Payments_Features::is_upe_enabled() ) { require_once __DIR__ . '/class-wc-payments-upe-blocks-payment-method.php'; - require_once __DIR__ . '/class-wc-payments-upe-blocks-card-payment-method.php'; - require_once __DIR__ . '/class-wc-payments-upe-blocks-bancontact-payment-method.php'; - require_once __DIR__ . '/class-wc-payments-upe-blocks-sepa-payment-method.php'; - require_once __DIR__ . '/class-wc-payments-upe-blocks-giropay-payment-method.php'; - $payment_method_registry->register( new WC_Payments_UPE_Blocks_Card_Payment_Method() ); - $payment_method_registry->register( new WC_Payments_UPE_Blocks_Bancontact_Payment_Method() ); - $payment_method_registry->register( new WC_Payments_UPE_Blocks_Sepa_Payment_Method() ); - $payment_method_registry->register( new WC_Payments_UPE_Blocks_Giropay_Payment_Method() ); + $payment_method_registry->register( new WC_Payments_UPE_Blocks_Payment_Method() ); } else { $payment_method_registry->register( new WC_Payments_Blocks_Payment_Method() ); } diff --git a/includes/payment-methods/class-upe-payment-gateway.php b/includes/payment-methods/class-upe-payment-gateway.php index 6abb337aad0..f23adbfbced 100644 --- a/includes/payment-methods/class-upe-payment-gateway.php +++ b/includes/payment-methods/class-upe-payment-gateway.php @@ -1068,6 +1068,9 @@ private function get_enabled_payment_method_config() { $enabled_payment_methods = $this->get_payment_method_ids_enabled_at_checkout(); foreach ( $enabled_payment_methods as $payment_method_id ) { + if ( 'card' === $payment_method_id ) { + continue; + } $payment_method = $this->wc_payments_get_payment_method_by_id( $payment_method_id ); $settings[ $payment_method_id ] = [ 'isReusable' => $payment_method->is_reusable(),