-
Notifications
You must be signed in to change notification settings - Fork 407
[do not merge][POC] feat(payment): PI-5065 Oney pay grouping in one tab #2903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,19 +64,54 @@ interface PaymentMethodSelectionParams { | |
| checkout: Checkout; | ||
| methods: PaymentMethod[]; | ||
| consignments?: Consignment[]; | ||
| checkoutSettings?: CheckoutSettings; | ||
| getPaymentMethod: (methodId: string, gatewayId?: string) => PaymentMethod | undefined; | ||
| paymentProviderCustomer?: PaymentProviderCustomer; | ||
| } | ||
|
|
||
| const groupMethodsByPrefix = (methods: PaymentMethod[], prefix: string): PaymentMethod[] => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, the pr looks good to me. Can we break this function into 3 functions:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bc-peng Thanks for the suggestion! Since this is just a POC, we can definitely incorporate these changes during the actual development phase. |
||
| const group = methods.filter((m) => m.id.startsWith(prefix)); | ||
|
|
||
| if (group.length <= 1) { | ||
| return methods; | ||
| } | ||
|
|
||
| const sorted = [...group].sort((a, b) => { | ||
| const toNum = (id: string) => parseInt(id.slice(prefix.length), 10) || 0; | ||
|
|
||
| return toNum(a.id) - toNum(b.id); | ||
| }); | ||
|
|
||
| const [first] = sorted; | ||
| const representative: PaymentMethod = { | ||
| ...first, | ||
| config: { | ||
| ...first.config, | ||
| displayName: first.config.displayName?.replace(/^\d+x\s+/i, '') ?? first.config.displayName, | ||
| }, | ||
| initializationData: { | ||
| ...(first.initializationData as Record<string, unknown>), | ||
| groupedMethods: sorted, | ||
| }, | ||
| }; | ||
|
|
||
| return methods.flatMap((m) => { | ||
| if (!m.id.startsWith(prefix)) return [m]; | ||
| if (m.id === first.id) return [representative]; | ||
|
|
||
| return []; | ||
| }); | ||
| }; | ||
|
|
||
| const getDefaultPaymentMethod = ({ | ||
| checkout, | ||
| checkoutSettings, | ||
| consignments, | ||
| getPaymentMethod, | ||
| methods, | ||
| paymentProviderCustomer, | ||
| }: PaymentMethodSelectionParams): { filteredMethods: PaymentMethod[]; defaultMethod?: PaymentMethod } => { | ||
| let filteredMethods = methods; | ||
|
|
||
| // TODO: In accordance with the checkout team, this functionality is temporary and will be implemented in the backend instead. | ||
| if (paymentProviderCustomer?.stripeLinkAuthenticationState) { | ||
| const stripeUpePaymentMethod = filteredMethods.filter( | ||
|
|
@@ -94,6 +129,12 @@ const getDefaultPaymentMethod = ({ | |
| return method.id !== PaymentMethodId.BraintreeLocalPaymentMethod; | ||
| }); | ||
|
|
||
| if (isExperimentEnabled(checkoutSettings, 'PAYMENTS-XXXX.oney_facilypay_grouping', false)) { | ||
| const GROUPED_METHOD_ID_PREFIXES = ['facilypay_']; | ||
|
|
||
| filteredMethods = GROUPED_METHOD_ID_PREFIXES.reduce(groupMethodsByPrefix, filteredMethods); | ||
| } | ||
|
|
||
| if (consignments && consignments.length > 1) { | ||
| const multiShippingIncompatibleMethodIds: string[] = [ | ||
| PaymentMethodId.AmazonPay, | ||
|
|
@@ -550,6 +591,7 @@ const Payment= (props: PaymentProps & WithCheckoutPaymentProps & WithLanguagePro | |
| const defaultMethod = checkout | ||
| ? getDefaultPaymentMethod({ | ||
| checkout, | ||
| checkoutSettings: updatedState.data.getConfig()?.checkoutSettings, | ||
| consignments: updatedState.data.getConsignments(), | ||
| getPaymentMethod: updatedState.data.getPaymentMethod, | ||
| methods, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m concerned that introducing
isHiddenconcept in the payment method list may not scale well, since some methods need to remain visible during initialization.Instead of keeping hidden payment methods and teaching
PaymentMethodListto skip them, can we consider filtering non-representative methods out offilteredMethodsentirely, and let the Oney component handle the selection and showing a represented method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I have updated PR.