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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user