diff --git a/packages/medusa-core-utils/CHANGELOG.md b/packages/medusa-core-utils/CHANGELOG.md index 7653a1871f..3f47b8b5a0 100644 --- a/packages/medusa-core-utils/CHANGELOG.md +++ b/packages/medusa-core-utils/CHANGELOG.md @@ -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.4](https://github.com/medusajs/medusa/compare/medusa-core-utils@1.1.3...medusa-core-utils@1.1.4) (2021-03-30) + + +### Bug Fixes + +* don't divide zero decimal currencies ([cfab2d4](https://github.com/medusajs/medusa/commit/cfab2d408a296a938266d0989b1de67d060b2ed5)) + + + + + ## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-core-utils@1.1.2...medusa-core-utils@1.1.3) (2021-03-17) **Note:** Version bump only for package medusa-core-utils diff --git a/packages/medusa-core-utils/package.json b/packages/medusa-core-utils/package.json index 13a3014564..6e99c05631 100644 --- a/packages/medusa-core-utils/package.json +++ b/packages/medusa-core-utils/package.json @@ -1,6 +1,6 @@ { "name": "medusa-core-utils", - "version": "1.1.3", + "version": "1.1.4", "description": "Core utils for Medusa", "main": "dist/index.js", "repository": { diff --git a/packages/medusa-core-utils/src/humanize-amount.js b/packages/medusa-core-utils/src/humanize-amount.js new file mode 100644 index 0000000000..1bdb827858 --- /dev/null +++ b/packages/medusa-core-utils/src/humanize-amount.js @@ -0,0 +1,13 @@ +import zeroDecimalCurrencies from "./zero-decimal-currencies" + +const humanizeAmount = (amount, currency) => { + let divisor = 100 + + if (zeroDecimalCurrencies.includes(currency.toLowerCase())) { + divisor = 1 + } + + return amount / divisor +} + +export default humanizeAmount diff --git a/packages/medusa-core-utils/src/index.js b/packages/medusa-core-utils/src/index.js index d15ba04bef..d30a469a72 100644 --- a/packages/medusa-core-utils/src/index.js +++ b/packages/medusa-core-utils/src/index.js @@ -5,3 +5,5 @@ export { default as MedusaError } from "./errors" export { default as getConfigFile } from "./get-config-file" export { default as createRequireFromPath } from "./create-require-from-path" export { default as compareObjectsByProp } from "./compare-objects" +export { default as zeroDecimalCurrencies } from "./zero-decimal-currencies" +export { default as humanizeAmount } from "./humanize-amount" diff --git a/packages/medusa-core-utils/src/zero-decimal-currencies.js b/packages/medusa-core-utils/src/zero-decimal-currencies.js new file mode 100644 index 0000000000..a8bef8e12a --- /dev/null +++ b/packages/medusa-core-utils/src/zero-decimal-currencies.js @@ -0,0 +1,20 @@ +const zeroDecimalCurrencies = [ + "bif", + "clp", + "djf", + "gnf", + "jpy", + "kmf", + "krw", + "mga", + "pyg", + "rwf", + "ugx", + "vnd", + "vuv", + "xaf", + "xof", + "xpf", +] + +export default zeroDecimalCurrencies diff --git a/packages/medusa-file-spaces/CHANGELOG.md b/packages/medusa-file-spaces/CHANGELOG.md index e4d71ff468..b0af732c58 100644 --- a/packages/medusa-file-spaces/CHANGELOG.md +++ b/packages/medusa-file-spaces/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-file-spaces@1.1.6...medusa-file-spaces@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-file-spaces + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-file-spaces@1.1.5...medusa-file-spaces@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-file-spaces diff --git a/packages/medusa-file-spaces/package.json b/packages/medusa-file-spaces/package.json index bb82fec39d..96cc49f5b2 100644 --- a/packages/medusa-file-spaces/package.json +++ b/packages/medusa-file-spaces/package.json @@ -1,6 +1,6 @@ { "name": "medusa-file-spaces", - "version": "1.1.6", + "version": "1.1.7", "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.3", - "medusa-test-utils": "^1.1.6", + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7", "stripe": "^8.50.0" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa-fulfillment-manual/CHANGELOG.md b/packages/medusa-fulfillment-manual/CHANGELOG.md index 68ae3a9e6d..018fbc9e46 100644 --- a/packages/medusa-fulfillment-manual/CHANGELOG.md +++ b/packages/medusa-fulfillment-manual/CHANGELOG.md @@ -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.4](https://github.com/medusajs/medusa/compare/medusa-fulfillment-manual@1.1.3...medusa-fulfillment-manual@1.1.4) (2021-03-30) + +**Note:** Version bump only for package medusa-fulfillment-manual + + + + + ## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-fulfillment-manual@1.1.2...medusa-fulfillment-manual@1.1.3) (2021-03-17) **Note:** Version bump only for package medusa-fulfillment-manual diff --git a/packages/medusa-fulfillment-manual/package.json b/packages/medusa-fulfillment-manual/package.json index 76e7ed775a..d1ddbbee6c 100644 --- a/packages/medusa-fulfillment-manual/package.json +++ b/packages/medusa-fulfillment-manual/package.json @@ -1,6 +1,6 @@ { "name": "medusa-fulfillment-manual", - "version": "1.1.3", + "version": "1.1.4", "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.3" + "medusa-core-utils": "^1.1.4" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" } diff --git a/packages/medusa-fulfillment-webshipper/CHANGELOG.md b/packages/medusa-fulfillment-webshipper/CHANGELOG.md index 836e5602ea..96e2a55fe2 100644 --- a/packages/medusa-fulfillment-webshipper/CHANGELOG.md +++ b/packages/medusa-fulfillment-webshipper/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.6...medusa-fulfillment-webshipper@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-fulfillment-webshipper + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-fulfillment-webshipper@1.1.5...medusa-fulfillment-webshipper@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-fulfillment-webshipper diff --git a/packages/medusa-fulfillment-webshipper/package.json b/packages/medusa-fulfillment-webshipper/package.json index 4c20bdaaad..fe910257e9 100644 --- a/packages/medusa-fulfillment-webshipper/package.json +++ b/packages/medusa-fulfillment-webshipper/package.json @@ -1,6 +1,6 @@ { "name": "medusa-fulfillment-webshipper", - "version": "1.1.6", + "version": "1.1.7", "description": "Webshipper Fulfillment provider for Medusa", "main": "index.js", "repository": { @@ -36,7 +36,7 @@ "body-parser": "^1.19.0", "cors": "^2.8.5", "express": "^4.17.1", - "medusa-core-utils": "^1.1.3" + "medusa-core-utils": "^1.1.4" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" } diff --git a/packages/medusa-interfaces/CHANGELOG.md b/packages/medusa-interfaces/CHANGELOG.md index 0fdb4f8ccb..6292fdd015 100644 --- a/packages/medusa-interfaces/CHANGELOG.md +++ b/packages/medusa-interfaces/CHANGELOG.md @@ -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.5](https://github.com/medusajs/medusa/compare/medusa-interfaces@1.1.4...medusa-interfaces@1.1.5) (2021-03-30) + +**Note:** Version bump only for package medusa-interfaces + + + + + ## [1.1.4](https://github.com/medusajs/medusa/compare/medusa-interfaces@1.1.3...medusa-interfaces@1.1.4) (2021-03-17) **Note:** Version bump only for package medusa-interfaces diff --git a/packages/medusa-interfaces/package.json b/packages/medusa-interfaces/package.json index 98583fcf40..c92643b902 100644 --- a/packages/medusa-interfaces/package.json +++ b/packages/medusa-interfaces/package.json @@ -1,6 +1,6 @@ { "name": "medusa-interfaces", - "version": "1.1.4", + "version": "1.1.5", "description": "Core interfaces for Medusa", "main": "dist/index.js", "repository": { @@ -35,7 +35,7 @@ "typeorm": "0.x" }, "dependencies": { - "medusa-core-utils": "^1.1.3" + "medusa-core-utils": "^1.1.4" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" } diff --git a/packages/medusa-payment-adyen/CHANGELOG.md b/packages/medusa-payment-adyen/CHANGELOG.md index 61cffcd9bd..08b79f91d5 100644 --- a/packages/medusa-payment-adyen/CHANGELOG.md +++ b/packages/medusa-payment-adyen/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-payment-adyen@1.1.6...medusa-payment-adyen@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-payment-adyen + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-payment-adyen@1.1.5...medusa-payment-adyen@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-payment-adyen diff --git a/packages/medusa-payment-adyen/package.json b/packages/medusa-payment-adyen/package.json index f4379e318f..fd460df886 100644 --- a/packages/medusa-payment-adyen/package.json +++ b/packages/medusa-payment-adyen/package.json @@ -1,6 +1,6 @@ { "name": "medusa-payment-adyen", - "version": "1.1.6", + "version": "1.1.7", "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.6" + "medusa-test-utils": "^1.1.7" }, "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.3" + "medusa-core-utils": "^1.1.4" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" } diff --git a/packages/medusa-payment-klarna/CHANGELOG.md b/packages/medusa-payment-klarna/CHANGELOG.md index 021f346e37..ae672447fd 100644 --- a/packages/medusa-payment-klarna/CHANGELOG.md +++ b/packages/medusa-payment-klarna/CHANGELOG.md @@ -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.8](https://github.com/medusajs/medusa/compare/medusa-payment-klarna@1.1.8...medusa-payment-klarna@1.1.8) (2021-03-30) + + +### Bug Fixes + +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + ## [1.1.8](https://github.com/medusajs/medusa/compare/medusa-payment-klarna@1.1.7...medusa-payment-klarna@1.1.8) (2021-03-23) diff --git a/packages/medusa-payment-klarna/package.json b/packages/medusa-payment-klarna/package.json index a98a5c7e62..65bbef675e 100644 --- a/packages/medusa-payment-klarna/package.json +++ b/packages/medusa-payment-klarna/package.json @@ -40,8 +40,8 @@ "axios": "^0.21.0", "body-parser": "^1.19.0", "express": "^4.17.1", - "medusa-core-utils": "^1.1.3", - "medusa-test-utils": "^1.1.6" + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7" }, - "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" + "gitHead": "d78a7ce85876e0bfd9a4bfebe4f5743921961e9c" } diff --git a/packages/medusa-payment-paypal/CHANGELOG.md b/packages/medusa-payment-paypal/CHANGELOG.md index 0a47e8e9d1..6faaf209f0 100644 --- a/packages/medusa-payment-paypal/CHANGELOG.md +++ b/packages/medusa-payment-paypal/CHANGELOG.md @@ -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.0.7](https://github.com/medusajs/medusa/compare/medusa-payment-paypal@1.0.6...medusa-payment-paypal@1.0.7) (2021-03-30) + +**Note:** Version bump only for package medusa-payment-paypal + + + + + ## [1.0.6](https://github.com/medusajs/medusa/compare/medusa-payment-paypal@1.0.5...medusa-payment-paypal@1.0.6) (2021-03-17) **Note:** Version bump only for package medusa-payment-paypal diff --git a/packages/medusa-payment-paypal/package.json b/packages/medusa-payment-paypal/package.json index 8ee5c7c442..9c32e22424 100644 --- a/packages/medusa-payment-paypal/package.json +++ b/packages/medusa-payment-paypal/package.json @@ -1,6 +1,6 @@ { "name": "medusa-payment-paypal", - "version": "1.0.6", + "version": "1.0.7", "description": "Paypal 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.6" + "medusa-test-utils": "^1.1.7" }, "scripts": { "build": "babel src -d . --ignore **/__tests__", @@ -41,7 +41,7 @@ "@paypal/checkout-server-sdk": "^1.0.2", "body-parser": "^1.19.0", "express": "^4.17.1", - "medusa-core-utils": "^1.1.3" + "medusa-core-utils": "^1.1.4" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" } diff --git a/packages/medusa-payment-stripe/CHANGELOG.md b/packages/medusa-payment-stripe/CHANGELOG.md index 8fd93f4c52..5765cd95b9 100644 --- a/packages/medusa-payment-stripe/CHANGELOG.md +++ b/packages/medusa-payment-stripe/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-payment-stripe@1.1.6...medusa-payment-stripe@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-payment-stripe + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-payment-stripe@1.1.5...medusa-payment-stripe@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-payment-stripe diff --git a/packages/medusa-payment-stripe/package.json b/packages/medusa-payment-stripe/package.json index 1f824e46f5..735fc99c0b 100644 --- a/packages/medusa-payment-stripe/package.json +++ b/packages/medusa-payment-stripe/package.json @@ -1,6 +1,6 @@ { "name": "medusa-payment-stripe", - "version": "1.1.6", + "version": "1.1.7", "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.6" + "medusa-test-utils": "^1.1.7" }, "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.3", + "medusa-core-utils": "^1.1.4", "stripe": "^8.50.0" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa-plugin-add-ons/CHANGELOG.md b/packages/medusa-plugin-add-ons/CHANGELOG.md index a5a9a47b07..fa724d3a1d 100644 --- a/packages/medusa-plugin-add-ons/CHANGELOG.md +++ b/packages/medusa-plugin-add-ons/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-plugin-add-ons@1.1.6...medusa-plugin-add-ons@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-plugin-add-ons + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-plugin-add-ons@1.1.5...medusa-plugin-add-ons@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-plugin-add-ons diff --git a/packages/medusa-plugin-add-ons/package.json b/packages/medusa-plugin-add-ons/package.json index e9c1f6effa..fe0659c704 100644 --- a/packages/medusa-plugin-add-ons/package.json +++ b/packages/medusa-plugin-add-ons/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-add-ons", - "version": "1.1.6", + "version": "1.1.7", "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.6" + "medusa-test-utils": "^1.1.7" }, "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.3", + "medusa-core-utils": "^1.1.4", "redis": "^3.0.2" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa-plugin-brightpearl/CHANGELOG.md b/packages/medusa-plugin-brightpearl/CHANGELOG.md index 522fd4ead2..e2a6943c87 100644 --- a/packages/medusa-plugin-brightpearl/CHANGELOG.md +++ b/packages/medusa-plugin-brightpearl/CHANGELOG.md @@ -3,6 +3,30 @@ 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-plugin-brightpearl@1.1.9...medusa-plugin-brightpearl@1.1.10) (2021-04-01) + + +### Bug Fixes + +* don't divide zero decimal currencies ([cfab2d4](https://github.com/medusajs/medusa/commit/cfab2d408a296a938266d0989b1de67d060b2ed5)) +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + +## [1.1.9](https://github.com/medusajs/medusa/compare/medusa-plugin-brightpearl@1.1.9...medusa-plugin-brightpearl@1.1.9) (2021-03-30) + + +### Bug Fixes + +* don't divide zero decimal currencies ([cfab2d4](https://github.com/medusajs/medusa/commit/cfab2d408a296a938266d0989b1de67d060b2ed5)) +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + ## [1.1.9](https://github.com/medusajs/medusa/compare/medusa-plugin-brightpearl@1.1.8...medusa-plugin-brightpearl@1.1.9) (2021-03-25) **Note:** Version bump only for package medusa-plugin-brightpearl diff --git a/packages/medusa-plugin-brightpearl/package.json b/packages/medusa-plugin-brightpearl/package.json index 2a1c349092..6894cf3dfc 100644 --- a/packages/medusa-plugin-brightpearl/package.json +++ b/packages/medusa-plugin-brightpearl/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-brightpearl", - "version": "1.1.9", + "version": "1.1.10", "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.6", + "medusa-test-utils": "^1.1.7", "prettier": "^2.0.5" }, "scripts": { @@ -43,8 +43,8 @@ "axios": "^0.19.2", "axios-rate-limit": "^1.2.1", "express": "^4.17.1", - "medusa-core-utils": "^1.1.3", + "medusa-core-utils": "^1.1.4", "randomatic": "^3.1.1" }, - "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" + "gitHead": "d78a7ce85876e0bfd9a4bfebe4f5743921961e9c" } diff --git a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js index c9616fe93b..bf02058c57 100644 --- a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js +++ b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js @@ -1,4 +1,4 @@ -import { MedusaError } from "medusa-core-utils" +import { MedusaError, humanizeAmount } from "medusa-core-utils" import { BaseService } from "medusa-interfaces" import Brightpearl from "../utils/brightpearl" @@ -299,10 +299,12 @@ class BrightpearlService extends BaseService { taxCode: region.tax_code, net: this.bpnum_( fromRefund.amount, + fromOrder.currency_code, 10000 / (100 + fromOrder.tax_rate) ), tax: this.bpnum_( - fromRefund.amount * (1 - 100 / (100 + fromOrder.tax_rate)) + fromRefund.amount * (1 - 100 / (100 + fromOrder.tax_rate)), + fromOrder.currency_code ), nominalCode: accountingCode, }, @@ -320,7 +322,7 @@ class BrightpearlService extends BaseService { paymentMethodCode: this.options.payment_method_code || "1220", orderId: creditId, currencyIsoCode: fromOrder.currency_code.toUpperCase(), - amountPaid: this.bpnum_(fromRefund.amount), + amountPaid: this.bpnum_(fromRefund.amount, fromOrder.currency_code), paymentDate: new Date(), paymentType, } @@ -389,8 +391,15 @@ class BrightpearlService extends BaseService { name: "Difference", quantity: 1, taxCode: region.tax_code, - net: this.bpnum_(difference, 10000 / (100 + fromOrder.tax_rate)), - tax: this.bpnum_(difference * (1 - 100 / (100 + fromOrder.tax_rate))), + net: this.bpnum_( + difference, + fromOrder.currency_code, + 10000 / (100 + fromOrder.tax_rate) + ), + tax: this.bpnum_( + difference * (1 - 100 / (100 + fromOrder.tax_rate)), + fromOrder.currency_code + ), nominalCode: this.options.sales_account_code || "4000", }) } @@ -406,7 +415,10 @@ class BrightpearlService extends BaseService { paymentMethodCode: this.options.payment_method_code || "1220", orderId: creditId, currencyIsoCode: fromOrder.currency_code.toUpperCase(), - amountPaid: this.bpnum_(fromReturn.refund_amount), + amountPaid: this.bpnum_( + fromReturn.refund_amount, + fromOrder.currencyCode + ), paymentDate: new Date(), paymentType, } @@ -649,10 +661,12 @@ class BrightpearlService extends BaseService { name: `#${fromOrder.display_id}: Claim ${fromClaim.id}`, net: this.bpnum_( fromClaim.refund_amount, + fromOrder.currency_code, 10000 / (100 + fromOrder.tax_rate) ), tax: this.bpnum_( - fromClaim.refund_amount * (1 - 100 / (100 + fromOrder.tax_rate)) + fromClaim.refund_amount * (1 - 100 / (100 + fromOrder.tax_rate)), + fromOrder.currency_code ), taxCode: region.tax_code, nominalCode: this.options.sales_account_code || `4000`, @@ -672,7 +686,10 @@ class BrightpearlService extends BaseService { paymentMethodCode: this.options.payment_method_code || "1220", orderId: creditId, currencyIsoCode: fromOrder.currency_code.toUpperCase(), - amountPaid: this.bpnum_(fromClaim.refund_amount), + amountPaid: this.bpnum_( + fromClaim.refund_amount, + fromOrder.currency_code + ), paymentDate: new Date(), paymentType, } @@ -784,7 +801,7 @@ class BrightpearlService extends BaseService { orderId: soId, paymentDate: new Date(), currencyIsoCode: fromOrder.currency_code.toUpperCase(), - amountPaid: this.bpnum_(fromOrder.total), + amountPaid: this.bpnum_(fromOrder.total, fromOrder.currency_code), paymentType, } @@ -820,9 +837,13 @@ class BrightpearlService extends BaseService { } if (config.include_price) { - row.net = this.bpnum_(item.unit_price * item.quantity - ld.amount) + row.net = this.bpnum_( + item.unit_price * item.quantity - ld.amount, + fromOrder.currency_code + ) row.tax = this.bpnum_( item.unit_price * item.quantity - ld.amount, + fromOrder.currency_code, fromOrder.tax_rate ) } else if (config.is_claim) { @@ -830,7 +851,11 @@ class BrightpearlService extends BaseService { bpProduct.productId, this.options.cost_price_list || `1` ) - row.tax = this.bpnum_(row.net * 100, fromOrder.tax_rate) + row.tax = this.bpnum_( + row.net * 100, + fromOrder.currency_code, + fromOrder.tax_rate + ) } row.quantity = item.quantity @@ -856,8 +881,12 @@ class BrightpearlService extends BaseService { if (gcTotal) { lines.push({ name: `Gift Card`, - net: this.bpnum_(-1 * gcTotal), - tax: this.bpnum_(-1 * gcTotal, fromOrder.tax_rate), + net: this.bpnum_(-1 * gcTotal, fromOrder.currency_code), + tax: this.bpnum_( + -1 * gcTotal, + fromOrder.currency_code, + fromOrder.tax_rate + ), quantity: 1, taxCode: region.tax_code, nominalCode: this.options.gift_card_account_code || "4000", @@ -872,8 +901,12 @@ class BrightpearlService extends BaseService { lines.push({ name: `Shipping: ${shippingMethods.map((m) => m.name).join(" + ")}`, quantity: 1, - net: this.bpnum_(shippingTotal), - tax: this.bpnum_(shippingTotal, fromOrder.tax_rate), + net: this.bpnum_(shippingTotal, fromOrder.currency_code), + tax: this.bpnum_( + shippingTotal, + fromOrder.currency_code, + fromOrder.tax_rate + ), taxCode: region.tax_code, nominalCode: this.options.shipping_account_code || "4040", }) @@ -1112,8 +1145,8 @@ class BrightpearlService extends BaseService { ) } - bpnum_(number, taxRate = 100) { - const bpNumber = number / 100 + bpnum_(number, currency, taxRate = 100) { + const bpNumber = humanizeAmount(number, currency) return this.bpround_(bpNumber * (taxRate / 100)) } } diff --git a/packages/medusa-plugin-contentful/CHANGELOG.md b/packages/medusa-plugin-contentful/CHANGELOG.md index e8b00bc538..97dcf69004 100644 --- a/packages/medusa-plugin-contentful/CHANGELOG.md +++ b/packages/medusa-plugin-contentful/CHANGELOG.md @@ -3,6 +3,28 @@ 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/medusa-plugin-contentful@1.1.8...medusa-plugin-contentful@1.1.8) (2021-03-30) + + +### Bug Fixes + +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + +## [1.1.8](https://github.com/medusajs/medusa/compare/medusa-plugin-contentful@1.1.7...medusa-plugin-contentful@1.1.8) (2021-03-26) + + +### Bug Fixes + +* update all contentful ([806918a](https://github.com/medusajs/medusa/commit/806918a10e42fde60240dcc785d8e175dc8507b5)) + + + + + ## [1.1.7](https://github.com/medusajs/medusa/compare/medusa-plugin-contentful@1.1.6...medusa-plugin-contentful@1.1.7) (2021-03-17) **Note:** Version bump only for package medusa-plugin-contentful diff --git a/packages/medusa-plugin-contentful/package.json b/packages/medusa-plugin-contentful/package.json index 45985a078c..2eb7b743f8 100644 --- a/packages/medusa-plugin-contentful/package.json +++ b/packages/medusa-plugin-contentful/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-contentful", - "version": "1.1.7", + "version": "1.1.8", "description": "Contentful plugin for Medusa Commerce", "main": "index.js", "repository": { @@ -39,9 +39,9 @@ "body-parser": "^1.19.0", "contentful-management": "^5.27.1", "express": "^4.17.1", - "medusa-core-utils": "^1.1.3", - "medusa-test-utils": "^1.1.6", + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7", "redis": "^3.0.2" }, - "gitHead": "739b7b3cc5ff31aa7a15637db2000e645c7597b1" + "gitHead": "d78a7ce85876e0bfd9a4bfebe4f5743921961e9c" } diff --git a/packages/medusa-plugin-contentful/src/services/contentful.js b/packages/medusa-plugin-contentful/src/services/contentful.js index da5e3bc765..5fed5759a4 100644 --- a/packages/medusa-plugin-contentful/src/services/contentful.js +++ b/packages/medusa-plugin-contentful/src/services/contentful.js @@ -449,9 +449,14 @@ class ContentfulService extends BaseService { "options", ] - const found = variant.fields.find((f) => updateFields.includes(f)) - if (!found) { - return + // Update came directly from product variant service so only act on a couple + // of fields. When the update comes from the product we want to ensure + // references are set up correctly so we run through everything. + if (variant.fields) { + const found = variant.fields.find((f) => updateFields.includes(f)) + if (!found) { + return + } } try { diff --git a/packages/medusa-plugin-economic/CHANGELOG.md b/packages/medusa-plugin-economic/CHANGELOG.md index f379aead3f..7c826812cb 100644 --- a/packages/medusa-plugin-economic/CHANGELOG.md +++ b/packages/medusa-plugin-economic/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-plugin-economic@1.1.6...medusa-plugin-economic@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-plugin-economic + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-plugin-economic@1.1.5...medusa-plugin-economic@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-plugin-economic diff --git a/packages/medusa-plugin-economic/package-lock.json b/packages/medusa-plugin-economic/package-lock.json index 8d11bc73b9..f61068049e 100644 --- a/packages/medusa-plugin-economic/package-lock.json +++ b/packages/medusa-plugin-economic/package-lock.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-economic", - "version": "1.1.6", + "version": "1.1.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/medusa-plugin-economic/package.json b/packages/medusa-plugin-economic/package.json index 6e5191e95f..a1383b4beb 100644 --- a/packages/medusa-plugin-economic/package.json +++ b/packages/medusa-plugin-economic/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-economic", - "version": "1.1.6", + "version": "1.1.7", "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.3", - "medusa-test-utils": "^1.1.6", + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7", "moment": "^2.27.0" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa-plugin-mailchimp/CHANGELOG.md b/packages/medusa-plugin-mailchimp/CHANGELOG.md index 3a04a55906..d3ac6f4062 100644 --- a/packages/medusa-plugin-mailchimp/CHANGELOG.md +++ b/packages/medusa-plugin-mailchimp/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-plugin-mailchimp@1.1.6...medusa-plugin-mailchimp@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-plugin-mailchimp + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-plugin-mailchimp@1.1.5...medusa-plugin-mailchimp@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-plugin-mailchimp diff --git a/packages/medusa-plugin-mailchimp/package.json b/packages/medusa-plugin-mailchimp/package.json index f6a5960bfb..b1fc5e4839 100644 --- a/packages/medusa-plugin-mailchimp/package.json +++ b/packages/medusa-plugin-mailchimp/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-mailchimp", - "version": "1.1.6", + "version": "1.1.7", "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.3", - "medusa-test-utils": "^1.1.6" + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" } diff --git a/packages/medusa-plugin-permissions/CHANGELOG.md b/packages/medusa-plugin-permissions/CHANGELOG.md index 5b08e3fa0c..382454d547 100644 --- a/packages/medusa-plugin-permissions/CHANGELOG.md +++ b/packages/medusa-plugin-permissions/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-plugin-permissions@1.1.6...medusa-plugin-permissions@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-plugin-permissions + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-plugin-permissions@1.1.5...medusa-plugin-permissions@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-plugin-permissions diff --git a/packages/medusa-plugin-permissions/package.json b/packages/medusa-plugin-permissions/package.json index 4cb7668a5b..50e534a287 100644 --- a/packages/medusa-plugin-permissions/package.json +++ b/packages/medusa-plugin-permissions/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-permissions", - "version": "1.1.6", + "version": "1.1.7", "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.3", - "medusa-test-utils": "^1.1.6", + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7", "mongoose": "^5.8.0" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa-plugin-segment/CHANGELOG.md b/packages/medusa-plugin-segment/CHANGELOG.md index 732acb8744..db243d361f 100644 --- a/packages/medusa-plugin-segment/CHANGELOG.md +++ b/packages/medusa-plugin-segment/CHANGELOG.md @@ -3,6 +3,30 @@ 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-plugin-segment@1.1.9...medusa-plugin-segment@1.1.10) (2021-04-02) + + +### Bug Fixes + +* adds exchange rates api key ([8eec38a](https://github.com/medusajs/medusa/commit/8eec38af7164fe60106b8dac33ae9acfeb2b0f2e)) + + + + + +## [1.1.9](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.8...medusa-plugin-segment@1.1.9) (2021-03-30) + + +### Bug Fixes + +* adds tests for segment ([1b00f96](https://github.com/medusajs/medusa/commit/1b00f967dea3dc3aa65fafbe1334492fba5c33c2)) +* don't divide zero decimal currencies ([3258955](https://github.com/medusajs/medusa/commit/3258955b462f91fc6f4d807c5cc9b5ad11d6bbdf)) +* don't divide zero decimal currencies ([cfab2d4](https://github.com/medusajs/medusa/commit/cfab2d408a296a938266d0989b1de67d060b2ed5)) + + + + + ## [1.1.8](https://github.com/medusajs/medusa/compare/medusa-plugin-segment@1.1.7...medusa-plugin-segment@1.1.8) (2021-03-17) **Note:** Version bump only for package medusa-plugin-segment diff --git a/packages/medusa-plugin-segment/package.json b/packages/medusa-plugin-segment/package.json index d73f16d9a1..217fff8b8d 100644 --- a/packages/medusa-plugin-segment/package.json +++ b/packages/medusa-plugin-segment/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-segment", - "version": "1.1.8", + "version": "1.1.10", "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.3", - "medusa-test-utils": "^1.1.6" + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7" }, "gitHead": "0c294b7b3acbc1b873aab7e90a8e596bdac48899" } diff --git a/packages/medusa-plugin-segment/src/services/__tests__/segment.js b/packages/medusa-plugin-segment/src/services/__tests__/segment.js new file mode 100644 index 0000000000..852820efc8 --- /dev/null +++ b/packages/medusa-plugin-segment/src/services/__tests__/segment.js @@ -0,0 +1,188 @@ +import SegmentService from "../segment" + +jest.mock("analytics-node") + +const orderFactory = (config = {}) => { + return { + id: "12355", + display_id: "1234", + cart_id: "cart_13", + region_id: "reg_123", + items: [ + { + title: "Test", + variant: { + product_id: "prod_123", + sku: "TEST", + }, + unit_price: 1100, + quantity: 2, + }, + ], + shipping_methods: [ + { + name: "standard", + price: 12399, + }, + ], + payments: [ + { + id: "123", + }, + ], + tax_rate: 23.1, + currency_code: "DKK", + discounts: [], + shipping_address: { + first_name: "Test", + last_name: "Testson", + address_1: "Test", + address_2: "TEst", + postal_code: "1234", + country_code: "DK", + phone: "12345678", + }, + email: "test@example.com", + subtotal: 2200, + total: 12399, + tax_total: 0, + shipping_total: 12399, + discount_total: 0, + gift_card_total: 0, + ...config, + } +} + +describe("SegmentService", () => { + const ProductService = { + retrieve: () => + Promise.resolve({ + collection: { title: "Collection" }, + type: { value: "Type" }, + subtitle: "Subtitle", + }), + } + + const TotalsService = { + getLineItemRefund: (_, item) => { + return item.unit_price + }, + } + + describe("buildOrder", () => { + const segmentService = new SegmentService( + { + productService: ProductService, + totalsService: TotalsService, + }, + { account: "test" } + ) + + segmentService.getReportingValue = async (_, v) => { + const num = v + return Promise.resolve(Number(Math.round(num + "e2") + "e-2")) + } + + it("successfully builds sales order", async () => { + jest.clearAllMocks() + + const order = orderFactory() + const segmentOrder = await segmentService.buildOrder(order) + + expect(segmentOrder).toEqual({ + checkout_id: "cart_13", + coupon: undefined, + currency: "DKK", + discount: 0, + email: "test@example.com", + order_id: "12355", + payment_provider: "", + products: [ + { + category: "Collection", + name: "Test", + price: 4.47, + product_id: "prod_123", + quantity: 2, + reporting_revenue: 8.94, + sku: "", + subtitle: "Subtitle", + type: "Type", + variant: "TEST", + }, + ], + region_id: "reg_123", + reporting_discount: 0, + reporting_revenue: 123.99, + reporting_shipping: 123.99, + reporting_subtotal: 22, + reporting_tax: 0, + reporting_total: 123.99, + revenue: 123.99, + shipping: 123.99, + shipping_city: undefined, + shipping_country: "DK", + shipping_methods: [ + { + name: "standard", + price: 12399, + }, + ], + subtotal: 22, + tax: 0, + total: 123.99, + }) + }) + + it("successfully builds order with zero decimal currency", async () => { + jest.clearAllMocks() + + const order = orderFactory({ currency_code: "krw" }) + const segmentOrder = await segmentService.buildOrder(order) + + expect(segmentOrder).toEqual({ + checkout_id: "cart_13", + coupon: undefined, + currency: "KRW", + discount: 0, + email: "test@example.com", + order_id: "12355", + payment_provider: "", + products: [ + { + category: "Collection", + name: "Test", + price: 446.79, + product_id: "prod_123", + quantity: 2, + reporting_revenue: 893.58, + sku: "", + subtitle: "Subtitle", + type: "Type", + variant: "TEST", + }, + ], + region_id: "reg_123", + reporting_discount: 0, + reporting_revenue: 12399, + reporting_shipping: 12399, + reporting_subtotal: 2200, + reporting_tax: 0, + reporting_total: 12399, + revenue: 12399, + shipping: 12399, + shipping_city: undefined, + shipping_country: "DK", + shipping_methods: [ + { + name: "standard", + price: 12399, + }, + ], + subtotal: 2200, + tax: 0, + total: 12399, + }) + }) + }) +}) diff --git a/packages/medusa-plugin-segment/src/services/segment.js b/packages/medusa-plugin-segment/src/services/segment.js index 6318f50a79..bd7eadee2a 100644 --- a/packages/medusa-plugin-segment/src/services/segment.js +++ b/packages/medusa-plugin-segment/src/services/segment.js @@ -1,6 +1,7 @@ import Analytics from "analytics-node" import axios from "axios" import { BaseService } from "medusa-interfaces" +import { humanizeAmount } from "medusa-core-utils" class SegmentService extends BaseService { /** @@ -43,26 +44,28 @@ class SegmentService extends BaseService { "EUR" if (fromCurrency === toCurrency) { - return this.totalsService_.rounded(value) + return this.rounded_(value) } const exchangeRate = await axios .get( - `https://api.exchangeratesapi.io/${date}?symbols=${fromCurrency}&base=${toCurrency}` + `https://api.exchangeratesapi.io/${date}?symbols=${fromCurrency}&base=${toCurrency}&access_key=${this.options_.exchange_rates_api_key}` ) .then(({ data }) => { return data.rates[fromCurrency] }) - return this.totalsService_.rounded(value / exchangeRate) + return this.rounded_(value / exchangeRate) } async buildOrder(order) { - const subtotal = order.subtotal / 100 - const total = order.total / 100 - const tax = order.tax_total / 100 - const discount = order.discount_total / 100 - const shipping = order.shipping_total / 100 + const curr = order.currency_code + + const subtotal = humanizeAmount(order.subtotal, curr) + const total = humanizeAmount(order.total, curr) + const tax = humanizeAmount(order.tax_total, curr) + const discount = humanizeAmount(order.discount_total, curr) + const shipping = humanizeAmount(order.shipping_total, curr) const revenue = total - tax let coupon @@ -119,7 +122,7 @@ class SegmentService extends BaseService { const revenue = await this.getReportingValue( order.currency_code, - lineTotal / 100 + humanizeAmount(lineTotal, curr) ) let sku = "" @@ -141,7 +144,9 @@ class SegmentService extends BaseService { return { name, variant, - price: lineTotal / 100 / item.quantity, + price: this.rounded_( + humanizeAmount(lineTotal, curr) / item.quantity + ), reporting_revenue: revenue, product_id: item.variant.product_id, category: product.collection?.title, @@ -156,6 +161,10 @@ class SegmentService extends BaseService { return orderData } + + rounded_(v) { + return Number(Math.round(v + "e2") + "e-2") + } } export default SegmentService diff --git a/packages/medusa-plugin-sendgrid/CHANGELOG.md b/packages/medusa-plugin-sendgrid/CHANGELOG.md index 72fc746ae4..2769c5567f 100644 --- a/packages/medusa-plugin-sendgrid/CHANGELOG.md +++ b/packages/medusa-plugin-sendgrid/CHANGELOG.md @@ -3,6 +3,18 @@ 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/medusa-plugin-sendgrid@1.1.7...medusa-plugin-sendgrid@1.1.8) (2021-03-30) + + +### Bug Fixes + +* format numbers correctly in sendgrid ([7682980](https://github.com/medusajs/medusa/commit/7682980c58f1a01f0c510b1d4feae3a62892040c)) +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + ## [1.1.7](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.6...medusa-plugin-sendgrid@1.1.7) (2021-03-17) **Note:** Version bump only for package medusa-plugin-sendgrid diff --git a/packages/medusa-plugin-sendgrid/package.json b/packages/medusa-plugin-sendgrid/package.json index 1ada3022f6..ecd280de88 100644 --- a/packages/medusa-plugin-sendgrid/package.json +++ b/packages/medusa-plugin-sendgrid/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-sendgrid", - "version": "1.1.7", + "version": "1.1.8", "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.3", - "medusa-test-utils": "^1.1.6" + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7" }, - "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" + "gitHead": "d78a7ce85876e0bfd9a4bfebe4f5743921961e9c" } diff --git a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js index 61aeb788e4..5f30c1ec1c 100644 --- a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js +++ b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js @@ -1,6 +1,8 @@ -import { NotificationService } from "medusa-interfaces" import SendGrid from "@sendgrid/mail" +import { NotificationService } from "medusa-interfaces" +import { humanizeAmount, zeroDecimalCurrencies } from "medusa-core-utils" + class SendGridService extends NotificationService { static identifier = "sendgrid" @@ -361,18 +363,24 @@ class SendGridService extends NotificationService { date: order.created_at.toDateString(), items, discounts, - subtotal: `${this.humanPrice_(subtotal * (1 + taxRate))} ${currencyCode}`, - gift_card_total: `${this.humanPrice_( - gift_card_total * (1 + taxRate) + subtotal: `${this.humanPrice_( + subtotal * (1 + taxRate), + currencyCode )} ${currencyCode}`, - tax_total: `${this.humanPrice_(tax_total)} ${currencyCode}`, + gift_card_total: `${this.humanPrice_( + gift_card_total * (1 + taxRate), + currencyCode + )} ${currencyCode}`, + tax_total: `${this.humanPrice_(tax_total, currencyCode)} ${currencyCode}`, discount_total: `${this.humanPrice_( - discount_total * (1 + taxRate) + discount_total * (1 + taxRate), + currencyCode )} ${currencyCode}`, shipping_total: `${this.humanPrice_( - shipping_total * (1 + taxRate) + shipping_total * (1 + taxRate), + currencyCode )} ${currencyCode}`, - total: `${this.humanPrice_(total)} ${currencyCode}`, + total: `${this.humanPrice_(total, currencyCode)} ${currencyCode}`, } } @@ -450,15 +458,23 @@ class SendGridService extends NotificationService { has_shipping: !!returnRequest.shipping_method, email: order.email, items: this.processItems_(returnItems, taxRate, currencyCode), - subtotal: `${this.humanPrice_(item_subtotal)} ${currencyCode}`, - shipping_total: `${this.humanPrice_(shippingTotal)} ${currencyCode}`, + subtotal: `${this.humanPrice_( + item_subtotal, + currencyCode + )} ${currencyCode}`, + shipping_total: `${this.humanPrice_( + shippingTotal, + currencyCode + )} ${currencyCode}`, refund_amount: `${this.humanPrice_( - returnRequest.refund_amount + returnRequest.refund_amount, + currencyCode )} ${currencyCode}`, return_request: { ...returnRequest, refund_amount: `${this.humanPrice_( - returnRequest.refund_amount + returnRequest.refund_amount, + currencyCode )} ${currencyCode}`, }, order, @@ -539,9 +555,18 @@ class SendGridService extends NotificationService { email: order.email, items: this.processItems_(swap.additional_items, taxRate, currencyCode), return_items: returnItems, - return_total: `${this.humanPrice_(returnTotal)} ${currencyCode}`, - refund_amount: `${this.humanPrice_(refundAmount)} ${currencyCode}`, - additional_total: `${this.humanPrice_(additionalTotal)} ${currencyCode}`, + return_total: `${this.humanPrice_( + returnTotal, + currencyCode + )} ${currencyCode}`, + refund_amount: `${this.humanPrice_( + refundAmount, + currencyCode + )} ${currencyCode}`, + additional_total: `${this.humanPrice_( + additionalTotal, + currencyCode + )} ${currencyCode}`, } } @@ -602,12 +627,25 @@ class SendGridService extends NotificationService { date: swap.updated_at.toDateString(), email: order.email, tax_amount: `${this.humanPrice_( - swap.difference_due * taxRate + swap.difference_due * taxRate, + currencyCode + )} ${currencyCode}`, + paid_total: `${this.humanPrice_( + swap.difference_due, + currencyCode + )} ${currencyCode}`, + return_total: `${this.humanPrice_( + returnTotal, + currencyCode + )} ${currencyCode}`, + refund_amount: `${this.humanPrice_( + refundAmount, + currencyCode + )} ${currencyCode}`, + additional_total: `${this.humanPrice_( + additionalTotal, + currencyCode )} ${currencyCode}`, - paid_total: `${this.humanPrice_(swap.difference_due)} ${currencyCode}`, - return_total: `${this.humanPrice_(returnTotal)} ${currencyCode}`, - refund_amount: `${this.humanPrice_(refundAmount)} ${currencyCode}`, - additional_total: `${this.humanPrice_(additionalTotal)} ${currencyCode}`, fulfillment: shipment, tracking_links: shipment.tracking_links, tracking_number: shipment.tracking_numbers.join(", "), @@ -647,14 +685,20 @@ class SendGridService extends NotificationService { ...i, thumbnail: this.normalizeThumbUrl_(i.thumbnail), price: `${this.humanPrice_( - i.unit_price * (1 + taxRate) + i.unit_price * (1 + taxRate), + currencyCode )} ${currencyCode}`, } }) } - humanPrice_(amount) { - return amount ? (amount / 100).toFixed(2) : "0.00" + humanPrice_(amount, currency) { + if (!amount) { + return "0.00" + } + + const normalized = humanizeAmount(amount, currency) + return normalized.toFixed(zeroDecimalCurrencies.includes(currency.toLowerCase()) ? 0 : 2) } normalizeThumbUrl_(url) { diff --git a/packages/medusa-plugin-slack-notification/CHANGELOG.md b/packages/medusa-plugin-slack-notification/CHANGELOG.md index 64f73c2045..e4fb433fbc 100644 --- a/packages/medusa-plugin-slack-notification/CHANGELOG.md +++ b/packages/medusa-plugin-slack-notification/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.7](https://github.com/medusajs/medusa/compare/medusa-plugin-slack-notification@1.1.6...medusa-plugin-slack-notification@1.1.7) (2021-03-30) + + +### Bug Fixes + +* **slack:** show discount code flag ([b5bf650](https://github.com/medusajs/medusa/commit/b5bf650ec26182be6324bc56e7f6efd744a7131e)) +* zero decimal amounts in slack + gc total ([c6a5dff](https://github.com/medusajs/medusa/commit/c6a5dffa7bd8f627310d1f90364492084051dd47)) + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-plugin-slack-notification@1.1.5...medusa-plugin-slack-notification@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-plugin-slack-notification diff --git a/packages/medusa-plugin-slack-notification/package-lock.json b/packages/medusa-plugin-slack-notification/package-lock.json index 8d11bc73b9..f61068049e 100644 --- a/packages/medusa-plugin-slack-notification/package-lock.json +++ b/packages/medusa-plugin-slack-notification/package-lock.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-economic", - "version": "1.1.6", + "version": "1.1.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/medusa-plugin-slack-notification/package.json b/packages/medusa-plugin-slack-notification/package.json index a731fe3a49..32f4ee5ad0 100644 --- a/packages/medusa-plugin-slack-notification/package.json +++ b/packages/medusa-plugin-slack-notification/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-slack-notification", - "version": "1.1.6", + "version": "1.1.7", "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.3", - "medusa-test-utils": "^1.1.6", + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7", "moment": "^2.27.0" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa-plugin-slack-notification/src/services/slack.js b/packages/medusa-plugin-slack-notification/src/services/slack.js index d67069d9c3..5821191e95 100644 --- a/packages/medusa-plugin-slack-notification/src/services/slack.js +++ b/packages/medusa-plugin-slack-notification/src/services/slack.js @@ -1,10 +1,13 @@ import axios from "axios" +import { zeroDecimalCurrencies, humanizeAmount } from "medusa-core-utils" import { BaseService } from "medusa-interfaces" class SlackService extends BaseService { /** * @param {Object} options - options defined in `medusa-config.js` * { + * show_discount_code: If set to true the discount code used will be + * displayed in the order channel. * slack_url: "https://hooks.slack.com/services/...", * admin_orders_url: "https:..../orders" * } @@ -58,6 +61,14 @@ class SlackService extends BaseService { const currencyCode = order.currency_code.toUpperCase() const taxRate = order.tax_rate / 100 + const getDisplayAmount = (amount) => { + const humanAmount = humanizeAmount(amount, currencyCode) + if (zeroDecimalCurrencies.includes(currencyCode.toLowerCase())) { + return humanAmount + } + return humanAmount.toFixed(2) + } + let blocks = [ { type: "section", @@ -83,32 +94,46 @@ class SlackService extends BaseService { type: "section", text: { type: "mrkdwn", - text: `*Subtotal*\t${(subtotal / 100).toFixed( - 2 - )} ${currencyCode}\n*Shipping*\t${(shipping_total / 100).toFixed( - 2 - )} ${currencyCode}\n*Discount Total*\t${( - discount_total / 100 - ).toFixed(2)} ${currencyCode}\n*Tax*\t${(tax_total / 100).toFixed( - 2 - )} ${currencyCode}\n*Total*\t${(total / 100).toFixed( - 2 + text: `*Subtotal*\t${getDisplayAmount( + subtotal + )} ${currencyCode}\n*Shipping*\t${getDisplayAmount( + shipping_total + )} ${currencyCode}\n*Discount Total*\t${getDisplayAmount( + discount_total + )} ${currencyCode}\n*Tax*\t${getDisplayAmount( + tax_total + )} ${currencyCode}\n*Total*\t${getDisplayAmount( + total )} ${currencyCode}`, }, }, ] - order.discounts.forEach((d) => { + if (order.gift_card_total) { blocks.push({ type: "section", text: { type: "mrkdwn", - text: `*Promo Code*\t${d.code} ${d.rule.value}${ - d.rule.type === "percentage" ? "%" : ` ${currencyCode}` - }`, + text: `*Gift Card Total*\t${getDisplayAmount( + order.gift_card_total + )} ${currencyCode}`, }, }) - }) + } + + if (this.options_.show_discount_code) { + order.discounts.forEach((d) => { + blocks.push({ + type: "section", + text: { + type: "mrkdwn", + text: `*Promo Code*\t${d.code} ${d.rule.value}${ + d.rule.type === "percentage" ? "%" : ` ${currencyCode}` + }`, + }, + }) + }) + } blocks.push({ type: "divider", @@ -119,19 +144,15 @@ class SlackService extends BaseService { type: "section", text: { type: "mrkdwn", - text: `*${lineItem.title}*\n${lineItem.quantity} x ${( - (lineItem.unit_price / 100) * - (1 + taxRate) - ).toFixed(2)} ${currencyCode}`, + text: `*${lineItem.title}*\n${lineItem.quantity} x ${getDisplayAmount( + lineItem.unit_price * (1 + taxRate) + )} ${currencyCode}`, }, } if (lineItem.thumbnail) { let url = lineItem.thumbnail - if ( - !lineItem.thumbnail.startsWith("http:") && - !lineItem.thumbnail.startsWith("https:") - ) { + if (lineItem.thumbnail.startsWith("//")) { url = `https:${lineItem.thumbnail}` } diff --git a/packages/medusa-plugin-twilio-sms/CHANGELOG.md b/packages/medusa-plugin-twilio-sms/CHANGELOG.md index 7236118b72..eff921cb0f 100644 --- a/packages/medusa-plugin-twilio-sms/CHANGELOG.md +++ b/packages/medusa-plugin-twilio-sms/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-plugin-twilio-sms@1.1.6...medusa-plugin-twilio-sms@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-plugin-twilio-sms + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-plugin-twilio-sms@1.1.5...medusa-plugin-twilio-sms@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-plugin-twilio-sms diff --git a/packages/medusa-plugin-twilio-sms/package.json b/packages/medusa-plugin-twilio-sms/package.json index 5a827b5d15..a657751024 100644 --- a/packages/medusa-plugin-twilio-sms/package.json +++ b/packages/medusa-plugin-twilio-sms/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-twilio-sms", - "version": "1.1.6", + "version": "1.1.7", "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.3", - "medusa-test-utils": "^1.1.6", + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7", "twilio": "^3.49.1" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa-plugin-wishlist/CHANGELOG.md b/packages/medusa-plugin-wishlist/CHANGELOG.md index be8e6d32f9..f841ab8cca 100644 --- a/packages/medusa-plugin-wishlist/CHANGELOG.md +++ b/packages/medusa-plugin-wishlist/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-plugin-wishlist@1.1.6...medusa-plugin-wishlist@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-plugin-wishlist + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-plugin-wishlist@1.1.5...medusa-plugin-wishlist@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-plugin-wishlist diff --git a/packages/medusa-plugin-wishlist/package.json b/packages/medusa-plugin-wishlist/package.json index 19e06fa2e6..dd0907daf8 100644 --- a/packages/medusa-plugin-wishlist/package.json +++ b/packages/medusa-plugin-wishlist/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-wishlist", - "version": "1.1.6", + "version": "1.1.7", "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.3", - "medusa-test-utils": "^1.1.6" + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" } diff --git a/packages/medusa-test-utils/CHANGELOG.md b/packages/medusa-test-utils/CHANGELOG.md index 5adda9185a..241696c081 100644 --- a/packages/medusa-test-utils/CHANGELOG.md +++ b/packages/medusa-test-utils/CHANGELOG.md @@ -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.7](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.6...medusa-test-utils@1.1.7) (2021-03-30) + +**Note:** Version bump only for package medusa-test-utils + + + + + ## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.5...medusa-test-utils@1.1.6) (2021-03-17) **Note:** Version bump only for package medusa-test-utils diff --git a/packages/medusa-test-utils/package.json b/packages/medusa-test-utils/package.json index 4cfdf0a7e3..5de9ef2cb1 100644 --- a/packages/medusa-test-utils/package.json +++ b/packages/medusa-test-utils/package.json @@ -1,6 +1,6 @@ { "name": "medusa-test-utils", - "version": "1.1.6", + "version": "1.1.7", "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.3", + "medusa-core-utils": "^1.1.4", "randomatic": "^3.1.1" }, "gitHead": "0646bd395a6056657cb0aa93c13699c4a9dbbcdd" diff --git a/packages/medusa/CHANGELOG.md b/packages/medusa/CHANGELOG.md index 28e48548c6..ce40936878 100644 --- a/packages/medusa/CHANGELOG.md +++ b/packages/medusa/CHANGELOG.md @@ -3,6 +3,47 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.17](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.16...@medusajs/medusa@1.1.17) (2021-03-30) + + +### Bug Fixes + +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + +## [1.1.16](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.16...@medusajs/medusa@1.1.16) (2021-03-30) + + +### Bug Fixes + +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + +## [1.1.15](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.16...@medusajs/medusa@1.1.15) (2021-03-30) + + +### Bug Fixes + +* publish assist ([7719957](https://github.com/medusajs/medusa/commit/7719957b44a0c0d950eff948faf31188fe0e3ef1)) + + + + + +## [1.1.16](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.15...@medusajs/medusa@1.1.16) (2021-03-26) + +**Note:** Version bump only for package @medusajs/medusa + + + + + ## [1.1.15](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.14...@medusajs/medusa@1.1.15) (2021-03-18) **Note:** Version bump only for package @medusajs/medusa diff --git a/packages/medusa/package.json b/packages/medusa/package.json index 610d60d8a9..cdc673e5d7 100644 --- a/packages/medusa/package.json +++ b/packages/medusa/package.json @@ -1,6 +1,6 @@ { "name": "@medusajs/medusa", - "version": "1.1.15", + "version": "1.1.17", "description": "E-commerce for JAMstack", "main": "dist/index.js", "repository": { @@ -67,8 +67,8 @@ "joi": "^17.3.0", "joi-objectid": "^3.0.1", "jsonwebtoken": "^8.5.1", - "medusa-core-utils": "^1.1.3", - "medusa-test-utils": "^1.1.6", + "medusa-core-utils": "^1.1.4", + "medusa-test-utils": "^1.1.7", "morgan": "^1.9.1", "multer": "^1.4.2", "passport": "^0.4.0", @@ -86,5 +86,5 @@ "uuid": "^8.3.1", "winston": "^3.2.1" }, - "gitHead": "8c87f25f766154368b0f15424028550966f7d3d6" + "gitHead": "d78a7ce85876e0bfd9a4bfebe4f5743921961e9c" } diff --git a/packages/medusa/src/services/claim-item.js b/packages/medusa/src/services/claim-item.js index 8a508c9767..6b547a83e3 100644 --- a/packages/medusa/src/services/claim-item.js +++ b/packages/medusa/src/services/claim-item.js @@ -83,27 +83,35 @@ class ClaimItemService extends BaseService { ) } - const claimTagRepo = manager.getCustomRepository(this.claimTagRepository_) - const tagsToAdd = await Promise.all( - tags.map(async t => { - const normalized = t.trim().toLowerCase() - const existing = await claimTagRepo.findOne({ - where: { value: normalized }, + let tagsToAdd = [] + if (tags && tags.length) { + const claimTagRepo = manager.getCustomRepository( + this.claimTagRepository_ + ) + tagsToAdd = await Promise.all( + tags.map(async t => { + const normalized = t.trim().toLowerCase() + const existing = await claimTagRepo.findOne({ + where: { value: normalized }, + }) + if (existing) { + return existing + } + + return claimTagRepo.create({ value: normalized }) }) - if (existing) { - return existing - } + ) + } - return claimTagRepo.create({ value: normalized }) + let imagesToAdd = [] + if (images && images.length) { + const claimImgRepo = manager.getCustomRepository( + this.claimImageRepository_ + ) + imagesToAdd = images.map(url => { + return claimImgRepo.create({ url }) }) - ) - - const claimImgRepo = manager.getCustomRepository( - this.claimImageRepository_ - ) - const imagesToAdd = images.map(url => { - return claimImgRepo.create({ url }) - }) + } const created = ciRepo.create({ ...rest,