paddle session fixes
This commit is contained in:
@@ -449,6 +449,7 @@ class CheckoutController extends Controller
|
|||||||
'transaction_id' => $transactionId,
|
'transaction_id' => $transactionId,
|
||||||
'status' => $exception->status(),
|
'status' => $exception->status(),
|
||||||
'message' => $exception->getMessage(),
|
'message' => $exception->getMessage(),
|
||||||
|
'context' => $exception->context(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -200,9 +200,12 @@ export const PaymentStep: React.FC = () => {
|
|||||||
const [freeActivationBusy, setFreeActivationBusy] = useState(false);
|
const [freeActivationBusy, setFreeActivationBusy] = useState(false);
|
||||||
const [awaitingConfirmation, setAwaitingConfirmation] = useState(false);
|
const [awaitingConfirmation, setAwaitingConfirmation] = useState(false);
|
||||||
const [confirmationElapsedMs, setConfirmationElapsedMs] = useState(0);
|
const [confirmationElapsedMs, setConfirmationElapsedMs] = useState(0);
|
||||||
|
const [pendingConfirmation, setPendingConfirmation] = useState<{
|
||||||
|
transactionId: string | null;
|
||||||
|
checkoutId: string | null;
|
||||||
|
} | null>(null);
|
||||||
const confirmationTimerRef = useRef<number | null>(null);
|
const confirmationTimerRef = useRef<number | null>(null);
|
||||||
const statusCheckRef = useRef<(() => void) | null>(null);
|
const statusCheckRef = useRef<(() => void) | null>(null);
|
||||||
const confirmRequestRef = useRef(false);
|
|
||||||
|
|
||||||
const paddleLocale = useMemo(() => {
|
const paddleLocale = useMemo(() => {
|
||||||
const sourceLocale = i18n.language || (typeof document !== 'undefined' ? document.documentElement.lang : null);
|
const sourceLocale = i18n.language || (typeof document !== 'undefined' ? document.documentElement.lang : null);
|
||||||
@@ -211,15 +214,12 @@ export const PaymentStep: React.FC = () => {
|
|||||||
|
|
||||||
const isFree = useMemo(() => (selectedPackage ? Number(selectedPackage.price) <= 0 : false), [selectedPackage]);
|
const isFree = useMemo(() => (selectedPackage ? Number(selectedPackage.price) <= 0 : false), [selectedPackage]);
|
||||||
|
|
||||||
const confirmCheckoutSession = useCallback(async (payload: Record<string, unknown>) => {
|
const confirmCheckoutSession = useCallback(async (payload: { transactionId: string | null; checkoutId: string | null }) => {
|
||||||
if (!checkoutSessionId) {
|
if (!checkoutSessionId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const transactionId = typeof payload?.transaction_id === 'string' ? payload.transaction_id : null;
|
if (!payload.transactionId && !payload.checkoutId) {
|
||||||
const checkoutId = typeof payload?.id === 'string' ? payload.id : null;
|
|
||||||
|
|
||||||
if (!transactionId && !checkoutId) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,8 +229,8 @@ export const PaymentStep: React.FC = () => {
|
|||||||
headers: buildCheckoutHeaders(),
|
headers: buildCheckoutHeaders(),
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
transaction_id: transactionId,
|
transaction_id: payload.transactionId,
|
||||||
checkout_id: checkoutId,
|
checkout_id: payload.checkoutId,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -544,15 +544,14 @@ export const PaymentStep: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.name === 'checkout.completed') {
|
if (event.name === 'checkout.completed') {
|
||||||
|
const transactionId = typeof event?.data?.transaction_id === 'string' ? event.data.transaction_id : null;
|
||||||
|
const checkoutId = typeof event?.data?.id === 'string' ? event.data.id : null;
|
||||||
setStatus('processing');
|
setStatus('processing');
|
||||||
setMessage(t('checkout.payment_step.processing_confirmation'));
|
setMessage(t('checkout.payment_step.processing_confirmation'));
|
||||||
setInlineActive(false);
|
setInlineActive(false);
|
||||||
setAwaitingConfirmation(true);
|
setAwaitingConfirmation(true);
|
||||||
setPaymentCompleted(false);
|
setPaymentCompleted(false);
|
||||||
if (!confirmRequestRef.current) {
|
setPendingConfirmation({ transactionId, checkoutId });
|
||||||
confirmRequestRef.current = true;
|
|
||||||
void confirmCheckoutSession(event.data as Record<string, unknown>);
|
|
||||||
}
|
|
||||||
toast.success(t('checkout.payment_step.toast_success'));
|
toast.success(t('checkout.payment_step.toast_success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,9 +627,18 @@ export const PaymentStep: React.FC = () => {
|
|||||||
setInlineActive(false);
|
setInlineActive(false);
|
||||||
setAwaitingConfirmation(false);
|
setAwaitingConfirmation(false);
|
||||||
setConfirmationElapsedMs(0);
|
setConfirmationElapsedMs(0);
|
||||||
confirmRequestRef.current = false;
|
setPendingConfirmation(null);
|
||||||
}, [selectedPackage?.id, setPaymentCompleted]);
|
}, [selectedPackage?.id, setPaymentCompleted]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!pendingConfirmation || !checkoutSessionId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void confirmCheckoutSession(pendingConfirmation);
|
||||||
|
setPendingConfirmation(null);
|
||||||
|
}, [checkoutSessionId, confirmCheckoutSession, pendingConfirmation]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!awaitingConfirmation || typeof window === 'undefined') {
|
if (!awaitingConfirmation || typeof window === 'undefined') {
|
||||||
if (confirmationTimerRef.current) {
|
if (confirmationTimerRef.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user