Klarna clean up
This commit is contained in:
@@ -16,7 +16,7 @@ export default () => {
|
||||
break
|
||||
case MedusaError.Types.DB_ERROR:
|
||||
statusCode = 500
|
||||
logger.error(err)
|
||||
console.log(err)
|
||||
break
|
||||
default:
|
||||
break
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const order = await orderService.completeOrder(id)
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ export default async (req, res) => {
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const order = await orderService.retrieve(id)
|
||||
|
||||
let order = await orderService.retrieve(id)
|
||||
order = await orderService.decorate(order, [], ["region"])
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
|
||||
@@ -11,6 +11,10 @@ export default app => {
|
||||
|
||||
route.post("/", middlewares.wrap(require("./create-order").default))
|
||||
route.post("/:id", middlewares.wrap(require("./update-order").default))
|
||||
route.post(
|
||||
"/:id/complete",
|
||||
middlewares.wrap(require("./complete-order").default)
|
||||
)
|
||||
|
||||
route.post(
|
||||
"/:id/capture",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id, code } = req.params
|
||||
|
||||
try {
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
|
||||
let cart = await cartService.removeDiscount(id, code)
|
||||
cart = await cartService.decorate(cart, [], ["region"])
|
||||
|
||||
res.status(200).json({ cart })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,11 @@ export default app => {
|
||||
middlewares.wrap(require("./delete-line-item").default)
|
||||
)
|
||||
|
||||
route.delete(
|
||||
"/:id/discounts/:code",
|
||||
middlewares.wrap(require("./delete-discount").default)
|
||||
)
|
||||
|
||||
// Payment sessions
|
||||
route.post(
|
||||
"/:id/payment-sessions",
|
||||
|
||||
@@ -51,7 +51,7 @@ export default async (req, res) => {
|
||||
if (value.discounts && value.discounts.length) {
|
||||
await Promise.all(
|
||||
value.discounts.map(async ({ code }) =>
|
||||
cartService.applyPromoCode(id, code)
|
||||
cartService.applyDiscount(id, code)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ export default async (req, res) => {
|
||||
const { id, line_id } = req.params
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
variant_id: Validator.objectId().required(),
|
||||
quantity: Validator.number().required(),
|
||||
})
|
||||
|
||||
@@ -16,15 +15,23 @@ export default async (req, res) => {
|
||||
try {
|
||||
const lineItemService = req.scope.resolve("lineItemService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
let cart = await cartService.retrieve(id)
|
||||
|
||||
const lineItem = await lineItemService.generate(
|
||||
value.variant_id,
|
||||
value.quantity,
|
||||
cart.region_id
|
||||
)
|
||||
let cart
|
||||
if (value.quantity === 0) {
|
||||
cart = await cartService.removeLineItem(id, line_id)
|
||||
} else {
|
||||
cart = await cartService.retrieve(id)
|
||||
|
||||
const existing = cart.items.find(i => i._id.equals(line_id))
|
||||
const lineItem = await lineItemService.generate(
|
||||
existing.content.variant._id,
|
||||
cart.region_id,
|
||||
value.quantity
|
||||
)
|
||||
|
||||
cart = await cartService.updateLineItem(cart._id, line_id, lineItem)
|
||||
}
|
||||
|
||||
cart = await cartService.updateLineItem(cart._id, line_id, lineItem)
|
||||
cart = await cartService.decorate(cart, [], ["region"])
|
||||
|
||||
res.status(200).json({ cart })
|
||||
|
||||
@@ -5,6 +5,7 @@ export default async (req, res) => {
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
provider_id: Validator.string().required(),
|
||||
data: Validator.object().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -15,13 +16,7 @@ export default async (req, res) => {
|
||||
try {
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
|
||||
const session = await cartService.retrievePaymentSession(
|
||||
id,
|
||||
value.provider_id
|
||||
)
|
||||
await cartService.setPaymentMethod(id, session)
|
||||
|
||||
let cart = await cartService.retrieve(id)
|
||||
let cart = await cartService.setPaymentMethod(id, value)
|
||||
cart = await cartService.decorate(cart, [], ["region"])
|
||||
|
||||
res.status(200).json({ cart })
|
||||
|
||||
@@ -16,6 +16,8 @@ export default async (req, res) => {
|
||||
|
||||
const cart = await cartService.retrieve(value.cartId)
|
||||
let order = await orderService.createFromCart(cart)
|
||||
|
||||
order = await orderService.retrieveByCartId(value.cartId)
|
||||
order = await orderService.decorate(order, [
|
||||
"status",
|
||||
"fulfillment_status",
|
||||
|
||||
@@ -4,21 +4,25 @@ export default async (req, res) => {
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
let order = await orderService.retrieve(id)
|
||||
order = await orderService.decorate(order, [
|
||||
"status",
|
||||
"fulfillment_status",
|
||||
"payment_status",
|
||||
"email",
|
||||
"billing_address",
|
||||
"shipping_address",
|
||||
"items",
|
||||
"region",
|
||||
"discounts",
|
||||
"customer_id",
|
||||
"payment_method",
|
||||
"shipping_methods",
|
||||
"metadata",
|
||||
])
|
||||
order = await orderService.decorate(
|
||||
order,
|
||||
[
|
||||
"status",
|
||||
"fulfillment_status",
|
||||
"payment_status",
|
||||
"email",
|
||||
"billing_address",
|
||||
"shipping_address",
|
||||
"items",
|
||||
"region",
|
||||
"discounts",
|
||||
"customer_id",
|
||||
"payment_method",
|
||||
"shipping_methods",
|
||||
"metadata",
|
||||
],
|
||||
["region"]
|
||||
)
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user