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:
Unchained
2026-03-29 19:33:04 +02:00
parent 9c3d8b0d11
commit de4eb0852c
2 changed files with 32 additions and 0 deletions

View File

@@ -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();

View File

@@ -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
}
}
}
`;