fix(core-flows): prevent completing cart from webhook when order already exists (#14108)

* Prevent completing cart when order already exists in processPaymentWorkflow

* Add tests

* Add changeset
This commit is contained in:
Nicolas Gorga
2025-11-24 05:23:39 -03:00
committed by GitHub
parent d6a9e36bf0
commit 79582bc94e
3 changed files with 206 additions and 3 deletions

View File

@@ -73,10 +73,23 @@ export const processPaymentWorkflow = createWorkflow(
const cartId = transform(
{ cartPaymentCollection },
({ cartPaymentCollection }) => {
return cartPaymentCollection.data[0].cart_id
return cartPaymentCollection.data[0]?.cart_id
}
)
const { data: order } = useQueryGraphStep({
entity: "order_cart",
fields: ["id"],
filters: {
cart_id: cartId
},
options: {
isList: false
}
}).config({
name: "cart-order-query",
})
when("lock-cart-when-available", { cartId }, ({ cartId }) => {
return !!cartId
}).then(() => {
@@ -158,8 +171,8 @@ export const processPaymentWorkflow = createWorkflow(
})
})
when({ cartPaymentCollection }, ({ cartPaymentCollection }) => {
return !!cartPaymentCollection.data.length
when({ cartPaymentCollection, order }, ({ cartPaymentCollection, order }) => {
return !!cartPaymentCollection.data.length && !order
}).then(() => {
completeCartAfterPaymentStep({
cart_id: cartPaymentCollection.data[0].cart_id,