Skip to content

Commit

Permalink
feat(dashboard,core-flows,types,utils,medusa): Order cancelations wil…
Browse files Browse the repository at this point in the history
…l refund payments (#10667)

* feat(order, types): Add Credit Line to order module

* chore: add action to inject credit lines

* WIP

* chore: add fixes + observe

* chore: fix balances

* chore: add canceled badge

* chore: fix i18n schema

* chore: remove redunddant query

* chore: add changeset

* chore: add credit lines for all cancel cases

* chore: add accounting total

* chore: address review & cleanup
  • Loading branch information
riqwan authored Jan 7, 2025
1 parent 99a0610 commit 4759419
Show file tree
Hide file tree
Showing 27 changed files with 1,239 additions and 1,664 deletions.
10 changes: 10 additions & 0 deletions .changeset/tall-camels-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@medusajs/dashboard": patch
"@medusajs/core-flows": patch
"@medusajs/types": patch
"@medusajs/utils": patch
"@medusajs/medusa": patch
"@medusajs/order": patch
---

feat(dashboard,core-flows,types,utils,medusa,order): Order cancelations will refund payments
193 changes: 193 additions & 0 deletions integration-tests/http/__tests__/order/admin/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,199 @@ medusaIntegrationTestRunner({
})
})

describe("POST /orders/:id/cancel", () => {
beforeEach(async () => {
seeder = await createOrderSeeder({
api,
container: getContainer(),
})
order = seeder.order

order = (await api.get(`/admin/orders/${order.id}`, adminHeaders)).data
.order
})

it("should successfully cancel an order and its authorized but not captured payments", async () => {
const response = await api.post(
`/admin/orders/${order.id}/cancel`,
{},
adminHeaders
)

expect(response.status).toBe(200)
expect(response.data.order).toEqual(
expect.objectContaining({
id: order.id,
status: "canceled",

summary: expect.objectContaining({
credit_line_total: 106,
current_order_total: 0,
accounting_total: 0,
}),

payment_collections: [
expect.objectContaining({
status: "canceled",
captured_amount: 0,
refunded_amount: 0,
amount: 106,
payments: [
expect.objectContaining({
canceled_at: expect.any(String),
refunds: [],
captures: [],
}),
],
}),
],
})
)
})

it("should successfully cancel an order with a captured payment", async () => {
const payment = order.payment_collections[0].payments[0]

const paymentResponse = await api.post(
`/admin/payments/${payment.id}/capture`,
undefined,
adminHeaders
)

expect(paymentResponse.data.payment).toEqual(
expect.objectContaining({
id: payment.id,
captured_at: expect.any(String),
captures: [
expect.objectContaining({
id: expect.any(String),
amount: 106,
}),
],
refunds: [],
amount: 106,
})
)

const response = await api.post(
`/admin/orders/${order.id}/cancel`,
{},
adminHeaders
)

expect(response.status).toBe(200)
expect(response.data.order).toEqual(
expect.objectContaining({
id: order.id,
status: "canceled",

summary: expect.objectContaining({
credit_line_total: 106,
current_order_total: 0,
accounting_total: 0,
}),

payment_collections: [
expect.objectContaining({
status: "canceled",
captured_amount: 106,
refunded_amount: 106,
amount: 106,
payments: [
expect.objectContaining({
// canceled_at: expect.any(String),
refunds: [
expect.objectContaining({
id: expect.any(String),
amount: 106,
}),
],
captures: [
expect.objectContaining({
id: expect.any(String),
amount: 106,
}),
],
}),
],
}),
],
})
)
})

it("should successfully cancel an order with a partially captured payment", async () => {
const payment = order.payment_collections[0].payments[0]

const paymentResponse = await api.post(
`/admin/payments/${payment.id}/capture`,
{ amount: 50 },
adminHeaders
)

expect(paymentResponse.data.payment).toEqual(
expect.objectContaining({
id: payment.id,
captured_at: null,
captures: [
expect.objectContaining({
id: expect.any(String),
amount: 50,
}),
],
refunds: [],
amount: 106,
})
)

const response = await api.post(
`/admin/orders/${order.id}/cancel`,
{},
adminHeaders
)

expect(response.status).toBe(200)
expect(response.data.order).toEqual(
expect.objectContaining({
id: order.id,
status: "canceled",

summary: expect.objectContaining({
credit_line_total: 106,
current_order_total: 0,
accounting_total: 0,
}),

payment_collections: [
expect.objectContaining({
status: "canceled",
captured_amount: 50,
refunded_amount: 50,
amount: 106,
payments: [
expect.objectContaining({
// canceled_at: expect.any(String),
refunds: [
expect.objectContaining({
id: expect.any(String),
amount: 50,
}),
],
captures: [
expect.objectContaining({
id: expect.any(String),
amount: 50,
}),
],
}),
],
}),
],
})
)
})
})

describe("POST /orders/:id/fulfillments", () => {
beforeEach(async () => {
const stockChannelOverride = (
Expand Down
Loading

0 comments on commit 4759419

Please sign in to comment.