fix(payment): guard ezpay redirect persistence
This commit is contained in:
@@ -63,10 +63,12 @@ export function SubscriptionCheckoutButton({
|
||||
}
|
||||
|
||||
if (isEzpay) {
|
||||
void redirectToEzpay({
|
||||
void launchEzpayRedirect({
|
||||
orderId: payment.currentOrderId,
|
||||
paymentUrl,
|
||||
subscriptionType,
|
||||
onFailed: (errorMessage) =>
|
||||
paymentDispatch({ type: "PaymentLaunchFailed", errorMessage }),
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -144,10 +146,14 @@ export function SubscriptionCheckoutButton({
|
||||
const handleEzpayConfirm = () => {
|
||||
if (!payment.currentOrderId || !ezpayPaymentUrl) return;
|
||||
setIsConfirmingEzpay(true);
|
||||
void redirectToEzpay({
|
||||
void launchEzpayRedirect({
|
||||
orderId: payment.currentOrderId,
|
||||
paymentUrl: ezpayPaymentUrl,
|
||||
subscriptionType,
|
||||
onFailed: (errorMessage) => {
|
||||
setIsConfirmingEzpay(false);
|
||||
paymentDispatch({ type: "PaymentLaunchFailed", errorMessage });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -235,47 +241,57 @@ interface RedirectToEzpayInput {
|
||||
orderId: string | null;
|
||||
paymentUrl: string;
|
||||
subscriptionType: "vip" | "voice";
|
||||
onFailed: (errorMessage: string) => void;
|
||||
}
|
||||
|
||||
async function redirectToEzpay({
|
||||
async function launchEzpayRedirect({
|
||||
orderId,
|
||||
paymentUrl,
|
||||
subscriptionType,
|
||||
onFailed,
|
||||
}: RedirectToEzpayInput): Promise<void> {
|
||||
log.debug("[subscription-checkout] redirectToEzpay START", {
|
||||
log.debug("[subscription-checkout] launchEzpayRedirect START", {
|
||||
hasOrderId: Boolean(orderId),
|
||||
orderId,
|
||||
subscriptionType,
|
||||
paymentUrl,
|
||||
});
|
||||
|
||||
if (orderId) {
|
||||
const saveResult = await PendingPaymentOrderStorage.setPendingOrder({
|
||||
orderId,
|
||||
payChannel: "ezpay",
|
||||
subscriptionType,
|
||||
createdAt: Date.now(),
|
||||
});
|
||||
if (Result.isOk(saveResult)) {
|
||||
log.debug("[subscription-checkout] pending ezpay order saved", {
|
||||
orderId,
|
||||
subscriptionType,
|
||||
});
|
||||
} else {
|
||||
log.error("[subscription-checkout] pending ezpay order save failed", {
|
||||
orderId,
|
||||
subscriptionType,
|
||||
error: saveResult.error,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
log.warn("[subscription-checkout] skip pending ezpay order save: missing orderId", {
|
||||
if (!orderId) {
|
||||
const errorMessage = "Missing order id before opening Ezpay.";
|
||||
log.error("[subscription-checkout] pending ezpay order save skipped", {
|
||||
subscriptionType,
|
||||
paymentUrl,
|
||||
errorMessage,
|
||||
});
|
||||
onFailed(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("[subscription-checkout] redirectToEzpay NOW", {
|
||||
const saveResult = await PendingPaymentOrderStorage.setPendingOrder({
|
||||
orderId,
|
||||
payChannel: "ezpay",
|
||||
subscriptionType,
|
||||
createdAt: Date.now(),
|
||||
});
|
||||
if (Result.isErr(saveResult)) {
|
||||
const errorMessage =
|
||||
"Could not save payment order before opening Ezpay. Please try again.";
|
||||
log.error("[subscription-checkout] pending ezpay order save failed", {
|
||||
orderId,
|
||||
subscriptionType,
|
||||
error: saveResult.error,
|
||||
});
|
||||
onFailed(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("[subscription-checkout] pending ezpay order saved", {
|
||||
orderId,
|
||||
subscriptionType,
|
||||
});
|
||||
|
||||
log.debug("[subscription-checkout] launchEzpayRedirect NOW", {
|
||||
orderId,
|
||||
subscriptionType,
|
||||
paymentUrl,
|
||||
|
||||
Reference in New Issue
Block a user