Skip to content

Commit 0c00e59

Browse files
authored
chore(clerk-js): Improve checkout error handling (#5654)
1 parent d8eda0b commit 0c00e59

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

.changeset/rude-mirrors-jog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/types': patch
4+
---
5+
6+
Chore: improve checkout error handling

packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,15 @@ const CheckoutFormElements = ({
109109
const { data: paymentSources } = data || { data: [] };
110110

111111
const confirmCheckout = async ({ paymentSourceId }: { paymentSourceId: string }) => {
112-
return checkout
113-
.confirm({
112+
try {
113+
const newCheckout = await checkout.confirm({
114114
paymentSourceId,
115115
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
116-
})
117-
.then(newCheckout => {
118-
onCheckoutComplete(newCheckout);
119-
})
120-
.catch(error => {
121-
throw error;
122116
});
117+
onCheckoutComplete(newCheckout);
118+
} catch (error) {
119+
handleError(error, [], setSubmitError);
120+
}
123121
};
124122

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

133-
try {
134-
await confirmCheckout({ paymentSourceId });
135-
} catch (error) {
136-
handleError(error, [], setSubmitError);
137-
} finally {
138-
setIsSubmitting(false);
139-
}
131+
await confirmCheckout({ paymentSourceId });
132+
setIsSubmitting(false);
140133
};
141134

142135
const onAddPaymentSourceSuccess = async (paymentSource: __experimental_CommercePaymentSourceResource) => {
143136
await confirmCheckout({ paymentSourceId: paymentSource.id });
137+
setIsSubmitting(false);
144138
};
145139

146140
return (

packages/clerk-js/src/ui/components/PricingTable/SubscriptionDetailDrawer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ const Header = React.forwardRef<HTMLDivElement, HeaderProps>((props, ref) => {
342342
<Badge
343343
elementDescriptor={descriptors.pricingTableCardBadge}
344344
localizationKey={localizationKeys('badge__currentPlan')}
345-
colorScheme={'primary'}
345+
colorScheme={'secondary'}
346346
/>
347347
) : (
348348
<Badge
349349
elementDescriptor={descriptors.pricingTableCardBadge}
350350
localizationKey={localizationKeys('badge__startsAt', {
351351
date: subscription?.periodStart,
352352
})}
353-
colorScheme={'secondary'}
353+
colorScheme={'primary'}
354354
/>
355355
)}
356356
</Span>

0 commit comments

Comments
 (0)