Allowing local lemonsqueezy payment skip and emulate success response
This commit is contained in:
@@ -465,7 +465,7 @@ export const PaymentStep: React.FC = () => {
|
||||
console.info('[Checkout] Lemon Squeezy checkout response', { status: response.status, rawBody });
|
||||
}
|
||||
|
||||
let data: { checkout_url?: string; message?: string } | null = null;
|
||||
let data: { checkout_url?: string; message?: string; simulated?: boolean; order_id?: string; checkout_id?: string; id?: string; checkout_session_id?: string } | null = null;
|
||||
try {
|
||||
data = rawBody && rawBody.trim().startsWith('{') ? JSON.parse(rawBody) : null;
|
||||
} catch (parseError) {
|
||||
@@ -473,8 +473,24 @@ export const PaymentStep: React.FC = () => {
|
||||
data = null;
|
||||
}
|
||||
|
||||
if (data && typeof (data as { checkout_session_id?: string }).checkout_session_id === 'string') {
|
||||
setCheckoutSessionId((data as { checkout_session_id?: string }).checkout_session_id ?? null);
|
||||
const checkoutSession = data?.checkout_session_id ?? null;
|
||||
if (checkoutSession && typeof checkoutSession === 'string') {
|
||||
setCheckoutSessionId(checkoutSession);
|
||||
}
|
||||
|
||||
if (data?.simulated) {
|
||||
const orderId = typeof data.order_id === 'string' ? data.order_id : null;
|
||||
const checkoutId = typeof data.checkout_id === 'string'
|
||||
? data.checkout_id
|
||||
: (typeof data.id === 'string' ? data.id : null);
|
||||
|
||||
setStatus('processing');
|
||||
setMessage(t('checkout.payment_step.processing_confirmation'));
|
||||
setInlineActive(false);
|
||||
setPendingConfirmation({ orderId, checkoutId });
|
||||
setPaymentCompleted(true);
|
||||
nextStep();
|
||||
return;
|
||||
}
|
||||
|
||||
let checkoutUrl: string | null = typeof data?.checkout_url === 'string' ? data.checkout_url : null;
|
||||
|
||||
Reference in New Issue
Block a user