Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit e2b559d

Browse files
Alex Floriscagithub-actions[bot]
andauthored
Move payment utils and delete orderPaymentMethods (#7679)
* Moved all payment utils functions in a utils folder * Delete as it's not being used * bot: update checkstyle.xml * bot: update checkstyle.xml * Fix TS error * bot: update checkstyle.xml Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 6dccf6f commit e2b559d

File tree

9 files changed

+22
-81
lines changed

9 files changed

+22
-81
lines changed

assets/js/data/payment/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
* Internal dependencies
1111
*/
1212
import { ACTION_TYPES } from './action-types';
13-
import { checkPaymentMethodsCanPay } from './check-payment-methods';
14-
import { setDefaultPaymentMethod } from './set-default-payment-method';
13+
import { checkPaymentMethodsCanPay } from './utils/check-payment-methods';
14+
import { setDefaultPaymentMethod } from './utils/set-default-payment-method';
1515

1616
// `Thunks are functions that can be dispatched, similar to actions creators
1717
export * from './thunks';

assets/js/data/payment/selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import deprecated from '@wordpress/deprecated';
88
* Internal dependencies
99
*/
1010
import { PaymentMethodDataState } from './default-state';
11-
import { filterActiveSavedPaymentMethods } from './utils';
11+
import { filterActiveSavedPaymentMethods } from './utils/filter-active-saved-payment-methods';
1212
import { STATUS as PAYMENT_STATUS } from './constants';
1313

1414
export const isPaymentPristine = ( state: PaymentMethodDataState ) =>

assets/js/data/payment/test/actions.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Internal dependencies
33
*/
4-
import * as setDefaultPaymentMethodFunctions from '../set-default-payment-method';
4+
import { setDefaultPaymentMethod as setDefaultPaymentMethodOriginal } from '../utils/set-default-payment-method';
55
import { PAYMENT_STORE_KEY } from '..';
66
import { PlainPaymentMethods } from '../../../types';
77

88
const originalDispatch = jest.requireActual( '@wordpress/data' ).dispatch;
99

10-
jest.mock( '../set-default-payment-method', () => ( {
10+
jest.mock( '../utils/set-default-payment-method', () => ( {
1111
setDefaultPaymentMethod: jest.fn(),
1212
} ) );
1313

@@ -28,9 +28,7 @@ describe( 'payment data store actions', () => {
2828
Object.keys( paymentMethods )[ 0 ]
2929
);
3030
actions.__internalSetAvailablePaymentMethods( paymentMethods );
31-
expect(
32-
setDefaultPaymentMethodFunctions.setDefaultPaymentMethod
33-
).not.toBeCalled();
31+
expect( setDefaultPaymentMethodOriginal ).not.toBeCalled();
3432
} );
3533

3634
it( 'Resets the default gateway if the current method is no longer available', () => {
@@ -41,9 +39,7 @@ describe( 'payment data store actions', () => {
4139
actions.__internalSetAvailablePaymentMethods( [
4240
paymentMethods[ Object.keys( paymentMethods )[ 0 ] ],
4341
] );
44-
expect(
45-
setDefaultPaymentMethodFunctions.setDefaultPaymentMethod
46-
).toBeCalled();
42+
expect( setDefaultPaymentMethodOriginal ).toBeCalled();
4743
} );
4844
} );
4945
} );

assets/js/data/payment/test/set-default-payment-method.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as wpDataFunctions from '@wordpress/data';
77
/**
88
* Internal dependencies
99
*/
10-
import { setDefaultPaymentMethod } from '../set-default-payment-method';
10+
import { setDefaultPaymentMethod } from '../utils/set-default-payment-method';
1111
import { PlainPaymentMethods } from '../../../types';
1212
import { PAYMENT_STORE_KEY } from '..';
1313

assets/js/data/payment/test/utils.js

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

assets/js/data/payment/check-payment-methods.ts renamed to assets/js/data/payment/utils/check-payment-methods.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ import { previewCart } from '@woocommerce/resource-previews';
2323
/**
2424
* Internal dependencies
2525
*/
26-
import { STORE_KEY as CART_STORE_KEY } from '../cart/constants';
27-
import { STORE_KEY as PAYMENT_STORE_KEY } from './constants';
28-
import { noticeContexts } from '../../base/context/event-emit';
26+
import { STORE_KEY as CART_STORE_KEY } from '../../cart/constants';
27+
import { STORE_KEY as PAYMENT_STORE_KEY } from '../constants';
28+
import { noticeContexts } from '../../../base/context/event-emit';
2929
import {
3030
EMPTY_CART_ERRORS,
3131
EMPTY_CART_ITEM_ERRORS,
3232
EMPTY_EXTENSIONS,
33-
} from '../../data/constants';
33+
} from '../../constants';
3434
import {
3535
defaultBillingAddress,
3636
defaultShippingAddress,
37-
} from '../../base/context/providers/cart-checkout/customer/constants';
37+
} from '../../../base/context/providers/cart-checkout/customer/constants';
3838

