Merge pull request #271 from medusajs/fix/mp

Fix/mp
This commit is contained in:
Sebastian Rindom authored and GitHub committed 2021-06-22 10:38:44 +02:00
commit db9d6c0cf5
16 files changed
+82 -501

No files matched your search

@@ -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,
@@ -323,6 +323,9 @@ export const CartServiceMock = {
applyDiscount: jest.fn().mockImplementation((cartId, code) => {
return Promise.resolve()
}),
setPaymentSession: jest.fn().mockImplementation(cartId => {
return Promise.resolve()
}),
setPaymentSessions: jest.fn().mockImplementation(cartId => {
return Promise.resolve()
}),
+3 -3
View File
@@ -467,9 +467,9 @@ class OrderService extends BaseService {
)
}
const paymentStatus = await this.paymentProviderService_.getStatus(
payment
)
const paymentStatus = await this.paymentProviderService_
.withTransaction(manager)
.getStatus(payment)
// If payment status is not authorized, we throw
if (paymentStatus !== "authorized" && paymentStatus !== "succeeded") {