Merge branch 'develop' into feat/disabling-of-notification
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
import {
|
||||
MedusaError,
|
||||
Validator,
|
||||
transformIdableFields,
|
||||
} from "medusa-core-utils"
|
||||
import { defaultFields, defaultRelations } from "."
|
||||
|
||||
/**
|
||||
@@ -137,11 +141,13 @@ export default async (req, res) => {
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
let { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
value = transformIdableFields(value, ["shipping_address", "billing_address"])
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
let draftOrder = await draftOrderService.create(value)
|
||||
|
||||
@@ -10,10 +10,10 @@ describe("POST /store/carts/:id/payment-session/update", () => {
|
||||
const cartId = IdMap.getId("cartWithPaySessions")
|
||||
subject = await request(
|
||||
"POST",
|
||||
`/store/carts/${cartId}/payment-session/update`,
|
||||
`/store/carts/${cartId}/payment-sessions/default_provider`,
|
||||
{
|
||||
payload: {
|
||||
session: {
|
||||
data: {
|
||||
data: "Something",
|
||||
},
|
||||
},
|
||||
@@ -26,6 +26,12 @@ describe("POST /store/carts/:id/payment-session/update", () => {
|
||||
})
|
||||
|
||||
it("calls CartService updatePaymentSession", () => {
|
||||
expect(CartServiceMock.setPaymentSession).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.setPaymentSession).toHaveBeenCalledWith(
|
||||
IdMap.getId("cartWithPaySessions"),
|
||||
"default_provider"
|
||||
)
|
||||
|
||||
expect(CartServiceMock.updatePaymentSession).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.updatePaymentSession).toHaveBeenCalledWith(
|
||||
IdMap.getId("cartWithPaySessions"),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
|
||||
/**
|
||||
* @oas [post] /carts/{id}/complete-cart
|
||||
* @oas [post] /carts/{id}/complete
|
||||
* summary: "Complete a Cart"
|
||||
* operationId: "PostCartsCartComplete"
|
||||
* description: "Completes a cart. The following steps will be performed. Payment
|
||||
|
||||
@@ -24,6 +24,12 @@ export default (app, container) => {
|
||||
|
||||
route.post("/:id", middlewares.wrap(require("./update-cart").default))
|
||||
|
||||
route.post(
|
||||
"/:id/complete",
|
||||
middlewares.wrap(require("./complete-cart").default)
|
||||
)
|
||||
|
||||
// DEPRECATION
|
||||
route.post(
|
||||
"/:id/complete-cart",
|
||||
middlewares.wrap(require("./complete-cart").default)
|
||||
@@ -55,7 +61,7 @@ export default (app, container) => {
|
||||
)
|
||||
|
||||
route.post(
|
||||
"/:id/payment-session/update",
|
||||
"/:id/payment-sessions/:provider_id",
|
||||
middlewares.wrap(require("./update-payment-session").default)
|
||||
)
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@ import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { defaultFields, defaultRelations } from "./"
|
||||
|
||||
/**
|
||||
* @oas [post] /carts/{id}/payment-session/update
|
||||
* @oas [post] /carts/{id}/payment-sessions/{provider_id}
|
||||
* operationId: PostCartsCartPaymentSessionUpdate
|
||||
* summary: Update a Payment Session
|
||||
* description: "Updates a Payment Session with additional data."
|
||||
* parameters:
|
||||
* - (path) id=* {string} The id of the Cart.
|
||||
* - (path) provider_id=* {string} The id of the payment provider.
|
||||
* - (body) provider_id=* {string} The id of the Payment Provider responsible for the Payment Session to update.
|
||||
* - (body) data=* {object} The data to update the payment session with.
|
||||
* tags:
|
||||
@@ -23,10 +24,10 @@ import { defaultFields, defaultRelations } from "./"
|
||||
* $ref: "#/components/schemas/cart"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
const { id, provider_id } = req.params
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
session: Validator.object().required(),
|
||||
data: Validator.object().required(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -37,7 +38,8 @@ export default async (req, res) => {
|
||||
try {
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
|
||||
await cartService.updatePaymentSession(id, value.session)
|
||||
await cartService.setPaymentSession(id, provider_id)
|
||||
await cartService.updatePaymentSession(id, value.data)
|
||||
|
||||
const cart = await cartService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
|
||||
Reference in New Issue
Block a user