Skip to content

Commit 88b01fd

Browse files
KariamosCopilot
andauthored
Update src/pages/Plan/summary/components/BuyButton.tsx
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 40e00b8 commit 88b01fd

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/pages/Plan/summary/components/BuyButton.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,23 @@ const BuyButton = ({ isStretched }: { isStretched?: boolean }) => {
4444
disabled={status === 'approved'}
4545
onClick={async () => {
4646
setIsPaymentInProgress(true);
47-
48-
await postCheckout({
49-
body: {
50-
meta: JSON.stringify(checkoutItemData?.metadata),
51-
price_id: checkoutItemData?.price_id ?? '',
52-
cancel_url: `${baseUrl}/plans/${planId}?payment=failed`,
53-
success_url: `${baseUrl}/plans/${planId}?payment=success`,
54-
},
55-
})
56-
.unwrap()
57-
.then((response) => {
58-
if (response.url) {
59-
window.location.href = response.url;
60-
}
61-
});
47+
try {
48+
const response = await postCheckout({
49+
body: {
50+
meta: JSON.stringify(checkoutItemData?.metadata),
51+
price_id: checkoutItemData?.price_id ?? '',
52+
cancel_url: `${baseUrl}/plans/${planId}?payment=failed`,
53+
success_url: `${baseUrl}/plans/${planId}?payment=success`,
54+
},
55+
}).unwrap();
56+
if (response.url) {
57+
window.location.href = response.url;
58+
} else {
59+
setIsPaymentInProgress(false);
60+
}
61+
} catch (error) {
62+
setIsPaymentInProgress(false);
63+
}
6264
}}
6365
>
6466
{t('__PLAN_PAGE_BUY_BUTTON_LABEL')}

0 commit comments

Comments
 (0)