Skip to content

Commit 23852c7

Browse files
authored
Removing card requirement for OC (#4573)
* Removing card requirement for OC * Backend changes * Backend changes * Changelog and readme entries * Fix tests * Fix tests * unit test * Fix tests * Fix shortcode checkout methods display * Removing unnecessary condition * Condition is actually necessary * Removing disabledButChecked prop and related code * Removing the required for OC pill and related files * Hide OC container when there are no methods available * Fix merge * Fix tests * Fix express methods not available
1 parent d063056 commit 23852c7

File tree

16 files changed

+134
-222
lines changed

16 files changed

+134
-222
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.9.0 - xxxx-xx-xx =
4+
* Fix - Removes the credit card payment method requirement for the Optimized Checkout feature
45
* Fix - Payment method test instructions not showing up for the Optimized Checkout payment element
56
* Add - Includes a new notice to highlight the Optimized Checkout feature above the payment methods list in the Stripe settings page
67
* Update - Increases the default font size for the Optimized Checkout payment element to match the rest of the checkout form

client/blocks/upe/index.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
import {
66
PAYMENT_METHOD_AFFIRM,
77
PAYMENT_METHOD_AMAZON_PAY,
8-
PAYMENT_METHOD_CARD,
98
PAYMENT_METHOD_GIROPAY,
109
PAYMENT_METHOD_KLARNA,
1110
PAYMENT_METHOD_LINK,
@@ -40,32 +39,25 @@ const api = new WCStripeAPI(
4039
const paymentMethodsConfig =
4140
getBlocksConfiguration()?.paymentMethodsConfig ?? {};
4241

43-
// Register UPE Elements.
44-
if ( getBlocksConfiguration()?.isOCEnabled ) {
45-
registerPaymentMethod(
46-
upeElement( PAYMENT_METHOD_CARD, api, paymentMethodsConfig.card )
47-
);
48-
} else {
49-
const methodsToFilter = [
50-
PAYMENT_METHOD_AMAZON_PAY,
51-
PAYMENT_METHOD_LINK,
52-
PAYMENT_METHOD_GIROPAY, // Skip giropay as it was deprecated by Jun, 30th 2024.
53-
];
54-
55-
// Filter out some BNPLs when other official extensions are present.
56-
if ( getBlocksConfiguration()?.hasAffirmGatewayPlugin ) {
57-
methodsToFilter.push( PAYMENT_METHOD_AFFIRM );
58-
}
59-
if ( getBlocksConfiguration()?.hasKlarnaGatewayPlugin ) {
60-
methodsToFilter.push( PAYMENT_METHOD_KLARNA );
61-
}
42+
const methodsToFilter = [
43+
PAYMENT_METHOD_AMAZON_PAY,
44+
PAYMENT_METHOD_LINK,
45+
PAYMENT_METHOD_GIROPAY, // Skip giropay as it was deprecated by Jun, 30th 2024.
46+
];
6247

63-
Object.entries( paymentMethodsConfig )
64-
.filter( ( [ method ] ) => ! methodsToFilter.includes( method ) )
65-
.forEach( ( [ method, config ] ) => {
66-
registerPaymentMethod( upeElement( method, api, config ) );
67-
} );
48+
// Filter out some BNPLs when other official extensions are present.
49+
if ( getBlocksConfiguration()?.hasAffirmGatewayPlugin ) {
50+
methodsToFilter.push( PAYMENT_METHOD_AFFIRM );
6851
}
52+
if ( getBlocksConfiguration()?.hasKlarnaGatewayPlugin ) {
53+
methodsToFilter.push( PAYMENT_METHOD_KLARNA );
54+
}
55+
56+
Object.entries( paymentMethodsConfig )
57+
.filter( ( [ method ] ) => ! methodsToFilter.includes( method ) )
58+
.forEach( ( [ method, config ] ) => {
59+
registerPaymentMethod( upeElement( method, api, config ) );
60+
} );
6961

7062
if ( getBlocksConfiguration()?.isECEEnabled ) {
7163
// Register Express Checkout Elements.

client/blocks/upe/upe-element.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
PAYMENT_METHOD_AFTERPAY_CLEARPAY,
77
PAYMENT_METHOD_CLEARPAY,
88
PAYMENT_METHOD_BACS,
9+
PAYMENT_METHOD_CARD,
10+
EXPRESS_PAYMENT_METHODS,
911
} from 'wcstripe/stripe-utils/constants';
1012
import { getBlocksConfiguration } from 'wcstripe/blocks/utils';
1113
import Icons from 'wcstripe/payment-method-icons';
@@ -78,6 +80,18 @@ export const upeElement = ( paymentMethod, api, upeConfig ) => {
7880
return false;
7981
}
8082

83+
const nonExpressPaymentMethods = upeConfig?.enabledPaymentMethods.filter(
84+
( method ) => ! EXPRESS_PAYMENT_METHODS.includes( method )
85+
);
86+
87+
if (
88+
paymentMethod === PAYMENT_METHOD_CARD &&
89+
getBlocksConfiguration()?.isOCEnabled &&
90+
nonExpressPaymentMethods.length === 0
91+
) {
92+
return false;
93+
}
94+
8195
return isAvailableInTheCountry && !! api.getStripe();
8296
},
8397
// see .wc-block-checkout__payment-method styles in blocks/style.scss

client/components/payment-method-required-for-oc-pill/__tests__/index.test.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

client/components/payment-method-required-for-oc-pill/index.js

Lines changed: 0 additions & 87 deletions
This file was deleted.

client/settings/general-settings-section/payment-method-checkbox.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const PaymentMethodCheckbox = ( {
3333
label,
3434
isAllowingManualCapture,
3535
disabled,
36-
disabledButChecked,
3736
} ) => {
3837
const [ isManualCaptureEnabled ] = useManualCapture();
3938
const [ isConfirmationModalOpen, setIsConfirmationModalOpen ] = useState(
@@ -45,12 +44,10 @@ const PaymentMethodCheckbox = ( {
4544
] = useEnabledPaymentMethodIds();
4645
const [ , setIsStripeEnabled ] = useIsStripeEnabled();
4746
const { isUpeEnabled } = useContext( UpeToggleContext );
48-
const checked =
49-
! disabled &&
50-
( disabledButChecked || enabledPaymentMethods.includes( id ) );
47+
const checked = ! disabled && enabledPaymentMethods.includes( id );
5148

5249
const handleCheckboxChange = ( hasBeenChecked ) => {
53-
if ( disabled || disabledButChecked ) {
50+
if ( disabled ) {
5451
return;
5552
}
5653
if ( ! hasBeenChecked ) {
@@ -113,7 +110,7 @@ const PaymentMethodCheckbox = ( {
113110
label={ <VisuallyHidden>{ label }</VisuallyHidden> }
114111
onChange={ handleCheckboxChange }
115112
checked={ checked }
116-
disabled={ disabled || disabledButChecked }
113+
disabled={ disabled }
117114
/>
118115
) }
119116
{ isConfirmationModalOpen && (

client/settings/general-settings-section/payment-method-description.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import RecurringPaymentIcon from '../../components/recurring-payment-icon';
55
import PaymentMethodCapabilityStatusPill from 'wcstripe/components/payment-method-capability-status-pill';
66
import PaymentMethodDeprecationPill from 'wcstripe/components/payment-method-deprecation-pill';
77
import PaymentMethodUnavailableDueConflictPill from 'wcstripe/components/payment-method-unavailable-due-conflict-pill';
8-
import PaymentMethodRequiredForOCPill from 'wcstripe/components/payment-method-required-for-oc-pill';
98

109
const Wrapper = styled.div`
1110
display: flex;
@@ -75,10 +74,6 @@ const PaymentMethodDescription = ( {
7574
id={ id }
7675
label={ label }
7776
/>
78-
<PaymentMethodRequiredForOCPill
79-
id={ id }
80-
label={ label }
81-
/>
8277
</>
8378
) }
8479
</LabelWrapper>

client/settings/general-settings-section/payment-method.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import interpolateComponents from 'interpolate-components';
77
import PaymentMethodsMap from '../../payment-methods-map';
88
import PaymentMethodDescription from './payment-method-description';
99
import PaymentMethodCheckbox from './payment-method-checkbox';
10-
import { useIsOCEnabled, useManualCapture } from 'wcstripe/data';
10+
import { useManualCapture } from 'wcstripe/data';
1111
import {
1212
PAYMENT_METHOD_AFFIRM,
1313
PAYMENT_METHOD_AFTERPAY_CLEARPAY,
@@ -105,7 +105,6 @@ const StyledFees = styled( PaymentMethodFeesPill )`
105105
`;
106106

107107
const PaymentMethod = ( { method, data } ) => {
108-
const [ isOCEnabled ] = useIsOCEnabled();
109108
const [ isManualCaptureEnabled ] = useManualCapture();
110109
const paymentMethodCurrencies = usePaymentMethodCurrencies( method );
111110

@@ -138,8 +137,6 @@ const PaymentMethod = ( { method, data } ) => {
138137
// eslint-disable-next-line camelcase
139138
wc_stripe_settings_params.has_klarna_gateway_plugin );
140139

141-
const isDisabledButChecked = PAYMENT_METHOD_CARD === method && isOCEnabled;
142-
143140
return (
144141
<div key={ method }>
145142
<ListElement
@@ -154,7 +151,6 @@ const PaymentMethod = ( { method, data } ) => {
154151
label={ label }
155152
isAllowingManualCapture={ isAllowingManualCapture }
156153
disabled={ deprecated || isDisabled }
157-
disabledButChecked={ isDisabledButChecked }
158154
/>
159155
<PaymentMethodWrapper>
160156
<PaymentMethodDescription

client/stripe-utils/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ export const EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY = 'applePay';
132132
export const EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY = 'googlePay';
133133
export const EXPRESS_PAYMENT_METHOD_SETTING_LINK = 'link';
134134

135+
/**
136+
* List of express payment methods
137+
*/
138+
export const EXPRESS_PAYMENT_METHODS = [
139+
EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY,
140+
EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY,
141+
EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY,
142+
EXPRESS_PAYMENT_METHOD_SETTING_LINK,
143+
];
144+
135145
/**
136146
* List of payment methods that are not recurring
137147
*/

includes/class-wc-stripe.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,7 @@ public function initialize_status_page() {
865865

866866
/**
867867
* Toggle payment methods that should be enabled/disabled, e.g. unreleased,
868-
* BNPLs when other official plugins are active,
869-
* cards when the Optimized Checkout is enabled, etc.
868+
* BNPLs when other official plugins are active, etc.
870869
*
871870
* @return void
872871
*/
@@ -877,7 +876,6 @@ public function maybe_toggle_payment_methods() {
877876
}
878877

879878
$payment_method_ids_to_disable = [];
880-
$payment_method_ids_to_enable = [];
881879
$enabled_payment_methods = $gateway->get_upe_enabled_payment_method_ids();
882880

883881
// Check for BNPLs that should be deactivated.
@@ -892,22 +890,10 @@ public function maybe_toggle_payment_methods() {
892890
$this->maybe_deactivate_amazon_pay( $enabled_payment_methods )
893891
);
894892

895-
// Check if cards should be activated.
896-
// TODO: Remove this once card is not a requirement for the Optimized Checkout.
897-
if ( $gateway->is_oc_enabled()
898-
&& ! in_array( WC_Stripe_Payment_Methods::CARD, $enabled_payment_methods, true ) ) {
899-
$payment_method_ids_to_enable[] = WC_Stripe_Payment_Methods::CARD;
900-
}
901-
902-
if ( [] === $payment_method_ids_to_disable && [] === $payment_method_ids_to_enable ) {
893+
if ( [] === $payment_method_ids_to_disable ) {
903894
return;
904895
}
905896

906-
$enabled_payment_methods = array_merge(
907-
$enabled_payment_methods,
908-
$payment_method_ids_to_enable
909-
);
910-
911897
$gateway->update_enabled_payment_methods(
912898
array_diff( $enabled_payment_methods, $payment_method_ids_to_disable )
913899
);

0 commit comments

Comments
 (0)