chore: merge develop
This commit is contained in:
@@ -100,11 +100,12 @@ describe("/admin/orders", () => {
|
||||
await manager.query(`DELETE FROM "fulfillment_item"`);
|
||||
await manager.query(`DELETE FROM "fulfillment"`);
|
||||
await manager.query(`DELETE FROM "swap"`);
|
||||
await manager.query(`DELETE FROM "return"`);
|
||||
await manager.query(`DELETE FROM "claim_image"`);
|
||||
await manager.query(`DELETE FROM "claim_tag"`);
|
||||
await manager.query(`DELETE FROM "claim_item"`);
|
||||
await manager.query(`DELETE FROM "shipping_method"`);
|
||||
await manager.query(`DELETE FROM "return_item"`);
|
||||
await manager.query(`DELETE FROM "return"`);
|
||||
await manager.query(`DELETE FROM "line_item"`);
|
||||
await manager.query(`DELETE FROM "claim_order"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
@@ -178,6 +179,72 @@ describe("/admin/orders", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("creates a claim with return shipping", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/orders/test-order/claims",
|
||||
{
|
||||
type: "replace",
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason: "production_failure",
|
||||
tags: ["fluff"],
|
||||
images: ["https://test.image.com"],
|
||||
},
|
||||
],
|
||||
additional_items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
return_shipping: { option_id: "test-return-option", price: 0 },
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data.order.claims[0].claim_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason: "production_failure",
|
||||
images: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
url: "https://test.image.com",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
);
|
||||
|
||||
expect(response.data.order.claims[0].additional_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
}),
|
||||
])
|
||||
);
|
||||
|
||||
expect(
|
||||
response.data.order.claims[0].return_order.shipping_method
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
price: 0,
|
||||
shipping_option_id: "test-return-option",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("updates a claim", async () => {
|
||||
const api = useApi();
|
||||
|
||||
|
||||
@@ -14,6 +14,19 @@ describe("/store/carts", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
const doAfterEach = async (manager) => {
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "shipping_method"`);
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
@@ -43,13 +56,7 @@ describe("/store/carts", () => {
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await doAfterEach(manager);
|
||||
});
|
||||
|
||||
it("creates a cart", async () => {
|
||||
@@ -108,14 +115,7 @@ describe("/store/carts", () => {
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await doAfterEach(manager);
|
||||
});
|
||||
|
||||
it("fails on apply discount if limit has been reached", async () => {
|
||||
@@ -142,6 +142,73 @@ describe("/store/carts", () => {
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
});
|
||||
|
||||
it("adds free shipping to cart then removes it again", async () => {
|
||||
const api = useApi();
|
||||
|
||||
let cart = await api.post(
|
||||
"/store/carts/test-cart",
|
||||
{
|
||||
discounts: [{ code: "FREE_SHIPPING" }, { code: "CREATED" }],
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
expect(cart.data.cart.shipping_total).toBe(0);
|
||||
expect(cart.status).toEqual(200);
|
||||
|
||||
cart = await api.post(
|
||||
"/store/carts/test-cart",
|
||||
{
|
||||
discounts: [{ code: "CREATED" }],
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
expect(cart.data.cart.shipping_total).toBe(1000);
|
||||
expect(cart.status).toEqual(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe("DELETE /store/carts/:id/discounts/:code", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection);
|
||||
await dbConnection.manager.query(
|
||||
`INSERT INTO "cart_discounts" (cart_id, discount_id) VALUES ('test-cart', 'free-shipping')`
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await doAfterEach(manager);
|
||||
});
|
||||
|
||||
it("removes free shipping and updates shipping total", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const cartWithFreeShipping = await api.post(
|
||||
"/store/carts/test-cart",
|
||||
{
|
||||
discounts: [{ code: "FREE_SHIPPING" }],
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
expect(cartWithFreeShipping.data.cart.shipping_total).toBe(0);
|
||||
expect(cartWithFreeShipping.status).toEqual(200);
|
||||
|
||||
const response = await api.delete(
|
||||
"/store/carts/test-cart/discounts/FREE_SHIPPING"
|
||||
);
|
||||
|
||||
expect(response.data.cart.shipping_total).toBe(1000);
|
||||
expect(response.status).toEqual(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe("get-cart with session customer", () => {
|
||||
@@ -156,14 +223,7 @@ describe("/store/carts", () => {
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await doAfterEach(manager);
|
||||
});
|
||||
|
||||
it("updates empty cart.customer_id on cart retrieval", async () => {
|
||||
|
||||
@@ -4,11 +4,18 @@ const {
|
||||
Cart,
|
||||
DiscountRule,
|
||||
Discount,
|
||||
ShippingProfile,
|
||||
ShippingOption,
|
||||
ShippingMethod,
|
||||
} = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
});
|
||||
|
||||
const r = manager.create(Region, {
|
||||
id: "test-region",
|
||||
name: "Test Region",
|
||||
@@ -16,24 +23,26 @@ module.exports = async (connection, data = {}) => {
|
||||
tax_rate: 0,
|
||||
});
|
||||
|
||||
await manager.insert(DiscountRule, {
|
||||
id: "test-discount-rule",
|
||||
description: "Dynamic rule",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
const freeRule = manager.create(DiscountRule, {
|
||||
id: "free-shipping-rule",
|
||||
description: "Free shipping rule",
|
||||
type: "free_shipping",
|
||||
value: 100,
|
||||
allocation: "total",
|
||||
});
|
||||
|
||||
await manager.insert(Discount, {
|
||||
id: "test-discount",
|
||||
code: "DYNAMIC",
|
||||
rule_id: "test-discount-rule",
|
||||
is_dynamic: true,
|
||||
usage_count: 0,
|
||||
usage_limit: 1,
|
||||
const freeDisc = manager.create(Discount, {
|
||||
id: "free-shipping",
|
||||
code: "FREE_SHIPPING",
|
||||
is_dynamic: false,
|
||||
is_disabled: false,
|
||||
});
|
||||
|
||||
freeDisc.regions = [r];
|
||||
freeDisc.rule = freeRule;
|
||||
|
||||
await manager.save(freeDisc);
|
||||
|
||||
const d = await manager.create(Discount, {
|
||||
id: "test-discount",
|
||||
code: "CREATED",
|
||||
@@ -73,6 +82,17 @@ module.exports = async (connection, data = {}) => {
|
||||
email: "some-customer@email.com",
|
||||
});
|
||||
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "test-option",
|
||||
name: "test-option",
|
||||
provider_id: "test-ful",
|
||||
region_id: "test-region",
|
||||
profile_id: defaultProfile.id,
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
data: {},
|
||||
});
|
||||
|
||||
const cart = manager.create(Cart, {
|
||||
id: "test-cart",
|
||||
customer_id: "some-customer",
|
||||
@@ -88,4 +108,12 @@ module.exports = async (connection, data = {}) => {
|
||||
});
|
||||
|
||||
await manager.save(cart);
|
||||
|
||||
await manager.insert(ShippingMethod, {
|
||||
id: "test-method",
|
||||
shipping_option_id: "test-option",
|
||||
cart_id: "test-cart",
|
||||
price: 1000,
|
||||
data: {},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -94,6 +94,18 @@ module.exports = async (connection, data = {}) => {
|
||||
data: {},
|
||||
});
|
||||
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "test-return-option",
|
||||
name: "Test ret",
|
||||
profile_id: defaultProfile.id,
|
||||
region_id: "test-region",
|
||||
provider_id: "test-ful",
|
||||
data: {},
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
is_return: true,
|
||||
});
|
||||
|
||||
const order = manager.create(Order, {
|
||||
id: "test-order",
|
||||
customer_id: "test-customer",
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.3](https://github.com/medusajs/medusa/compare/babel-preset-medusa-package@1.1.0...babel-preset-medusa-package@1.1.3) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package babel-preset-medusa-package
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.2](https://github.com/medusajs/medusa/compare/babel-preset-medusa-package@1.1.1...babel-preset-medusa-package@1.1.2) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package babel-preset-medusa-package
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-preset-medusa-package",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"author": "Sebastian Rindom <sebastian@mrbltech.com>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
.env
|
||||
dist/
|
||||
node_modules/
|
||||
|
||||
.env
|
||||
|
||||
@@ -3,3 +3,4 @@ src
|
||||
.eslintrc
|
||||
.gitignore
|
||||
.prettierrc
|
||||
.env
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.8](https://github.com/medusajs/medusa/compare/@medusajs/medusa-cli@1.1.7...@medusajs/medusa-cli@1.1.8) (2021-05-05)
|
||||
|
||||
**Note:** Version bump only for package @medusajs/medusa-cli
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.7](https://github.com/medusajs/medusa/compare/@medusajs/medusa-cli@1.1.4...@medusajs/medusa-cli@1.1.7) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package @medusajs/medusa-cli
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.6](https://github.com/medusajs/medusa/compare/@medusajs/medusa-cli@1.1.5...@medusajs/medusa-cli@1.1.6) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package @medusajs/medusa-cli
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@medusajs/medusa-cli",
|
||||
"version": "1.1.6",
|
||||
"version": "1.1.8",
|
||||
"description": "Command Line interface for Medusa Commerce",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.9](https://github.com/medusajs/medusa/compare/medusa-core-utils@1.1.6...medusa-core-utils@1.1.9) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-core-utils
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.8](https://github.com/medusajs/medusa/compare/medusa-core-utils@1.1.7...medusa-core-utils@1.1.8) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-core-utils
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-core-utils",
|
||||
"version": "1.1.8",
|
||||
"version": "1.1.9",
|
||||
"description": "Core utils for Medusa",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [0.0.8](https://github.com/medusajs/medusa/compare/medusa-dev-cli@0.0.5...medusa-dev-cli@0.0.8) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-dev-cli
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [0.0.7](https://github.com/medusajs/medusa/compare/medusa-dev-cli@0.0.6...medusa-dev-cli@0.0.7) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-dev-cli
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "medusa-dev-cli",
|
||||
"description": "CLI helpers for contributors working on Medusa",
|
||||
"version": "0.0.7",
|
||||
"version": "0.0.8",
|
||||
"author": "Sebastian Rindom <skrindom@gmail.com>",
|
||||
"bin": {
|
||||
"medusa-dev": "./dist/index.js"
|
||||
@@ -24,7 +24,7 @@
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.1",
|
||||
"@babel/core": "^7.12.3",
|
||||
"babel-preset-medusa-package": "^1.1.2",
|
||||
"babel-preset-medusa-package": "^1.1.3",
|
||||
"cross-env": "^7.0.3"
|
||||
},
|
||||
"homepage": "https://github.com/medusajs/medusa/tree/master/packages/medusa-dev-cli#readme",
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-file-spaces@1.1.9...medusa-file-spaces@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-file-spaces
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-file-spaces@1.1.10...medusa-file-spaces@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-file-spaces
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-file-spaces",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Digital Ocean Spaces file connector for Medusa",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -40,8 +40,8 @@
|
||||
"aws-sdk": "^2.710.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"stripe": "^8.50.0"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.9](https://github.com/medusajs/medusa/compare/medusa-fulfillment-manual@1.1.6...medusa-fulfillment-manual@1.1.9) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-fulfillment-manual
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.8](https://github.com/medusajs/medusa/compare/medusa-fulfillment-manual@1.1.7...medusa-fulfillment-manual@1.1.8) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-fulfillment-manual
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-fulfillment-manual",
|
||||
"version": "1.1.8",
|
||||
"version": "1.1.9",
|
||||
"description": "A manual fulfillment provider for Medusa",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -36,7 +36,7 @@
|
||||
"@babel/plugin-transform-instanceof": "^7.8.3",
|
||||
"@babel/runtime": "^7.7.6",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8"
|
||||
"medusa-core-utils": "^1.1.9"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.13](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.12...medusa-fulfillment-webshipper@1.1.13) (2021-05-05)
|
||||
|
||||
**Note:** Version bump only for package medusa-fulfillment-webshipper
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.9...medusa-fulfillment-webshipper@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-fulfillment-webshipper
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.10...medusa-fulfillment-webshipper@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-fulfillment-webshipper
|
||||
|
||||
@@ -12,4 +12,5 @@ A webhook listener is exposed at `/webshipper/shipments` to listen for shipment
|
||||
api_token: [a webshipper api token] (required)
|
||||
order_channel_id: [the channel id to register orders on] (required)
|
||||
webhook_secret: [the webhook secret used to listen for shipments] (required)
|
||||
coo_countries: [an array of countries in which a Certificate of Origin will be attached] (default: "all")
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-fulfillment-webshipper",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.13",
|
||||
"description": "Webshipper Fulfillment provider for Medusa",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -37,7 +37,7 @@
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8"
|
||||
"medusa-core-utils": "^1.1.9"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -9,6 +9,16 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
|
||||
this.options_ = options
|
||||
|
||||
if (!options.coo_countries) {
|
||||
this.options_.coo_countries = ["all"]
|
||||
} else if (Array.isArray(options.coo_countries)) {
|
||||
this.options_.coo_countries = options.coo_countries.map((c) =>
|
||||
c.toLowerCase()
|
||||
)
|
||||
} else if (typeof options.coo_countries === "string") {
|
||||
this.options_.coo_countries = [options.coo_countries]
|
||||
}
|
||||
|
||||
/** @private @const {logger} */
|
||||
this.logger_ = logger
|
||||
|
||||
@@ -242,6 +252,8 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
webshipperOrder = await this.client_.orders.retrieve(existing)
|
||||
}
|
||||
|
||||
const { shipping_address } = fromOrder
|
||||
|
||||
if (!webshipperOrder) {
|
||||
let invoice
|
||||
let certificateOfOrigin
|
||||
@@ -266,7 +278,14 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
throw err
|
||||
})
|
||||
|
||||
if (this.invoiceGenerator_.createCertificateOfOrigin) {
|
||||
const cooCountries = this.options_.coo_countries
|
||||
if (
|
||||
(cooCountries.includes("all") ||
|
||||
cooCountries.includes(
|
||||
shipping_address.country_code.toLowerCase()
|
||||
)) &&
|
||||
this.invoiceGenerator_.createCertificateOfOrigin
|
||||
) {
|
||||
const base64Coo = await this.invoiceGenerator_.createCertificateOfOrigin(
|
||||
fromOrder,
|
||||
fulfillmentItems
|
||||
@@ -297,7 +316,6 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
||||
visible_ref = `S-${fromOrder.display_id}`
|
||||
}
|
||||
|
||||
const { shipping_address } = fromOrder
|
||||
const newOrder = {
|
||||
type: "orders",
|
||||
attributes: {
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.10](https://github.com/medusajs/medusa/compare/medusa-interfaces@1.1.7...medusa-interfaces@1.1.10) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-interfaces
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.9](https://github.com/medusajs/medusa/compare/medusa-interfaces@1.1.8...medusa-interfaces@1.1.9) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-interfaces
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-interfaces",
|
||||
"version": "1.1.9",
|
||||
"version": "1.1.10",
|
||||
"description": "Core interfaces for Medusa",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
@@ -35,7 +35,7 @@
|
||||
"typeorm": "0.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"medusa-core-utils": "^1.1.8"
|
||||
"medusa-core-utils": "^1.1.9"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-payment-adyen@1.1.9...medusa-payment-adyen@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-adyen
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-payment-adyen@1.1.10...medusa-payment-adyen@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-adyen
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-payment-adyen",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Adyen Payment provider for Medusa Commerce",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -24,7 +24,7 @@
|
||||
"cross-env": "^7.0.2",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^25.5.2",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src -d .",
|
||||
@@ -42,7 +42,7 @@
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8"
|
||||
"medusa-core-utils": "^1.1.9"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.13](https://github.com/medusajs/medusa/compare/medusa-payment-klarna@1.1.10...medusa-payment-klarna@1.1.13) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-klarna
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-payment-klarna@1.1.11...medusa-payment-klarna@1.1.12) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-klarna
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-payment-klarna",
|
||||
"version": "1.1.12",
|
||||
"version": "1.1.13",
|
||||
"description": "Klarna Payment provider for Medusa Commerce",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -40,8 +40,8 @@
|
||||
"axios": "^0.21.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.0.13](https://github.com/medusajs/medusa/compare/medusa-payment-paypal@1.0.12...medusa-payment-paypal@1.0.13) (2021-04-29)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-paypal
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.0.12](https://github.com/medusajs/medusa/compare/medusa-payment-paypal@1.0.9...medusa-payment-paypal@1.0.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-paypal
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.0.11](https://github.com/medusajs/medusa/compare/medusa-payment-paypal@1.0.10...medusa-payment-paypal@1.0.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-paypal
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-payment-paypal",
|
||||
"version": "1.0.11",
|
||||
"version": "1.0.13",
|
||||
"description": "Paypal Payment provider for Meduas Commerce",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -26,12 +26,13 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^25.5.2",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-interfaces": "^1.1.10",
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src -d . --ignore **/__tests__",
|
||||
"build": "babel src -d . --ignore **/__tests__,**/__mocks__",
|
||||
"prepare": "cross-env NODE_ENV=production npm run build",
|
||||
"watch": "babel -w src --out-dir . --ignore **/__tests__",
|
||||
"watch": "babel -w src --out-dir . --ignore **/__tests__,**/__mocks__",
|
||||
"test": "jest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
@@ -41,7 +42,7 @@
|
||||
"@paypal/checkout-server-sdk": "^1.0.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8"
|
||||
"medusa-core-utils": "^1.1.9"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
export const PayPalClientMock = {
|
||||
execute: jest.fn().mockImplementation((r) => {
|
||||
return {
|
||||
result: r.result,
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
export const PayPalMock = {
|
||||
core: {
|
||||
SandboxEnvironment: function () {
|
||||
this.env = {
|
||||
sandbox: true,
|
||||
live: false,
|
||||
}
|
||||
},
|
||||
LiveEnvironment: function () {
|
||||
this.env = {
|
||||
sandbox: false,
|
||||
live: true,
|
||||
}
|
||||
},
|
||||
PayPalHttpClient: function () {
|
||||
return PayPalClientMock
|
||||
},
|
||||
},
|
||||
|
||||
payments: {
|
||||
AuthorizationsGetRequest: jest.fn().mockImplementation(() => {}),
|
||||
AuthorizationsVoidRequest: jest.fn().mockImplementation(() => {}),
|
||||
AuthorizationsCaptureRequest: jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
result: {
|
||||
id: "test",
|
||||
},
|
||||
capture: true,
|
||||
}
|
||||
}),
|
||||
CapturesRefundRequest: jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
result: {
|
||||
id: "test",
|
||||
},
|
||||
body: null,
|
||||
requestBody: function (d) {
|
||||
this.body = d
|
||||
},
|
||||
}
|
||||
}),
|
||||
},
|
||||
|
||||
orders: {
|
||||
OrdersCreateRequest: jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
result: {
|
||||
id: "test",
|
||||
},
|
||||
order: true,
|
||||
body: null,
|
||||
requestBody: function (d) {
|
||||
this.body = d
|
||||
},
|
||||
}
|
||||
}),
|
||||
OrdersPatchRequest: jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
result: {
|
||||
id: "test",
|
||||
},
|
||||
order: true,
|
||||
body: null,
|
||||
requestBody: function (d) {
|
||||
this.body = d
|
||||
},
|
||||
}
|
||||
}),
|
||||
OrdersGetRequest: jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
result: {
|
||||
id: "test",
|
||||
},
|
||||
}
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
export default PayPalMock
|
||||
@@ -0,0 +1,346 @@
|
||||
import PayPalProviderService from "../paypal-provider"
|
||||
import {
|
||||
PayPalMock,
|
||||
PayPalClientMock,
|
||||
} from "../../__mocks__/@paypal/checkout-server-sdk"
|
||||
|
||||
const TotalsServiceMock = {
|
||||
getTotal: jest.fn().mockImplementation((c) => c.total),
|
||||
}
|
||||
|
||||
const RegionServiceMock = {
|
||||
retrieve: jest.fn().mockImplementation((id) =>
|
||||
Promise.resolve({
|
||||
currency_code: "eur",
|
||||
})
|
||||
),
|
||||
}
|
||||
|
||||
describe("PaypalProviderService", () => {
|
||||
describe("createPayment", () => {
|
||||
let result
|
||||
const paypalProviderService = new PayPalProviderService(
|
||||
{
|
||||
regionService: RegionServiceMock,
|
||||
totalsService: TotalsServiceMock,
|
||||
},
|
||||
{
|
||||
api_key: "test",
|
||||
}
|
||||
)
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("creates paypal order", async () => {
|
||||
result = await paypalProviderService.createPayment({
|
||||
id: "test_cart",
|
||||
region_id: "fr",
|
||||
total: 1000,
|
||||
})
|
||||
|
||||
expect(PayPalMock.orders.OrdersCreateRequest).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
order: true,
|
||||
body: {
|
||||
intent: "AUTHORIZE",
|
||||
application_context: {
|
||||
shipping_preference: "NO_SHIPPING",
|
||||
},
|
||||
purchase_units: [
|
||||
{
|
||||
custom_id: "test_cart",
|
||||
amount: {
|
||||
currency_code: "EUR",
|
||||
value: "10.00",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrievePayment", () => {
|
||||
let result
|
||||
const paypalProviderService = new PayPalProviderService(
|
||||
{
|
||||
regionService: RegionServiceMock,
|
||||
totalsService: TotalsServiceMock,
|
||||
},
|
||||
{
|
||||
api_key: "test",
|
||||
}
|
||||
)
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("retrieves paypal order", async () => {
|
||||
result = await paypalProviderService.retrievePayment({ id: "test" })
|
||||
expect(PayPalMock.orders.OrdersGetRequest).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalMock.orders.OrdersGetRequest).toHaveBeenCalledWith("test")
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(1)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
})
|
||||
|
||||
describe("updatePayment", () => {
|
||||
let result
|
||||
const paypalProviderService = new PayPalProviderService(
|
||||
{
|
||||
regionService: RegionServiceMock,
|
||||
totalsService: TotalsServiceMock,
|
||||
},
|
||||
{
|
||||
api_key: "test",
|
||||
}
|
||||
)
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("updates paypal order", async () => {
|
||||
result = await paypalProviderService.updatePayment(
|
||||
{ id: "test" },
|
||||
{
|
||||
id: "test_cart",
|
||||
region_id: "fr",
|
||||
total: 1000,
|
||||
}
|
||||
)
|
||||
|
||||
expect(PayPalMock.orders.OrdersPatchRequest).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalMock.orders.OrdersPatchRequest).toHaveBeenCalledWith("test")
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(1)
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
order: true,
|
||||
body: [
|
||||
{
|
||||
op: "replace",
|
||||
path: "/purchase_units/@reference_id=='default'",
|
||||
value: {
|
||||
amount: {
|
||||
currency_code: "EUR",
|
||||
value: "10.00",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
})
|
||||
|
||||
describe("capturePayment", () => {
|
||||
let result
|
||||
const paypalProviderService = new PayPalProviderService(
|
||||
{
|
||||
regionService: RegionServiceMock,
|
||||
totalsService: TotalsServiceMock,
|
||||
},
|
||||
{
|
||||
api_key: "test",
|
||||
}
|
||||
)
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("updates paypal order", async () => {
|
||||
result = await paypalProviderService.capturePayment({
|
||||
data: {
|
||||
id: "test",
|
||||
purchase_units: [
|
||||
{
|
||||
payments: {
|
||||
authorizations: [
|
||||
{
|
||||
id: "test_auth",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
expect(
|
||||
PayPalMock.payments.AuthorizationsCaptureRequest
|
||||
).toHaveBeenCalledTimes(1)
|
||||
expect(
|
||||
PayPalMock.payments.AuthorizationsCaptureRequest
|
||||
).toHaveBeenCalledWith("test_auth")
|
||||
expect(PayPalMock.orders.OrdersGetRequest).toHaveBeenCalledWith("test")
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(2)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
})
|
||||
|
||||
describe("refundPayment", () => {
|
||||
let result
|
||||
const paypalProviderService = new PayPalProviderService(
|
||||
{
|
||||
regionService: RegionServiceMock,
|
||||
totalsService: TotalsServiceMock,
|
||||
},
|
||||
{
|
||||
api_key: "test",
|
||||
}
|
||||
)
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("refunds payment", async () => {
|
||||
result = await paypalProviderService.refundPayment(
|
||||
{
|
||||
currency_code: "eur",
|
||||
data: {
|
||||
id: "test",
|
||||
purchase_units: [
|
||||
{
|
||||
payments: {
|
||||
captures: [
|
||||
{
|
||||
id: "test_cap",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
2000
|
||||
)
|
||||
|
||||
expect(PayPalMock.payments.CapturesRefundRequest).toHaveBeenCalledWith(
|
||||
"test_cap"
|
||||
)
|
||||
expect(PayPalMock.orders.OrdersGetRequest).toHaveBeenCalledWith("test")
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(2)
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: {
|
||||
amount: {
|
||||
currency_code: "EUR",
|
||||
value: "20.00",
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
|
||||
it("doesn't refund without captures", async () => {
|
||||
await expect(
|
||||
paypalProviderService.refundPayment(
|
||||
{
|
||||
currency_code: "eur",
|
||||
data: {
|
||||
id: "test",
|
||||
purchase_units: [
|
||||
{
|
||||
payments: {
|
||||
captures: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
2000
|
||||
)
|
||||
).rejects.toThrow("Order not yet captured")
|
||||
})
|
||||
})
|
||||
|
||||
describe("cancelPayment", () => {
|
||||
let result
|
||||
const paypalProviderService = new PayPalProviderService(
|
||||
{
|
||||
regionService: RegionServiceMock,
|
||||
totalsService: TotalsServiceMock,
|
||||
},
|
||||
{
|
||||
api_key: "test",
|
||||
}
|
||||
)
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("refunds if captured", async () => {
|
||||
result = await paypalProviderService.cancelPayment({
|
||||
captured_at: "true",
|
||||
currency_code: "eur",
|
||||
data: {
|
||||
id: "test",
|
||||
purchase_units: [
|
||||
{
|
||||
payments: {
|
||||
captures: [
|
||||
{
|
||||
id: "test_cap",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
expect(PayPalMock.payments.CapturesRefundRequest).toHaveBeenCalledWith(
|
||||
"test_cap"
|
||||
)
|
||||
expect(PayPalMock.orders.OrdersGetRequest).toHaveBeenCalledWith("test")
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(2)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
|
||||
it("voids if not captured", async () => {
|
||||
result = await paypalProviderService.cancelPayment({
|
||||
currency_code: "eur",
|
||||
data: {
|
||||
id: "test",
|
||||
purchase_units: [
|
||||
{
|
||||
payments: {
|
||||
authorizations: [
|
||||
{
|
||||
id: "test_auth",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
expect(
|
||||
PayPalMock.payments.AuthorizationsVoidRequest
|
||||
).toHaveBeenCalledWith("test_auth")
|
||||
expect(PayPalMock.orders.OrdersGetRequest).toHaveBeenCalledWith("test")
|
||||
expect(PayPalClientMock.execute).toHaveBeenCalledTimes(2)
|
||||
|
||||
expect(result.id).toEqual("test")
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -5,7 +5,7 @@ import { PaymentService } from "medusa-interfaces"
|
||||
class PayPalProviderService extends PaymentService {
|
||||
static identifier = "paypal"
|
||||
|
||||
constructor({ customerService, totalsService, regionService }, options) {
|
||||
constructor({ totalsService, regionService }, options) {
|
||||
super()
|
||||
|
||||
/**
|
||||
@@ -35,9 +35,6 @@ class PayPalProviderService extends PaymentService {
|
||||
/** @private @const {PayPalHttpClient} */
|
||||
this.paypal_ = new PayPal.core.PayPalHttpClient(environment)
|
||||
|
||||
/** @private @const {CustomerService} */
|
||||
this.customerService_ = customerService
|
||||
|
||||
/** @private @const {RegionService} */
|
||||
this.regionService_ = regionService
|
||||
|
||||
@@ -196,7 +193,7 @@ class PayPalProviderService extends PaymentService {
|
||||
value: {
|
||||
amount: {
|
||||
currency_code: currency_code.toUpperCase(),
|
||||
value: (cart.total / 100).toFixed(),
|
||||
value: (cart.total / 100).toFixed(2),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -240,7 +237,7 @@ class PayPalProviderService extends PaymentService {
|
||||
* Refunds a given amount.
|
||||
* @param {object} payment - payment to refund
|
||||
* @param {number} amountToRefund - amount to refund
|
||||
* @returns {string} the resulting PayPal order
|
||||
* @returns {Promise<Object>} the resulting PayPal order
|
||||
*/
|
||||
async refundPayment(payment, amountToRefund) {
|
||||
const { purchase_units } = payment.data
|
||||
@@ -257,13 +254,13 @@ class PayPalProviderService extends PaymentService {
|
||||
request.requestBody({
|
||||
amount: {
|
||||
currency_code: payment.currency_code.toUpperCase(),
|
||||
value: (amountToRefund / 100).toFixed(),
|
||||
value: (amountToRefund / 100).toFixed(2),
|
||||
},
|
||||
})
|
||||
|
||||
await this.paypal_.execute(request)
|
||||
|
||||
return this.retrievePayment(payment.id)
|
||||
return this.retrievePayment(payment.data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
@@ -272,7 +269,7 @@ class PayPalProviderService extends PaymentService {
|
||||
/**
|
||||
* Cancels payment for Stripe payment intent.
|
||||
* @param {object} paymentData - payment method data from cart
|
||||
* @returns {object} canceled payment intent
|
||||
* @returns {Promise<object>} canceled payment intent
|
||||
*/
|
||||
async cancelPayment(payment) {
|
||||
try {
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-payment-stripe@1.1.9...medusa-payment-stripe@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-stripe
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-payment-stripe@1.1.10...medusa-payment-stripe@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-payment-stripe
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-payment-stripe",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Stripe Payment provider for Meduas Commerce",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -26,7 +26,7 @@
|
||||
"cross-env": "^5.2.1",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^25.5.2",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src -d . --ignore **/__tests__",
|
||||
@@ -40,7 +40,7 @@
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"stripe": "^8.50.0"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-add-ons@1.1.9...medusa-plugin-add-ons@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-add-ons
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-add-ons@1.1.10...medusa-plugin-add-ons@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-add-ons
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-add-ons",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Add-on plugin for Medusa Commerce",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -25,7 +25,7 @@
|
||||
"cross-env": "^7.0.2",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^25.5.2",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src -d . --ignore **/__tests__",
|
||||
@@ -37,7 +37,7 @@
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"redis": "^3.0.2"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.15](https://github.com/medusajs/medusa/compare/medusa-plugin-brightpearl@1.1.13...medusa-plugin-brightpearl@1.1.15) (2021-04-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* better inventory sync ([9eaf027](https://github.com/medusajs/medusa/commit/9eaf02762ff1ad455ac5020668ee9106db7c705a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.14](https://github.com/medusajs/medusa/compare/medusa-plugin-brightpearl@1.1.13...medusa-plugin-brightpearl@1.1.14) (2021-04-20)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-brightpearl",
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.15",
|
||||
"description": "Brightpearl plugin for Medusa Commerce",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -27,7 +27,7 @@
|
||||
"cross-env": "^7.0.2",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^25.5.2",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"prettier": "^2.0.5"
|
||||
},
|
||||
"scripts": {
|
||||
@@ -43,7 +43,7 @@
|
||||
"axios": "^0.19.2",
|
||||
"axios-rate-limit": "^1.2.1",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"randomatic": "^3.1.1"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -5,13 +5,9 @@ const inventorySync = async (container, options) => {
|
||||
const brightpearlService = container.resolve("brightpearlService")
|
||||
const eventBus = container.resolve("eventBusService")
|
||||
try {
|
||||
const client = await brightpearlService.getClient()
|
||||
const pattern = options.inventory_sync_cron
|
||||
eventBus.createCronJob(
|
||||
"inventory-sync",
|
||||
{},
|
||||
pattern,
|
||||
brightpearlService.syncInventory
|
||||
eventBus.createCronJob("inventory-sync", {}, pattern, () =>
|
||||
brightpearlService.syncInventory()
|
||||
)
|
||||
} catch (err) {
|
||||
if (err.name === "not_allowed") {
|
||||
|
||||
@@ -126,7 +126,6 @@ class BrightpearlService extends BaseService {
|
||||
|
||||
async syncInventory() {
|
||||
const client = await this.getClient()
|
||||
const variants = await this.productVariantService_.list()
|
||||
|
||||
let search = true
|
||||
let bpProducts = []
|
||||
@@ -141,31 +140,39 @@ class BrightpearlService extends BaseService {
|
||||
}
|
||||
|
||||
if (bpProducts.length) {
|
||||
const productRange = `${bpProducts[0].productId}-${
|
||||
bpProducts[bpProducts.length - 1].productId
|
||||
}`
|
||||
const productRange = bpProducts
|
||||
.map(({ productId }) => productId)
|
||||
.join(",")
|
||||
|
||||
const availabilities = await client.products.retrieveAvailability(
|
||||
productRange
|
||||
)
|
||||
|
||||
return Promise.all(
|
||||
variants.map(async (v) => {
|
||||
const brightpearlProduct = bpProducts.find(
|
||||
(prod) => prod.SKU === v.sku
|
||||
)
|
||||
if (!brightpearlProduct) {
|
||||
return
|
||||
bpProducts.map(async (bpProduct) => {
|
||||
const { SKU: sku, productId } = bpProduct
|
||||
|
||||
const variant = await this.productVariantService_
|
||||
.retrieveBySKU(sku, {
|
||||
select: ["id", "manage_inventory", "inventory_quantity"],
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
|
||||
const prodAvail = availabilities[productId]
|
||||
|
||||
let onHand = 0
|
||||
if (
|
||||
prodAvail &&
|
||||
prodAvail.warehouses &&
|
||||
prodAvail.warehouses[`${this.options.warehouse}`]
|
||||
) {
|
||||
onHand = prodAvail.warehouses[`${this.options.warehouse}`].onHand
|
||||
}
|
||||
|
||||
const { productId } = brightpearlProduct
|
||||
const availability = availabilities[productId]
|
||||
if (availability) {
|
||||
const onHand = availability.total.onHand
|
||||
|
||||
// Only update if the inventory levels have changed
|
||||
if (parseInt(v.inventory_quantity) !== parseInt(onHand)) {
|
||||
return this.productVariantService_.update(v.id, {
|
||||
inventory_quantity: onHand,
|
||||
if (variant && variant.manage_inventory) {
|
||||
if (parseInt(variant.inventory_quantity) !== parseInt(onHand)) {
|
||||
return this.productVariantService_.update(variant.id, {
|
||||
inventory_quantity: parseInt(onHand),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.13](https://github.com/medusajs/medusa/compare/medusa-plugin-contentful@1.1.10...medusa-plugin-contentful@1.1.13) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-contentful
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-contentful@1.1.11...medusa-plugin-contentful@1.1.12) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-contentful
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-contentful",
|
||||
"version": "1.1.12",
|
||||
"version": "1.1.13",
|
||||
"description": "Contentful plugin for Medusa Commerce",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -39,8 +39,8 @@
|
||||
"body-parser": "^1.19.0",
|
||||
"contentful-management": "^5.27.1",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"redis": "^3.0.2"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-plugin-discount-generator@1.1.0...medusa-plugin-discount-generator@1.1.3) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-discount-generator
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.2](https://github.com/medusajs/medusa/compare/medusa-plugin-discount-generator@1.1.1...medusa-plugin-discount-generator@1.1.2) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-discount-generator
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-discount-generator",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"author": "Sebastian Rindom",
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-economic@1.1.9...medusa-plugin-economic@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-economic
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-economic@1.1.10...medusa-plugin-economic@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-economic
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-economic",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-economic",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "E-conomic financial reporting",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -39,8 +39,8 @@
|
||||
"axios": "^0.19.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"moment": "^2.27.0"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-plugin-ip-lookup@1.1.0...medusa-plugin-ip-lookup@1.1.3) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-ip-lookup
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.2](https://github.com/medusajs/medusa/compare/medusa-plugin-ip-lookup@1.1.1...medusa-plugin-ip-lookup@1.1.2) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-ip-lookup
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-ip-lookup",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"description": "IP lookup middleware for Medusa core",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-mailchimp@1.1.9...medusa-plugin-mailchimp@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-mailchimp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-mailchimp@1.1.10...medusa-plugin-mailchimp@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-mailchimp
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-mailchimp",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Mailchimp newsletter subscriptions",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -40,8 +40,8 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"mailchimp-api-v3": "^1.14.0",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-permissions@1.1.9...medusa-plugin-permissions@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-permissions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-permissions@1.1.10...medusa-plugin-permissions@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-permissions
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-permissions",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Role permission for Medusa core",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
@@ -32,8 +32,8 @@
|
||||
"medusa-interfaces": "1.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"mongoose": "^5.8.0"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [0.0.7](https://github.com/medusajs/medusa/compare/medusa-plugin-restock-notification@0.0.6...medusa-plugin-restock-notification@0.0.7) (2021-04-29)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-restock-notification
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [0.0.6](https://github.com/medusajs/medusa/compare/medusa-plugin-restock-notification@0.0.3...medusa-plugin-restock-notification@0.0.6) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-restock-notification
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [0.0.5](https://github.com/medusajs/medusa/compare/medusa-plugin-restock-notification@0.0.4...medusa-plugin-restock-notification@0.0.5) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-restock-notification
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-restock-notification",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.7",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -14,12 +14,12 @@
|
||||
"@babel/core": "^7.7.5",
|
||||
"@babel/plugin-transform-typescript": "^7.13.0",
|
||||
"@babel/preset-typescript": "^7.12.7",
|
||||
"@medusajs/medusa": "^1.1.21",
|
||||
"babel-preset-medusa-package": "^1.1.2",
|
||||
"@medusajs/medusa": "^1.1.23",
|
||||
"babel-preset-medusa-package": "^1.1.3",
|
||||
"cross-env": "^5.2.1",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^25.5.2",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"pg": "^8.5.1",
|
||||
"ulid": "^2.3.0"
|
||||
},
|
||||
@@ -37,7 +37,7 @@
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8"
|
||||
"medusa-core-utils": "^1.1.9"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.15](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.12...medusa-plugin-segment@1.1.15) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-segment
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.14](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.13...medusa-plugin-segment@1.1.14) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-segment
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-segment",
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.15",
|
||||
"description": "Segment Analytics",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -39,8 +39,8 @@
|
||||
"axios": "^0.19.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.13](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.10...medusa-plugin-sendgrid@1.1.13) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-sendgrid
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.11...medusa-plugin-sendgrid@1.1.12) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-sendgrid
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-sendgrid",
|
||||
"version": "1.1.12",
|
||||
"version": "1.1.13",
|
||||
"description": "SendGrid transactional emails",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -39,8 +39,8 @@
|
||||
"@sendgrid/mail": "^7.1.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-slack-notification@1.1.9...medusa-plugin-slack-notification@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-slack-notification
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-slack-notification@1.1.10...medusa-plugin-slack-notification@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-slack-notification
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-economic",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-slack-notification",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Slack notifications",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -39,8 +39,8 @@
|
||||
"axios": "^0.19.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"moment": "^2.27.0"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-twilio-sms@1.1.9...medusa-plugin-twilio-sms@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-twilio-sms
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-twilio-sms@1.1.10...medusa-plugin-twilio-sms@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-twilio-sms
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-twilio-sms",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -35,8 +35,8 @@
|
||||
"dependencies": {
|
||||
"@babel/plugin-transform-classes": "^7.9.5",
|
||||
"body-parser": "^1.19.0",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"twilio": "^3.49.1"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-wishlist@1.1.9...medusa-plugin-wishlist@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-wishlist
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-wishlist@1.1.10...medusa-plugin-wishlist@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-wishlist
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-wishlist",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Provides /customers/:id/wishlist to add items to a customr's wishlist",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -37,8 +37,8 @@
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.9...medusa-test-utils@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.10...medusa-test-utils@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-test-utils",
|
||||
"version": "1.1.11",
|
||||
"version": "1.1.12",
|
||||
"description": "Test utils for Medusa",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
@@ -29,7 +29,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-transform-classes": "^7.9.5",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"randomatic": "^3.1.1"
|
||||
},
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.23](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.22...@medusajs/medusa@1.1.23) (2021-04-29)
|
||||
|
||||
**Note:** Version bump only for package @medusajs/medusa
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.22](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.19...@medusajs/medusa@1.1.22) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package @medusajs/medusa
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.21](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.20...@medusajs/medusa@1.1.21) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package @medusajs/medusa
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@medusajs/medusa",
|
||||
"version": "1.1.21",
|
||||
"version": "1.1.23",
|
||||
"description": "E-commerce for JAMstack",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
@@ -26,7 +26,7 @@
|
||||
"@babel/preset-typescript": "^7.12.7",
|
||||
"@babel/register": "^7.7.4",
|
||||
"@babel/runtime": "^7.7.6",
|
||||
"babel-preset-medusa-package": "^1.1.2",
|
||||
"babel-preset-medusa-package": "^1.1.3",
|
||||
"cross-env": "^5.2.1",
|
||||
"eslint": "^6.8.0",
|
||||
"jest": "^25.5.2",
|
||||
@@ -67,8 +67,8 @@
|
||||
"joi": "^17.3.0",
|
||||
"joi-objectid": "^3.0.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11",
|
||||
"medusa-core-utils": "^1.1.9",
|
||||
"medusa-test-utils": "^1.1.12",
|
||||
"morgan": "^1.9.1",
|
||||
"multer": "^1.4.2",
|
||||
"passport": "^0.4.0",
|
||||
|
||||
@@ -65,7 +65,7 @@ describe("POST /store/carts/:id", () => {
|
||||
expect(CartServiceMock.retrieve).toHaveBeenCalledWith(
|
||||
IdMap.getId("emptyCart"),
|
||||
{
|
||||
relations: ["payment_sessions"],
|
||||
relations: ["payment_sessions", "shipping_methods"],
|
||||
}
|
||||
)
|
||||
expect(CartServiceMock.retrieve).toHaveBeenCalledWith(
|
||||
|
||||
@@ -104,7 +104,7 @@ export default async (req, res) => {
|
||||
|
||||
// If the cart has payment sessions update these
|
||||
const updated = await cartService.retrieve(id, {
|
||||
relations: ["payment_sessions"],
|
||||
relations: ["payment_sessions", "shipping_methods"],
|
||||
})
|
||||
|
||||
if (updated.payment_sessions?.length && !value.region_id) {
|
||||
|
||||
@@ -1281,6 +1281,7 @@ describe("CartService", () => {
|
||||
profile_id: IdMap.getId(m.profile),
|
||||
},
|
||||
})),
|
||||
discounts: [],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,31 +100,20 @@ describe("ClaimService", () => {
|
||||
expect(withTransactionMock).toHaveBeenCalledWith("return")
|
||||
|
||||
expect(returnService.create).toHaveBeenCalledTimes(1)
|
||||
expect(returnService.create).toHaveBeenCalledWith(
|
||||
{
|
||||
claim_order_id: "claim_134",
|
||||
shipping_method: {
|
||||
option_id: "opt_13",
|
||||
price: 0,
|
||||
},
|
||||
items: [
|
||||
{
|
||||
item_id: "itm_1",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
expect(returnService.create).toHaveBeenCalledWith({
|
||||
order_id: "1234",
|
||||
claim_order_id: "claim_134",
|
||||
shipping_method: {
|
||||
option_id: "opt_13",
|
||||
price: 0,
|
||||
},
|
||||
{
|
||||
id: "1234",
|
||||
region_id: "order_region",
|
||||
items: [
|
||||
{
|
||||
id: "itm_1",
|
||||
unit_price: 8000,
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
items: [
|
||||
{
|
||||
item_id: "itm_1",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
expect(withTransactionMock).toHaveBeenCalledWith("lineItem")
|
||||
expect(lineItemService.generate).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import _ from "lodash"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { defaultFields, defaultRelations } from "../api/routes/store/carts"
|
||||
|
||||
/**
|
||||
* Provides layer to manipulate carts.
|
||||
@@ -574,6 +573,49 @@ class CartService extends BaseService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures shipping total on cart is correct in regards to a potential free
|
||||
* shipping discount
|
||||
* If a free shipping is present, we set shipping methods price to 0
|
||||
* if a free shipping was present, we set shipping methods to original amount
|
||||
* @param {Cart} cart - the the cart to adjust free shipping for
|
||||
* @param {boolean} shouldAdd - flag to indicate, if we should add or remove
|
||||
*/
|
||||
async adjustFreeShipping_(cart, shouldAdd) {
|
||||
if (cart.shipping_methods?.length) {
|
||||
// if any free shipping discounts, we ensure to update shipping method amount
|
||||
if (shouldAdd) {
|
||||
await Promise.all(
|
||||
cart.shipping_methods.map(async sm => {
|
||||
const smRepo = this.manager_.getCustomRepository(
|
||||
this.shippingMethodRepository_
|
||||
)
|
||||
|
||||
const method = await smRepo.findOne({ where: { id: sm.id } })
|
||||
|
||||
if (method) {
|
||||
method.price = 0
|
||||
await smRepo.save(method)
|
||||
}
|
||||
})
|
||||
)
|
||||
} else {
|
||||
await Promise.all(
|
||||
cart.shipping_methods.map(async sm => {
|
||||
const smRepo = this.manager_.getCustomRepository(
|
||||
this.shippingMethodRepository_
|
||||
)
|
||||
|
||||
// if free shipping discount is removed, we adjust the shipping
|
||||
// back to its original amount
|
||||
sm.price = sm.shipping_option.amount
|
||||
await smRepo.save(sm)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async update(cartId, update) {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cartRepo = manager.getCustomRepository(this.cartRepository_)
|
||||
@@ -627,10 +669,29 @@ class CartService extends BaseService {
|
||||
}
|
||||
|
||||
if ("discounts" in update) {
|
||||
const previousDiscounts = cart.discounts
|
||||
cart.discounts = []
|
||||
|
||||
for (const { code } of update.discounts) {
|
||||
await this.applyDiscount_(cart, code)
|
||||
}
|
||||
|
||||
const hasFreeShipping = cart.discounts.some(
|
||||
({ rule }) => rule.type === "free_shipping"
|
||||
)
|
||||
|
||||
// if we previously had a free shipping discount and then removed it,
|
||||
// we need to update shipping methods to original price
|
||||
if (
|
||||
previousDiscounts.some(({ rule }) => rule.type === "free_shipping") &&
|
||||
!hasFreeShipping
|
||||
) {
|
||||
await this.adjustFreeShipping_(cart, false)
|
||||
}
|
||||
|
||||
if (hasFreeShipping) {
|
||||
await this.adjustFreeShipping_(cart, true)
|
||||
}
|
||||
}
|
||||
|
||||
if ("gift_cards" in update) {
|
||||
@@ -890,8 +951,13 @@ class CartService extends BaseService {
|
||||
async removeDiscount(cartId, discountCode) {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: ["discounts", "payment_sessions"],
|
||||
relations: ["discounts", "payment_sessions", "shipping_methods"],
|
||||
})
|
||||
|
||||
if (cart.discounts.some(({ rule }) => rule.type === "free_shipping")) {
|
||||
await this.adjustFreeShipping_(cart, false)
|
||||
}
|
||||
|
||||
cart.discounts = cart.discounts.filter(d => d.code !== discountCode)
|
||||
|
||||
const cartRepo = manager.getCustomRepository(this.cartRepository_)
|
||||
@@ -1232,6 +1298,7 @@ class CartService extends BaseService {
|
||||
select: ["subtotal"],
|
||||
relations: [
|
||||
"shipping_methods",
|
||||
"discounts",
|
||||
"shipping_methods.shipping_option",
|
||||
"items",
|
||||
"items.variant",
|
||||
@@ -1267,7 +1334,15 @@ class CartService extends BaseService {
|
||||
})
|
||||
}
|
||||
|
||||
const result = await this.retrieve(cartId)
|
||||
const result = await this.retrieve(cartId, {
|
||||
relations: ["discounts", "shipping_methods"],
|
||||
})
|
||||
|
||||
// if cart has freeshipping, adjust price
|
||||
if (result.discounts.some(({ rule }) => rule.type === "free_shipping")) {
|
||||
await this.adjustFreeShipping_(result, true)
|
||||
}
|
||||
|
||||
await this.eventBus_
|
||||
.withTransaction(manager)
|
||||
.emit(CartService.Events.UPDATED, result)
|
||||
|
||||
@@ -252,18 +252,16 @@ class ClaimService extends BaseService {
|
||||
}
|
||||
|
||||
if (return_shipping) {
|
||||
await this.returnService_.withTransaction(manager).create(
|
||||
{
|
||||
claim_order_id: result.id,
|
||||
items: claim_items.map(ci => ({
|
||||
item_id: ci.item_id,
|
||||
quantity: ci.quantity,
|
||||
metadata: ci.metadata,
|
||||
})),
|
||||
shipping_method: return_shipping,
|
||||
},
|
||||
order
|
||||
)
|
||||
await this.returnService_.withTransaction(manager).create({
|
||||
order_id: order.id,
|
||||
claim_order_id: result.id,
|
||||
items: claim_items.map(ci => ({
|
||||
item_id: ci.item_id,
|
||||
quantity: ci.quantity,
|
||||
metadata: ci.metadata,
|
||||
})),
|
||||
shipping_method: return_shipping,
|
||||
})
|
||||
}
|
||||
|
||||
await this.eventBus_
|
||||
|
||||
@@ -400,8 +400,13 @@ class SwapService extends BaseService {
|
||||
|
||||
const order = swap.order
|
||||
|
||||
// filter out free shipping discounts
|
||||
const discounts =
|
||||
order?.discounts?.filter(({ rule }) => rule.type !== "free_shipping") ||
|
||||
undefined
|
||||
|
||||
const cart = await this.cartService_.withTransaction(manager).create({
|
||||
discounts: order.discounts,
|
||||
discounts,
|
||||
email: order.email,
|
||||
billing_address_id: order.billing_address_id,
|
||||
shipping_address_id: order.shipping_address_id,
|
||||
|
||||
Reference in New Issue
Block a user