Skip to content

Commit a59a54d

Browse files
authored
Removing the payment method customization feature (#4452)
* Removing the payment method customization feature * Removing additional files * Deprecating backend methods * Changelog and readme entries * Removing backend unit tests * Removing reading of the custom title and description from the customer-facing methods * Fix tests * Fix tests * Removing the rest endpoint * Removing indivisual payment method settings test * Fix tests
1 parent 0f24715 commit a59a54d

24 files changed

+33
-1110
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.6.0 - xxxx-xx-xx =
4+
* Update - Removes the customization of individual payment method titles and descriptions
45
* Fix - Fixes some inconsistencies related to the Optimized Checkout feature and improves its unit tests
56
* Add - Introduces a new marketing note to promote BNPLs (Buy Now Pay Later) payment methods (Klarna and Affirm) on WooCommerce admin home page
67
* Fix - Fixes some inconsistencies related to the Optimized Checkout feature and improves its unit tests

client/data/settings/__tests__/actions.js

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
updateIsSavingSettings,
77
saveOrderedPaymentMethodIds,
88
updateIsSavingOrderedPaymentMethodIds,
9-
saveIndividualPaymentMethodSettings,
10-
updateIsCustomizingPaymentMethod,
119
} from '../actions';
1210
import {
1311
PAYMENT_METHOD_CARD,
@@ -132,121 +130,6 @@ describe( 'Settings actions tests', () => {
132130
} );
133131
} );
134132