3939
export const checkPaymentMethodsCanPay = async ( express = false ) => {
4040
const isEditor = !! select( 'core/editor' );
@@ -129,11 +129,8 @@ export const checkPaymentMethodsCanPay = async ( express = false ) => {
129129
shippingRates: previewCart.shipping_rates,
130130
isLoadingRates: false,
131131
cartHasCalculatedShipping: previewCart.has_calculated_shipping,
132-
paymentRequirements: previewCart.paymentRequirements,
133-
receiveCart:
134-
typeof previewCart?.receiveCart === 'function'
135-
? previewCart.receiveCart
136-
: () => undefined,
132+
paymentRequirements: previewCart.payment_requirements,
133+
receiveCart: () => undefined,
137134
};
138135
canPayArgument = {
139136
cart: cartForCanPayArgument,
@@ -149,6 +146,7 @@ export const checkPaymentMethodsCanPay = async ( express = false ) => {
149146
};
150147
}
151148

149+
// Order payment methods
152150
let paymentMethodsOrder;
153151
if ( express ) {
154152
paymentMethodsOrder = Object.keys( paymentMethods );

assets/js/data/payment/utils.ts renamed to assets/js/data/payment/utils/filter-active-saved-payment-methods.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getPaymentMethods } from '@woocommerce/blocks-registry';
66
/**
77
* Internal dependencies
88
*/
9-
import type { SavedPaymentMethods } from './types';
9+
import type { SavedPaymentMethods } from '../types';
1010

1111
/**
1212
* Gets the payment methods saved for the current user after filtering out disabled ones.
@@ -47,28 +47,3 @@ export const filterActiveSavedPaymentMethods = (
4747
} );
4848
return activeSavedPaymentMethods;
4949
};
50-
51-
/**
52-
* Given the order of methods from WooCommerce -> Payments, this method takes that order and sorts the list of available
53-
* payment methods to match it. This is required to ensure the payment methods show up in the correct order in the
54-
* Checkout
55-
*
56-
* @param order The order of payment methods from WooCommerce -> Settings -> Payments.
57-
* @param methods The list of payment method names to add to the state as available.
58-
*
59-
* @return string[] The list of available methods in their correct order.
60-
*/
61-
export const orderPaymentMethods = ( order: string[], methods: string[] ) => {
62-
const orderedMethods: string[] = [];
63-
order.forEach( ( paymentMethodName ) => {
64-
if ( methods.includes( paymentMethodName ) ) {
65-
orderedMethods.push( paymentMethodName );
66-
}
67-
} );
68-
// Now find any methods in `methods` that were not added to `orderedMethods` and append them to `orderedMethods`
69-
methods
70-
.filter( ( methodName ) => ! orderedMethods.includes( methodName ) )
71-
.forEach( ( methodName ) => orderedMethods.push( methodName ) );
72-
73-
return orderedMethods;
74-
};

assets/js/data/payment/set-default-payment-method.ts renamed to assets/js/data/payment/utils/set-default-payment-method.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PlainPaymentMethods } from '@woocommerce/type-defs/payments';
77
/**
88
* Internal dependencies
99
*/
10-
import { STORE_KEY as PAYMENT_STORE_KEY } from './constants';
10+
import { STORE_KEY as PAYMENT_STORE_KEY } from '../constants';
1111

