Skip to content

Commit

Permalink
feat(payment): STRIPE-444 New Stripe UPE (PoC)
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlenkoM committed Oct 7, 2024
1 parent 79f0163 commit e12c07e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/src/app/ui/form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export { default as CheckboxInput } from './CheckboxInput';
export { default as Label, LabelProps } from './Label';
export { default as Legend, LegendProps } from './Legend';
export { default as ChecklistItemInput, ChecklistItemInputProps } from './ChecklistItemInput';
export { default as CustomChecklistItem, CustomChecklistItemProps } from './CustomChecklistItem';
export { default as DynamicFormField } from './DynamicFormField';
export { default as DynamicFormFieldType } from './DynamicFormFieldType';
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,14 @@
will-change: $loading-skeleton-will-change;
}
}

.custom-checklist-item {
margin: 0;
overflow: hidden;
border-bottom: 0;

.paymentMethod--hosted,
.widget {
padding: 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { PaymentInitializeOptions } from '@bigcommerce/checkout-sdk';
import { noop, some } from 'lodash';
import React, { FunctionComponent, useCallback, useMemo } from 'react';
import React, {
FunctionComponent,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
} from 'react';

import { getAppliedStyles } from '@bigcommerce/checkout/dom-utils';
import { HostedWidgetPaymentComponent } from '@bigcommerce/checkout/hosted-widget-integration';
Expand All @@ -13,6 +20,7 @@ import {
PaymentMethodResolveId,
toResolvableComponent,
} from '@bigcommerce/checkout/payment-integration-api';
import { AccordionContext } from '@bigcommerce/checkout/ui';

const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
paymentForm,
Expand All @@ -22,9 +30,19 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
onUnhandledError = noop,
...rest
}) => {
const collapseStripeElement = useRef<() => void>();
const { onToggle, selectedItemId } = useContext(AccordionContext);
const containerId = `stripe-${method.id}-component-field`;
const paymentContext = paymentForm;

useEffect(() => {
if (selectedItemId?.includes('stripeupe-')) {
return;
}

collapseStripeElement.current?.();
}, [selectedItemId]);

const renderSubmitButton = useCallback(() => {
paymentContext.hidePaymentSubmitButton(method, false);
}, [paymentContext, method]);
Expand Down Expand Up @@ -69,6 +87,10 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
return getAppliedStyles(parentContainer, properties);
};

// const accordionCollapseListener = (collapseElement: () => void) => {
// collapseStripeElement.current = collapseElement;
// };

const initializeStripePayment = useCallback(
async (options: PaymentInitializeOptions) => {
const formInput = getStylesFromElement(`${containerId}--input`, [
Expand Down Expand Up @@ -97,6 +119,10 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
},
onError: onUnhandledError,
render: renderSubmitButton,
paymentMethodSelect: onToggle,
handleClosePaymentMethod: (collapseElement: () => void) => {
collapseStripeElement.current = collapseElement;
},
},
});
},
Expand All @@ -107,6 +133,7 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
method,
paymentContext,
renderSubmitButton,
onToggle,
],
);

Expand Down

0 comments on commit e12c07e

Please sign in to comment.