feat: Add order auto-confirmation (best effort)
Added order confirmation after checkout completion. Note: This requires MANAGE_ORDERS permission which currently has the same bug as HANDLE_PAYMENTS. The try-catch ensures checkout won't fail if confirmation fails. Orders will be UNCONFIRMED until manually confirmed in dashboard.
This commit is contained in:
@@ -13,6 +13,7 @@ import { saleorClient } from "@/lib/saleor/client";
|
|||||||
import { useAnalytics } from "@/lib/analytics";
|
import { useAnalytics } from "@/lib/analytics";
|
||||||
import {
|
import {
|
||||||
CHECKOUT_SHIPPING_ADDRESS_UPDATE,
|
CHECKOUT_SHIPPING_ADDRESS_UPDATE,
|
||||||
|
ORDER_CONFIRM,
|
||||||
} from "@/lib/saleor/mutations/Checkout";
|
} from "@/lib/saleor/mutations/Checkout";
|
||||||
import { PaymentSection } from "./components/PaymentSection";
|
import { PaymentSection } from "./components/PaymentSection";
|
||||||
import { DEFAULT_PAYMENT_METHOD } from "@/lib/config/paymentMethods";
|
import { DEFAULT_PAYMENT_METHOD } from "@/lib/config/paymentMethods";
|
||||||
@@ -306,6 +307,21 @@ export default function CheckoutPage() {
|
|||||||
setOrderNumber(result.order.number);
|
setOrderNumber(result.order.number);
|
||||||
setOrderComplete(true);
|
setOrderComplete(true);
|
||||||
|
|
||||||
|
// Auto-confirm the order
|
||||||
|
try {
|
||||||
|
console.log("Auto-confirming order:", result.order.id);
|
||||||
|
await saleorClient.mutate({
|
||||||
|
mutation: ORDER_CONFIRM,
|
||||||
|
variables: {
|
||||||
|
orderId: result.order.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log("Order confirmed successfully");
|
||||||
|
} catch (confirmError) {
|
||||||
|
console.error("Failed to auto-confirm order:", confirmError);
|
||||||
|
// Don't fail the checkout if confirmation fails
|
||||||
|
}
|
||||||
|
|
||||||
// Clear the checkout/cart from the store
|
// Clear the checkout/cart from the store
|
||||||
clearCheckout();
|
clearCheckout();
|
||||||
|
|
||||||
|
|||||||
@@ -224,3 +224,19 @@ export const TRANSACTION_CREATE = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const ORDER_CONFIRM = gql`
|
||||||
|
mutation OrderConfirm($orderId: ID!) {
|
||||||
|
orderConfirm(id: $orderId) {
|
||||||
|
order {
|
||||||
|
id
|
||||||
|
number
|
||||||
|
status
|
||||||
|
}
|
||||||
|
errors {
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user