Skip to content
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

feat(payment): STRIPE-444 New Stripe UPE (PoC) #2018

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -97,6 +115,10 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
},
onError: onUnhandledError,
render: renderSubmitButton,
paymentMethodSelect: onToggle,
handleClosePaymentMethod: (collapseElement: () => void) => {
collapseStripeElement.current = collapseElement;
},
},
});
},
Expand All @@ -107,6 +129,7 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
method,
paymentContext,
renderSubmitButton,
onToggle,
],
);

Expand Down