1212
export const setDefaultPaymentMethod = async (
1313
paymentMethods: PlainPaymentMethods

checkstyle.xml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,12 @@
666666
<error line="411" column="5" severity="error" message="Type &apos;{ currency_code: &quot;USD&quot;; currency_symbol: string; currency_minor_unit: number; currency_decimal_separator: string; currency_thousand_separator: string; currency_prefix: string; currency_suffix: string; total: string; total_tax: string; tax_lines: { ...; }[]; }&apos; is not assignable to type &apos;CartResponseFeeItemTotals&apos;.
667667
Object literal may only specify known properties, and &apos;tax_lines&apos; does not exist in type &apos;CartResponseFeeItemTotals&apos;." source="TS2322" />
668668
</file>
669-
<file name="assets/js/data/payment/check-payment-methods.ts">
669+
<file name="assets/js/data/payment/utils/check-payment-methods.ts">
670670
<error line="15" column="10" severity="error" message="Module &apos;&quot;@wordpress/notices&quot;&apos; has no exported member &apos;store&apos;." source="TS2305" />
671-
<error line="132" column="37" severity="error" message="Property &apos;paymentRequirements&apos; does not exist on type &apos;CartResponse&apos;. Did you mean &apos;payment_requirements&apos;?" source="TS2551" />
672-
<error line="134" column="25" severity="error" message="Property &apos;receiveCart&apos; does not exist on type &apos;CartResponse&apos;." source="TS2339" />
673-
<error line="135" column="20" severity="error" message="Property &apos;receiveCart&apos; does not exist on type &apos;CartResponse&apos;." source="TS2339" />
674-
<error line="146" column="5" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;CartShippingRate[]&apos;." source="TS2345" />
675-
<error line="176" column="37" severity="error" message="Argument of type &apos;Record&lt;string, unknown&gt;&apos; is not assignable to parameter of type &apos;CanMakePaymentArgument&apos;.
671+
<error line="143" column="5" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;CartShippingRate[]&apos;." source="TS2345" />
672+
<error line="174" column="37" severity="error" message="Argument of type &apos;Record&lt;string, unknown&gt;&apos; is not assignable to parameter of type &apos;CanMakePaymentArgument&apos;.
676673
Type &apos;Record&lt;string, unknown&gt;&apos; is missing the following properties from type &apos;CanMakePaymentArgument&apos;: cart, cartTotals, cartNeedsShipping, billingData, and 3 more." source="TS2345" />
677-
<error line="188" column="13" severity="error" message="Property &apos;createErrorNotice&apos; does not exist on type &apos;typeof import(&quot;/home/runner/work/woocommerce-blocks/woocommerce-blocks/node_modules/@types/wordpress__rich-text/store/actions&quot;)&apos;." source="TS2339" />
674+
<error line="186" column="13" severity="error" message="Property &apos;createErrorNotice&apos; does not exist on type &apos;typeof import(&quot;/home/runner/work/woocommerce-blocks/woocommerce-blocks/node_modules/@types/wordpress__rich-text/store/actions&quot;)&apos;." source="TS2339" />
678675
</file>
679676
<file name="assets/js/data/payment/thunks.ts">
680677
<error line="4" column="10" severity="error" message="Module &apos;&quot;@wordpress/notices&quot;&apos; has no exported member &apos;store&apos;." source="TS2305" />

0 commit comments

Comments
 (0)