Redirect checkout to billing with status
This commit is contained in:
@@ -34,6 +34,8 @@
|
|||||||
"more": "Weitere Einträge konnten nicht geladen werden.",
|
"more": "Weitere Einträge konnten nicht geladen werden.",
|
||||||
"portal": "Paddle-Portal konnte nicht geöffnet werden."
|
"portal": "Paddle-Portal konnte nicht geöffnet werden."
|
||||||
},
|
},
|
||||||
|
"checkoutSuccess": "Checkout abgeschlossen. Dein Paket wird in Kürze aktiviert.",
|
||||||
|
"checkoutCancelled": "Checkout wurde abgebrochen.",
|
||||||
"sections": {
|
"sections": {
|
||||||
"invoices": {
|
"invoices": {
|
||||||
"title": "Rechnungen & Zahlungen",
|
"title": "Rechnungen & Zahlungen",
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
"more": "Unable to load more entries.",
|
"more": "Unable to load more entries.",
|
||||||
"portal": "Unable to open the Paddle portal."
|
"portal": "Unable to open the Paddle portal."
|
||||||
},
|
},
|
||||||
|
"checkoutSuccess": "Checkout completed. Your package will activate shortly.",
|
||||||
|
"checkoutCancelled": "Checkout was cancelled.",
|
||||||
"sections": {
|
"sections": {
|
||||||
"invoices": {
|
"invoices": {
|
||||||
"title": "Invoices & payments",
|
"title": "Invoices & payments",
|
||||||
|
|||||||
@@ -108,6 +108,34 @@ export default function MobileBillingPage() {
|
|||||||
}
|
}
|
||||||
}, [location.hash, loading]);
|
}, [location.hash, loading]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!location.search) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const params = new URLSearchParams(location.search);
|
||||||
|
const checkout = params.get('checkout');
|
||||||
|
if (!checkout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkout === 'success') {
|
||||||
|
toast.success(t('billing.checkoutSuccess', 'Checkout completed. Your package will activate shortly.'));
|
||||||
|
} else if (checkout === 'cancel') {
|
||||||
|
toast(t('billing.checkoutCancelled', 'Checkout was cancelled.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
params.delete('checkout');
|
||||||
|
navigate(
|
||||||
|
{
|
||||||
|
pathname: location.pathname,
|
||||||
|
search: params.toString(),
|
||||||
|
hash: location.hash,
|
||||||
|
},
|
||||||
|
{ replace: true },
|
||||||
|
);
|
||||||
|
}, [location.hash, location.pathname, location.search, navigate, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MobileShell
|
<MobileShell
|
||||||
activeTab="profile"
|
activeTab="profile"
|
||||||
@@ -535,4 +563,4 @@ function formatDate(value: string | null | undefined): string {
|
|||||||
const date = new Date(value);
|
const date = new Date(value);
|
||||||
if (Number.isNaN(date.getTime())) return '—';
|
if (Number.isNaN(date.getTime())) return '—';
|
||||||
return date.toLocaleDateString(undefined, { day: '2-digit', month: 'short', year: 'numeric' });
|
return date.toLocaleDateString(undefined, { day: '2-digit', month: 'short', year: 'numeric' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,9 +249,19 @@ function CheckoutConfirmation({ pkg, onCancel }: { pkg: Package; onCancel: () =>
|
|||||||
if (!canProceed || busy) return;
|
if (!canProceed || busy) return;
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
try {
|
try {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
throw new Error('Checkout is only available in the browser.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const billingUrl = new URL(adminPath('/mobile/billing'), window.location.origin);
|
||||||
|
const successUrl = new URL(billingUrl);
|
||||||
|
successUrl.searchParams.set('checkout', 'success');
|
||||||
|
const cancelUrl = new URL(billingUrl);
|
||||||
|
cancelUrl.searchParams.set('checkout', 'cancel');
|
||||||
|
|
||||||
const { checkout_url } = await createTenantPaddleCheckout(pkg.id, {
|
const { checkout_url } = await createTenantPaddleCheckout(pkg.id, {
|
||||||
success_url: window.location.href,
|
success_url: successUrl.toString(),
|
||||||
return_url: window.location.href,
|
return_url: cancelUrl.toString(),
|
||||||
});
|
});
|
||||||
window.location.href = checkout_url;
|
window.location.href = checkout_url;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user