Skip to content

Commit dc46699

Browse files
authored
Merge pull request #1468 from w3bdesign/dev
Fix checkout error
2 parents 2284dbe + abf8980 commit dc46699

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ Optional plugin:
4444
- [headless-wordpress](https://github.com/w3bdesign/headless-wp) Disables the frontend so only the backend is accessible.
4545
- [wp-graphql-cors](https://github.com/funkhaus/wp-graphql-cors) Ensures that CORS works correctly. Remember to add the domain to the store under `Extend "Access-Control-Allow-Origin” header`
4646

47-
The current release has been tested and is confirmed working with the following plugin versions:
47+
The current release has been tested and is confirmed working with the following versions:
4848

49-
- WordPress version 6.6.2
50-
- WooCommerce version 7.4.0
51-
- WP GraphQL version 1.13.8
52-
- WooGraphQL version 0.12.0
49+
- WordPress version 6.8.1
50+
- WooCommerce version 9.9.5
51+
- WP GraphQL version 2.3.3
52+
- WooGraphQL version 0.19.0
5353
- WPGraphQL CORS version 2.1
5454

5555
2. Make sure WooCommerce has some products already or import some sample products

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)