135-
describe( 'saveIndividualPaymentMethodSettings()', () => {
136-
const paymentMethodSettingsMock = {
137-
method: 'foo',
138-
isEnabled: true,
139-
name: 'bar',
140-
description: 'baz',
141-
expiration: 123,
142-
};
143-
144-
beforeEach( () => {
145-
const noticesDispatch = {
146-
createErrorNotice: jest.fn(),
147-
};
148-
149-
apiFetch.mockImplementation( () => {} );
150-
dispatch.mockImplementation( ( storeName ) => {
151-
if ( storeName === 'core/notices' ) {
152-
return noticesDispatch;
153-
}
154-
155-
return { invalidateResolutionForStoreSelector: () => null };
156-
} );
157-
} );
158-
159-
test( 'makes POST request with payment method settings data', () => {
160-
apiFetch.mockReturnValue( 'api response' );
161-
162-
const yielded = [
163-
...saveIndividualPaymentMethodSettings(
164-
paymentMethodSettingsMock
165-
),
166-
];
167-
168-
expect( apiFetch ).toHaveBeenCalledWith( {
169-
method: 'post',
170-
path: '/wc/v3/wc_stripe/settings/payment_method',
171-
data: {
172-
is_enabled: paymentMethodSettingsMock.isEnabled,
173-
payment_method_id: paymentMethodSettingsMock.method,
174-
title: paymentMethodSettingsMock.name,
175-
description: paymentMethodSettingsMock.description,
176-
expiration: paymentMethodSettingsMock.expiration,
177-
},
178-
} );
179-
expect( yielded ).toContainEqual( 'api response' );
180-
} );
181-
182-
test( 'before saving sets isCustomizingPaymentMethod to true, and after - to false', () => {
183-
apiFetch.mockReturnValue( 'api request' );
184-
185-
const yielded = [
186-
...saveIndividualPaymentMethodSettings(
187-
paymentMethodSettingsMock
188-
),
189-
];
190-
191-
const apiRequestIndex = yielded.indexOf( 'api request' );
192-
193-
const isCustomizingStartIndex = findIndex(
194-
yielded,
195-
updateIsCustomizingPaymentMethod( true, null )
196-
);
197-
198-
const isCustomizingEndIndex = findIndex(
199-
yielded,
200-
updateIsCustomizingPaymentMethod( false, null )
201-
);
202-
203-
expect( apiRequestIndex ).not.toEqual( -1 );
204-
expect( isCustomizingStartIndex ).toBeLessThan( apiRequestIndex );
205-
expect( isCustomizingEndIndex ).toBeGreaterThan( apiRequestIndex );
206-
} );
207-
208-
test( 'displays error notice if error is thrown', () => {
209-
const saveGenerator = saveIndividualPaymentMethodSettings(
210-
paymentMethodSettingsMock
211-
);
212-
213-
apiFetch.mockImplementation( () => {
214-
saveGenerator.throw( 'Some error' );
215-
} );
216-
217-
// eslint-disable-next-line no-unused-expressions
218-
[ ...saveGenerator ];
219-
220-
expect(
221-
dispatch( 'core/notices' ).createErrorNotice
222-
).toHaveBeenCalledWith( 'Error saving payment method.' );
223-
} );
224-
225-
test( 'after throwing error, isCustomizingPaymentMethod is reset', () => {
226-
const saveGenerator = saveIndividualPaymentMethodSettings(
227-
paymentMethodSettingsMock
228-
);
229-
230-
apiFetch.mockImplementation( () => {
231-
saveGenerator.throw( 'Some error' );
232-
} );
233-
234-
const yielded = [ ...saveGenerator ];
235-
236-
expect(
237-
dispatch( 'core/notices' ).createErrorNotice
238-
).toHaveBeenCalled();
239-
expect( yielded ).toEqual(
240-
expect.arrayContaining( [
241-
expect.objectContaining( {
242-
type: 'SET_IS_CUSTOMIZING_PAYMENT_METHOD',
243-
isCustomizingPaymentMethod: false,
244-
} ),
245-
] )
246-
);
247-
} );
248-
} );
249-
250133
describe( 'saveOrderedPaymentMethodIds()', () => {
251134
beforeEach( () => {
252135
const noticesDispatch = {

client/data/settings/__tests__/hooks.js

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
useGetAvailablePaymentMethodIds,
66
useSettings,
77
useGetOrderedPaymentMethodIds,
8-
useCustomizePaymentMethodSettings,
98
usePaymentRequestEnabledSettings,
109
usePaymentRequestButtonTheme,
1110
usePaymentRequestLocations,
@@ -131,65 +130,6 @@ describe( 'Settings hooks tests', () => {
131130
);
132131
} );
133132

134-
describe( 'useCustomizePaymentMethodSettings()', () => {
135-
beforeEach( () => {
136-
actions = {
137-
saveIndividualPaymentMethodSettings: jest.fn(),
138-
updateSettingsValues: jest.fn(),
139-
};
140-
141-
selectors = {
142-
getIndividualPaymentMethodSettings: jest.fn( () => ( {
143-
eps: {
144-
title: 'EPS',
145-
description: 'Pay with EPS',
146-
},
147-
giropay: {
148-
title: 'Giropay',
149-
description: 'Pay with Giropay',
150-
},
151-
} ) ),
152-
isCustomizingPaymentMethod: jest.fn(),
153-
};
154-
} );
155-
156-
test( 'returns individula payment method settings from selector', () => {
157-
const { result } = renderHook( useCustomizePaymentMethodSettings );
158-
const {
159-
individualPaymentMethodSettings,
160-
customizePaymentMethod,
161-
} = result.current;
162-
163-
expect( individualPaymentMethodSettings ).toEqual( {
164-
eps: {
165-
title: 'EPS',
166-
description: 'Pay with EPS',
167-
},
168-
giropay: {
169-
title: 'Giropay',
170-
description: 'Pay with Giropay',
171-
},
172-
} );
173-
174-
customizePaymentMethod( PAYMENT_METHOD_GIROPAY, true, {
175-
giropay: {
176-
name: 'Giropay',
177-
description: 'Pay with Giropay',
178-
expiration: '10',
179-
},
180-
} );
181-
expect(
182-
actions.saveIndividualPaymentMethodSettings
183-
).toHaveBeenCalledWith( {
184-
isEnabled: true,
185-
method: PAYMENT_METHOD_GIROPAY,
186-
name: 'Giropay',
187-
description: 'Pay with Giropay',
188-
expiration: '10',
189-
} );
190-
} );
191-
} );
192-
193133
describe( 'useGetOrderedPaymentMethodIds()', () => {
194134
beforeEach( () => {
195135
actions = {

client/data/settings/__tests__/reducer.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
updateIsSavingSettings,
55
updateSettingsValues,
66
updateIsSavingOrderedPaymentMethodIds,
7-
updateIsCustomizingPaymentMethod,
87
} from '../actions';
98

109
describe( 'Settings reducer tests', () => {
@@ -187,42 +186,6 @@ describe( 'Settings reducer tests', () => {
187186
} );
188187
} );
189188

190-
describe( 'SET_IS_CUSTOMIZING_PAYMENT_METHOD', () => {
191-
test( 'toggles isCustomizingPaymentMethod', () => {
192-
const oldState = {
193-
isCustomizingPaymentMethod: false,
194-
};
195-
196-
const state = reducer(
197-
oldState,
198-
updateIsCustomizingPaymentMethod( true )
199-
);
200-
201-
expect( state.isCustomizingPaymentMethod ).toBeTruthy();
202-
} );
203-
204-
test( 'leaves other fields unchanged', () => {
205-
const oldState = {
206-
foo: 'bar',
207-
isSaving: false,
208-
savingError: {},
209-
isCustomizingPaymentMethod: false,
210-
};
211-
212-
const state = reducer(
213-
oldState,
214-
updateIsCustomizingPaymentMethod( true )
215-
);
216-
217-
expect( state ).toEqual( {
218-
foo: 'bar',
219-
savingError: {},
220-
isSaving: false,
221-
isCustomizingPaymentMethod: true,
222-
} );
223-
} );
224-
} );
225-
226189
describe( 'SET_IS_SAVING_ORDERED_PAYMENT_METHOD_IDS', () => {
227190
test( 'toggles isSavingOrderedPaymentMethodIds', () => {
228191
const oldState = {

client/data/settings/__tests__/selectors.js

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import {
33
isSavingSettings,
44
getOrderedPaymentMethodIds,
55
isSavingOrderedPaymentMethodIds,
6-
getIndividualPaymentMethodSettings,
7-
isCustomizingPaymentMethod,
86
} from '../selectors';
97
import {
108
PAYMENT_METHOD_CARD,
@@ -53,67 +51,6 @@ describe( 'Settings selectors tests', () => {
5351
);
5452
} );
5553

56-
describe( 'getIndividualPaymentMethodSettings()', () => {
57-
test( 'returns the value of state.settings.data.individual_payment_method_settings', () => {
58-
const state = {
59-
settings: {
60-
data: {
61-
foo: 'bar',
62-
individual_payment_method_settings: {
63-
eps: {
64-
title: 'EPS',
65-
description: 'Pay with EPS',
66-
},
67-
giropay: {
68-
title: 'Giropay',
69-
description: 'Pay with Giropay',
70-
},
71-
},
72-
},
73-
},
74-
};
75-
76-
expect( getIndividualPaymentMethodSettings( state ) ).toEqual( {
77-
eps: {
78-
title: 'EPS',
79-
description: 'Pay with EPS',
80-
},
81-
giropay: {
82-
title: 'Giropay',
83-
description: 'Pay with Giropay',
84-
},
85-
} );
86-
} );
87-
88-
test.each( [ [ undefined ], [ {} ], [ { settings: {} } ] ] )(
89-
'returns {} if key is missing (tested state: %j)',
90-
( state ) => {
91-
expect( getIndividualPaymentMethodSettings( state ) ).toEqual(
92-
{}
93-
);
94-
}
95-
);
96-
} );
97-
98-
describe( 'isCustomizingPaymentMethod()', () => {
99-
test( 'returns the value of state.settings.isCustomizingPaymentMethod', () => {
100-
const state = {
101-
settings: {
102-
isCustomizingPaymentMethod: true,
103-
},
104-
};
105-
106-
expect( isCustomizingPaymentMethod( state ) ).toBeTruthy();
107-
} );
108-
109-
test.each( [ [ undefined ], [ {} ], [ { settings: {} } ] ] )(
110-
'returns false if missing (tested state: %j)',
111-
( state ) => {
112-
expect( isCustomizingPaymentMethod( state ) ).toBeFalsy();
113-
}
114-
);
115-
} );
116-
11754
describe( 'getOrderedPaymentMethodIds()', () => {
11855
test( 'returns the value of state.settings.data', () => {
11956
const state = {

client/data/settings/actions.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ export function updateIsSavingOrderedPaymentMethodIds(
3535
};
3636
}
3737

38-
export function updateIsCustomizingPaymentMethod( isCustomizingPaymentMethod ) {
39-
return {
40-
type: ACTION_TYPES.SET_IS_CUSTOMIZING_PAYMENT_METHOD,
41-
isCustomizingPaymentMethod,
42-
};
43-
}
44-
4538
export function* saveSettings() {
4639
let error = null;
4740
try {
@@ -103,33 +96,3 @@ export function* saveOrderedPaymentMethodIds() {
10396
yield updateIsSavingOrderedPaymentMethodIds( false );
10497
}
10598
}
106-
107-
export function* saveIndividualPaymentMethodSettings(
108-
paymentMethodData = null
109-
) {
110-
if ( ! paymentMethodData ) {
111-
return;
112-
}
113-
114-
try {
115-
yield updateIsCustomizingPaymentMethod( true );
116-
117-
yield apiFetch( {
118-
path: `${ NAMESPACE }/settings/payment_method`,
119-
method: 'post',
120-
data: {
121-
is_enabled: paymentMethodData.isEnabled,
122-
payment_method_id: paymentMethodData.method,
123-
title: paymentMethodData.name,
124-
description: paymentMethodData.description,
125-
expiration: paymentMethodData.expiration,
126-
},
127-
} );
128-
} catch ( e ) {
129-
yield dispatch( 'core/notices' ).createErrorNotice(
130-
__( 'Error saving payment method.', 'woocommerce-gateway-stripe' )
131-
);
132-
} finally {
133-
yield updateIsCustomizingPaymentMethod( false );
134-
}
135-
}

0 commit comments

Comments
 (0)