Skip to content

Commit 6fc5bfe

Browse files
authored
WooPay express checkout button on blocks checkout (#5139)
1 parent d1a9910 commit 6fc5bfe

File tree

7 files changed

+57
-6
lines changed

7 files changed

+57
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: add
3+
4+
Added support for a WooPay express checkout button on checkout blocks. This feature is currently behind a feature flag and is not yet publicly available.

client/checkout/blocks/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import request from '../utils/request';
2222
import enqueueFraudScripts from 'fraud-scripts';
2323
import paymentRequestPaymentMethod from '../../payment-request/blocks';
2424
import { handlePlatformCheckoutEmailInput } from '../platform-checkout/email-input-iframe';
25+
import wooPayExpressCheckoutPaymentMethod from '../platform-checkout/express-button/woopay-express-checkout-payment-method';
2526

2627
// Create an API object, which will be used throughout the checkout.
2728
const api = new WCPayAPI(
@@ -52,12 +53,16 @@ registerPaymentMethod( {
5253

5354
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) );
5455

55-
// If platform checkout is enabled and this is the checkout page.
56-
if (
57-
getConfig( 'isPlatformCheckoutEnabled' ) &&
58-
document.querySelector( '[data-block-name="woocommerce/checkout"]' )
59-
) {
60-
handlePlatformCheckoutEmailInput( '#email', api, true );
56+
if ( getConfig( 'isPlatformCheckoutEnabled' ) ) {
57+
// Call handlePlatformCheckoutEmailInput if platform checkout is enabled and this is the checkout page.
58+
if (
59+
document.querySelector( '[data-block-name="woocommerce/checkout"]' )
60+
) {
61+
handlePlatformCheckoutEmailInput( '#email', api, true );
62+
}
63+
if ( getConfig( 'isWoopayExpressCheckoutEnabled' ) ) {
64+
registerExpressPaymentMethod( wooPayExpressCheckoutPaymentMethod() );
65+
}
6166
}
6267

6368
window.addEventListener( 'load', () => {

client/checkout/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ export const PAYMENT_METHOD_NAME_SOFORT = 'woocommerce_payments_sofort';
66
export const PAYMENT_METHOD_NAME_UPE = 'woocommerce_payments_upe';
77
export const PAYMENT_METHOD_NAME_PAYMENT_REQUEST =
88
'woocommerce_payments_payment_request';
9+
export const PAYMENT_METHOD_NAME_WOOPAY_EXPRESS_CHECKOUT =
10+
'woocommerce_payments_woopay_express_checkout';
911
export const WC_STORE_CART = 'wc/store/cart';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* global wcpayWooPayExpressParams */
2+
/**
3+
* Internal dependencies
4+
*/
5+
import { PAYMENT_METHOD_NAME_WOOPAY_EXPRESS_CHECKOUT } from '../../constants';
6+
import { WoopayExpressCheckoutButton } from './woopay-express-checkout-button';
7+
import { getConfig } from '../../../utils/checkout';
8+
9+
const wooPayExpressCheckoutPaymentMethod = () => ( {
10+
name: PAYMENT_METHOD_NAME_WOOPAY_EXPRESS_CHECKOUT,
11+
content: (
12+
<WoopayExpressCheckoutButton
13+
buttonSettings={ wcpayWooPayExpressParams?.button }
14+
/>
15+
),
16+
edit: (
17+
<WoopayExpressCheckoutButton
18+
buttonSettings={ wcpayWooPayExpressParams?.button }
19+
isPreview={ true }
20+
/>
21+
),
22+
canMakePayment: () => true,
23+
paymentMethodId: PAYMENT_METHOD_NAME_WOOPAY_EXPRESS_CHECKOUT,
24+
supports: {
25+
features: getConfig( 'features' ),
26+
},
27+
} );
28+
29+
export default wooPayExpressCheckoutPaymentMethod;

client/checkout/platform-checkout/style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
display: flex;
139139
align-items: center;
140140
justify-content: center;
141+
white-space: nowrap;
141142

142143
svg {
143144
fill: $studio-woocommerce-purple-60;

includes/class-wc-payments-checkout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function get_payment_fields_js_config() {
115115
'isUPEEnabled' => WC_Payments_Features::is_upe_enabled(),
116116
'isSavedCardsEnabled' => $this->gateway->is_saved_cards_enabled(),
117117
'isPlatformCheckoutEnabled' => $this->platform_checkout_util->should_enable_platform_checkout( $this->gateway ),
118+
'isWoopayExpressCheckoutEnabled' => $this->platform_checkout_util->is_woopay_express_checkout_enabled(),
118119
'isClientEncryptionEnabled' => WC_Payments_Features::is_client_secret_encryption_enabled(),
119120
'platformCheckoutHost' => defined( 'PLATFORM_CHECKOUT_FRONTEND_HOST' ) ? PLATFORM_CHECKOUT_FRONTEND_HOST : 'https://pay.woo.com',
120121
'platformTrackerNonce' => wp_create_nonce( 'platform_tracks_nonce' ),

includes/platform-checkout/class-platform-checkout-utilities.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public function should_enable_platform_checkout( $gateway ) {
3030
return $is_platform_checkout_eligible && $is_platform_checkout_enabled;
3131
}
3232

33+
/**
34+
* Check conditions to determine if woopay express checkout is enabled.
35+
*
36+
* @return boolean
37+
*/
38+
public function is_woopay_express_checkout_enabled() {
39+
return WC_Payments_Features::is_woopay_express_checkout_enabled(); // Feature flag.
40+
}
41+
3342
/**
3443
* Generates a hash based on the store's blog token, merchant ID, and the time step window.
3544
*

0 commit comments

Comments
 (0)