Add PayPal checkout provider

This commit is contained in:
Codex Agent
2026-02-04 12:18:14 +01:00
parent 56a39d0535
commit fc5dfb272c
33 changed files with 1586 additions and 571 deletions

View File

@@ -2,7 +2,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import toast from 'react-hot-toast';
import { createTenantLemonSqueezyCheckout } from '../../api';
import { createTenantPayPalCheckout } from '../../api';
import { adminPath } from '../../constants';
import { getApiErrorMessage } from '../../lib/apiError';
import { storePendingCheckout } from '../lib/billingCheckout';
@@ -33,7 +33,7 @@ export function usePackageCheckout(): {
cancelUrl.searchParams.set('checkout', 'cancel');
cancelUrl.searchParams.set('package_id', String(packageId));
const { checkout_url, checkout_session_id } = await createTenantLemonSqueezyCheckout(packageId, {
const { approve_url, order_id, checkout_session_id } = await createTenantPayPalCheckout(packageId, {
success_url: successUrl.toString(),
return_url: cancelUrl.toString(),
});
@@ -43,10 +43,15 @@ export function usePackageCheckout(): {
packageId,
checkoutSessionId: checkout_session_id,
startedAt: Date.now(),
orderId: order_id,
});
}
window.location.href = checkout_url;
if (!approve_url) {
throw new Error('PayPal checkout URL missing.');
}
window.location.href = approve_url;
} catch (err) {
toast.error(getApiErrorMessage(err, t('shop.errors.checkout', 'Checkout failed')));
setBusy(false);