Skip to content

Commit abf8980

Browse files
committed
Fix checkout error
1 parent db73afc commit abf8980

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

components/Checkout/CheckoutForm.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,28 @@ const handleSubmit = ({
9292
transactionId: "hjkhjkhsdsdiui",
9393
};
9494
95-
const variables = { input: checkoutData };
95+
const { mutate, onDone, onError } = useMutation(CHECKOUT_MUTATION);
9696
97-
const { mutate, onDone, onError } = useMutation(CHECKOUT_MUTATION, {
98-
variables,
99-
});
100-
101-
mutate(checkoutData);
97+
mutate({ input: checkoutData });
10298
103-
onDone(async () => await navigateTo("/success"));
99+
onDone(async (result) => {
100+
const { data } = result;
101+
if (data?.checkout?.result === "success") {
102+
await navigateTo("/success");
103+
} else {
104+
alert("Error, order not placed. Please try again.");
105+
}
106+
});
104107
105-
onError(() => alert("Error, order not placed"));
108+
onError((error) => {
109+
console.error("Checkout error:", error);
110+
if (error.message.includes("session")) {
111+
alert(
112+
"Your session has expired. Please refresh the page and try again.",
113+
);
114+
} else {
115+
alert("An unexpected error occurred. Please try again.");
116+
}
117+
});
106118
};
107119
</script>

0 commit comments

Comments
 (0)