feat(core-flows): create or update payment collections in RMA flows (#8676)

* feat(core-flows): create or update payment collections in RMA flows

* chore: change ui to pick payment link from unpaid payment collection

* Apply suggestions from code review

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* chore: fix mathbn

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
Riqwan Thamir
2024-08-20 18:40:58 +02:00
committed by GitHub
co-authored by Carlos R. L. Rodrigues
parent 29830f0077
commit 430d9a38c4
10 changed files with 193 additions and 162 deletions
@@ -557,7 +557,11 @@ medusaIntegrationTestRunner({
adminHeaders
)
await api.post(`/admin/claims/${claimId2}/request`, {}, adminHeaders)
const testRes = await api.post(
`/admin/claims/${claimId2}/request`,
{},
adminHeaders
)
claimId = baseClaim.id
item = order.items[0]
@@ -682,6 +686,17 @@ medusaIntegrationTestRunner({
await api.get(`/admin/orders/${order.id}`, adminHeaders)
).data.order
const paymentCollections = fulfillOrder.payment_collections
expect(paymentCollections).toHaveLength(1)
expect(paymentCollections[0]).toEqual(
expect.objectContaining({
status: "not_paid",
amount: 171.5,
currency_code: "usd",
})
)
const fulfillableItem = fulfillOrder.items.find(
(item) => item.detail.fulfilled_quantity === 0
)
@@ -720,13 +735,26 @@ medusaIntegrationTestRunner({
)
})
it("should create a payment collection successfully and throw on multiple", async () => {
const paymentDelta = 171.5
it("should create a payment collection successfully", async () => {
const orderForPayment = (
await api.get(`/admin/orders/${order.id}`, adminHeaders)
).data.order
const paymentCollections = orderForPayment.payment_collections
expect(paymentCollections).toHaveLength(1)
expect(paymentCollections[0]).toEqual(
expect.objectContaining({
status: "not_paid",
amount: 171.5,
currency_code: "usd",
})
)
const paymentCollection = (
await api.post(
`/admin/payment-collections`,
{ order_id: order.id },
{ order_id: order.id, amount: 100 },
adminHeaders
)
).data.payment_collection
@@ -734,28 +762,14 @@ medusaIntegrationTestRunner({
expect(paymentCollection).toEqual(
expect.objectContaining({
currency_code: "usd",
amount: paymentDelta,
payment_sessions: [],
amount: 100,
status: "not_paid",
})
)
const { response } = await api
.post(
`/admin/payment-collections`,
{ order_id: order.id },
adminHeaders
)
.catch((e) => e)
expect(response.data).toEqual({
type: "not_allowed",
message:
"Active payment collections were found. Complete existing ones or delete them before proceeding.",
})
const deleted = (
await api.delete(
`/admin/payment-collections/${paymentCollection.id}`,
`/admin/payment-collections/${paymentCollections[0].id}`,
adminHeaders
)
).data
@@ -973,7 +987,8 @@ medusaIntegrationTestRunner({
},
adminHeaders
)
await api.post(
const { response } = await api.post(
`/admin/claims/${baseClaim.id}/request`,
{},
adminHeaders