feature: swaps (#137)
* feat: swap schema * chore(refactor): move returns to separate service * swap order creates return * fix: adds returns/fulfillments/shipments and cart creation to swaps * search products by variants * feat: swaps ready * fix: test passing * chore: include customer expand fields on order * add tests * fix: add brightpearl plugin support * fix: adds swap link template setting * fix: tests * fix(medusa-plugin-brightpearl): add swap status option * docs: add swap description * fix: adds GET swap in store api * chore: unmock axios * fix: passing klarna tests * fix: pr
This commit is contained in:
@@ -48,10 +48,13 @@ export default (rootDirectory) => {
|
||||
"/webshipper/shipments",
|
||||
bodyParser.raw({ type: "application/vnd.api+json" }),
|
||||
async (req, res) => {
|
||||
const webshipperService = req.scope.resolve(
|
||||
"webshipperFulfillmentService"
|
||||
)
|
||||
const eventBus = req.scope.resolve("eventBusService")
|
||||
const logger = req.scope.resolve("logger")
|
||||
|
||||
const secret = `da791d87513eb091640f9fb6c4b94384`
|
||||
const secret = webshipperService.options_.webhook_secret
|
||||
const hmac = crypto.createHmac("sha256", secret)
|
||||
const digest = hmac.update(req.body).digest("base64")
|
||||
const hash = req.header("x-webshipper-hmac-sha256")
|
||||
|
||||
@@ -4,12 +4,13 @@ import Webshipper from "../utils/webshipper"
|
||||
class WebshipperFulfillmentService extends FulfillmentService {
|
||||
static identifier = "webshipper"
|
||||
|
||||
constructor({ logger, orderService }, options) {
|
||||
constructor({ logger, swapService, orderService }, options) {
|
||||
super()
|
||||
|
||||
this.logger_ = logger
|
||||
this.orderService_ = orderService
|
||||
this.options_ = options
|
||||
this.swapService_ = swapService
|
||||
this.client_ = new Webshipper({
|
||||
account: this.options_.account,
|
||||
token: this.options_.api_token,
|
||||
@@ -227,15 +228,23 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
})
|
||||
}
|
||||
|
||||
let visible_ref = `${fromOrder.display_id}-${
|
||||
fromOrder.fulfillments.length + 1
|
||||
}`
|
||||
let ext_ref = `${fromOrder._id}.${fromOrder.fulfillments.length}`
|
||||
|
||||
if (fromOrder.is_swap) {
|
||||
ext_ref = `S${fromOrder._id}.${fromOrder.fulfillments.length}`
|
||||
visible_ref = `S-${fromOrder.display_id}`
|
||||
}
|
||||
|
||||
const { shipping_address } = fromOrder
|
||||
const newOrder = {
|
||||
type: "orders",
|
||||
attributes: {
|
||||
status: "pending",
|
||||
ext_ref: `${fromOrder._id}.${fromOrder.fulfillments.length}`,
|
||||
visible_ref: `${fromOrder.display_id}-${
|
||||
fromOrder.fulfillments.length + 1
|
||||
}`,
|
||||
ext_ref,
|
||||
visible_ref,
|
||||
order_lines: fulfillmentItems.map((item) => {
|
||||
return {
|
||||
ext_ref: item._id,
|
||||
@@ -325,14 +334,24 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
"."
|
||||
)
|
||||
|
||||
const order = await this.orderService_.retrieve(orderId)
|
||||
const fulfillment = order.fulfillments[fulfillmentIndex]
|
||||
if (fulfillment) {
|
||||
await this.orderService_.createShipment(
|
||||
order._id,
|
||||
if (orderId.charAt(0) === "S") {
|
||||
const swap = await this.swapService_.retrieve(orderId.substring(1))
|
||||
const fulfillment = swap.fulfillments[fulfillmentIndex]
|
||||
await this.swapService_.createShipment(
|
||||
swap._id,
|
||||
fulfillment._id,
|
||||
trackingNumbers
|
||||
)
|
||||
} else {
|
||||
const order = await this.orderService_.retrieve(orderId)
|
||||
const fulfillment = order.fulfillments[fulfillmentIndex]
|
||||
if (fulfillment) {
|
||||
await this.orderService_.createShipment(
|
||||
order._id,
|
||||
fulfillment._id,
|
||||
trackingNumbers
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user