feat(medusa,medusa-react): PaymentCollection support (#2659)

* chore: medusa react, order edit complete fix and single payment session
This commit is contained in:
Carlos R. L. Rodrigues
2022-12-07 12:39:35 -03:00
committed by GitHub
parent 42d9c7222b
commit 15c667fbd3
54 changed files with 2001 additions and 261 deletions
+73 -3
View File
@@ -1154,8 +1154,8 @@
"publishable_api_key": {
"id": "pubkey_1234",
"created_by": "admin_user",
"created_at": "2021-11-08 11:58:56.975971+01",
"updated_at": "2021-11-08 11:58:56.975971+01",
"created_at": "2021-11-08 11:58:56.975971+01",
"updated_at": "2021-11-08 11:58:56.975971+01",
"revoked_by": null,
"revoked_at": null
},
@@ -1324,6 +1324,76 @@
"created_at": "2022-07-05T15:16:01.959Z",
"deleted_at": null
}
]
],
"payment_collection": {
"id": "paycol_01GJK7P9MRHM6XWCJG70JFB8PF",
"created_at": "2022-11-23T21:53:19.367Z",
"updated_at": "2022-11-24T12:57:08.652Z",
"deleted_at": null,
"type": "order_edit",
"status": "authorized",
"description": null,
"amount": 900,
"authorized_amount": 900,
"region_id": "test-region",
"currency_code": "usd",
"metadata": null,
"created_by": "admin_user",
"payment_sessions": [
{
"id": "ps_01GJMVD71Z4WF9FXXGT7DHGPCM",
"created_at": "2022-11-24T12:57:07.883Z",
"updated_at": "2022-11-24T12:57:08.652Z",
"cart_id": null,
"provider_id": "test-pay",
"is_selected": null,
"status": "authorized",
"data": {},
"idempotency_key": null,
"amount": 900,
"payment_authorized_at": "2022-11-24T12:57:08.672Z"
}
]
},
"payment_sessions": {
"id": "ps_01GJMVD71Z4WF9FXXGT7DHGPCM",
"created_at": "2022-11-24T12:57:07.883Z",
"updated_at": "2022-11-24T12:57:08.652Z",
"cart_id": null,
"provider_id": "test-pay",
"is_selected": null,
"status": "authorized",
"data": {},
"idempotency_key": null,
"amount": 900,
"payment_authorized_at": "2022-11-24T12:57:08.672Z"
},
"payment": {
"id": "pay_A1GJEVD71Z4WF9FXFGT7D1GP15",
"swap_id": null,
"cart_id": null,
"order_id": null,
"amount": 900,
"currency_code": "usd",
"amount_refunded": 0,
"amount_captured": 900,
"provider_id": "manual",
"data": {},
"captured_at": "2022-11-17T21:24:35.871Z",
"canceled_at": null,
"created_at": "2022-11-16T21:24:35.871Z",
"updated_at": "2022-11-16T21:24:35.871Z",
"metadata": null,
"idempotency_key": null
},
"refund": {
"order_id": null,
"payment_id": "pay_A1GJEVD71Z4WF9FXFGT7D1GP15",
"amount": 900,
"note": null,
"reason": "return",
"metadata": null,
"idempotency_key": null
}
}
}
@@ -2104,4 +2104,103 @@ export const adminHandlers = [
})
)
}),
rest.get("/admin/payment-collections/:id", (req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(200),
ctx.json({
payment_collection: {
...fixtures.get("payment_collection"),
id,
},
})
)
}),
rest.delete("/admin/payment-collections/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
id: req.params.id,
object: "payment_collection",
deleted: true,
})
)
}),
rest.post("/admin/payment-collections/:id", (req, res, ctx) => {
const { id } = req.params
const { description, metadata } = req.body as any
return res(
ctx.status(200),
ctx.json({
payment_collection: {
...fixtures.get("payment_collection"),
description,
metadata,
id,
},
})
)
}),
rest.post("/admin/payment-collections/:id/authorize", (req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(200),
ctx.json({
payment_collection: {
...fixtures.get("payment_collection"),
id,
},
})
)
}),
rest.get("/admin/payments/:id", (req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(200),
ctx.json({
payment: {
...fixtures.get("payment"),
id,
},
})
)
}),
rest.post("/admin/payments/:id/capture", (req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(200),
ctx.json({
payment: {
...fixtures.get("payment"),
id,
},
})
)
}),
rest.post("/admin/payments/:id/refund", (req, res, ctx) => {
const { id } = req.params
const { amount, reason, note } = req.body as any
return res(
ctx.status(200),
ctx.json({
refund: {
...fixtures.get("refund"),
payment_id: id,
amount,
reason,
note,
},
})
)
}),
]
@@ -446,4 +446,100 @@ export const storeHandlers = [
})
)
}),
rest.get("/store/payment-collections/:id", (req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(200),
ctx.json({
payment_collection: {
...fixtures.get("payment_collection"),
id,
},
})
)
}),
rest.post(
"/store/payment-collections/:id/sessions/batch",
(req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(200),
ctx.json({
payment_collection: {
...fixtures.get("payment_collection"),
id,
},
})
)
}
),
rest.post(
"/store/payment-collections/:id/sessions/batch/authorize",
(req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(207),
ctx.json({
payment_collection: {
...fixtures.get("payment_collection"),
id,
},
})
)
}
),
rest.post("/store/payment-collections/:id/sessions", (req, res, ctx) => {
const { id } = req.params
return res(
ctx.status(200),
ctx.json({
payment_collection: {
...fixtures.get("payment_collection"),
id,
},
})
)
}),
rest.post(
"/store/payment-collections/:id/sessions/:session_id",
(req, res, ctx) => {
const { id, session_id } = req.params
const payCol: any = { ...fixtures.get("payment_collection") }
payCol.payment_sessions[0].id = `new_${session_id}`
const session = {
payment_session: payCol.payment_sessions[0],
}
return res(
ctx.status(200),
ctx.json({
...session,
})
)
}
),
rest.post(
"/store/payment-collections/:id/sessions/:session_id/authorize",
(req, res, ctx) => {
const { session_id } = req.params
const session = fixtures.get("payment_collection").payment_sessions[0]
return res(
ctx.status(200),
ctx.json({
payment_session: {
...session,
id: session_id,
},
})
)
}
),
]