Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/rude-mirrors-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Chore: improve checkout error handling
24 changes: 9 additions & 15 deletions packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ const CheckoutFormElements = ({
const { data: paymentSources } = data || { data: [] };

const confirmCheckout = async ({ paymentSourceId }: { paymentSourceId: string }) => {
return checkout
.confirm({
try {
const newCheckout = await checkout.confirm({
paymentSourceId,
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
})
.then(newCheckout => {
onCheckoutComplete(newCheckout);
})
.catch(error => {
throw error;
});
onCheckoutComplete(newCheckout);
} catch (error) {
handleError(error, [], setSubmitError);
}
};

const onPaymentSourceSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -130,17 +128,13 @@ const CheckoutFormElements = ({
const data = new FormData(e.currentTarget);
const paymentSourceId = data.get('payment_source_id') as string;

try {
await confirmCheckout({ paymentSourceId });
} catch (error) {
handleError(error, [], setSubmitError);
} finally {
setIsSubmitting(false);
}
await confirmCheckout({ paymentSourceId });
setIsSubmitting(false);
};

const onAddPaymentSourceSuccess = async (paymentSource: __experimental_CommercePaymentSourceResource) => {
await confirmCheckout({ paymentSourceId: paymentSource.id });
setIsSubmitting(false);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ const Header = React.forwardRef<HTMLDivElement, HeaderProps>((props, ref) => {
<Badge
elementDescriptor={descriptors.pricingTableCardBadge}
localizationKey={localizationKeys('badge__currentPlan')}
colorScheme={'primary'}
colorScheme={'secondary'}
/>
) : (
<Badge
elementDescriptor={descriptors.pricingTableCardBadge}
localizationKey={localizationKeys('badge__startsAt', {
date: subscription?.periodStart,
})}
colorScheme={'secondary'}
colorScheme={'primary'}
/>
)}
</Span>
Expand Down