Redirect checkout to billing with status
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
"more": "Weitere Einträge konnten nicht geladen werden.",
|
||||
"portal": "Paddle-Portal konnte nicht geöffnet werden."
|
||||
},
|
||||
"checkoutSuccess": "Checkout abgeschlossen. Dein Paket wird in Kürze aktiviert.",
|
||||
"checkoutCancelled": "Checkout wurde abgebrochen.",
|
||||
"sections": {
|
||||
"invoices": {
|
||||
"title": "Rechnungen & Zahlungen",
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
"more": "Unable to load more entries.",
|
||||
"portal": "Unable to open the Paddle portal."
|
||||
},
|
||||
"checkoutSuccess": "Checkout completed. Your package will activate shortly.",
|
||||
"checkoutCancelled": "Checkout was cancelled.",
|
||||
"sections": {
|
||||
"invoices": {
|
||||
"title": "Invoices & payments",
|
||||
|
||||
@@ -108,6 +108,34 @@ export default function MobileBillingPage() {
|
||||
}
|
||||
}, [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 (
|
||||
<MobileShell
|
||||
activeTab="profile"
|
||||
|
||||
@@ -249,9 +249,19 @@ function CheckoutConfirmation({ pkg, onCancel }: { pkg: Package; onCancel: () =>
|
||||
if (!canProceed || busy) return;
|
||||
setBusy(true);
|
||||
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, {
|
||||
success_url: window.location.href,
|
||||
return_url: window.location.href,
|
||||
success_url: successUrl.toString(),
|
||||
return_url: cancelUrl.toString(),
|
||||
});
|
||||
window.location.href = checkout_url;
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user