@commercetools/connect-payments-sdk 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert the CoCo tax percentage, for example found on "lineItems", which ranges from 0-1 as floating point numbers to the minor units.
|
|
3
|
+
*
|
|
4
|
+
* @example CoCo taxRate of 0.21, normalized is 21%, in minor-units = 2100
|
|
5
|
+
* @example CoCo taxRate of 0.07, normalized is 7%, in minor-units = 700
|
|
6
|
+
* @example CoCo taxRate of 0.489, normalized is 48.9%, in minor-units = 4891
|
|
7
|
+
*
|
|
8
|
+
* @param decimalTaxRate the tax rate expressed in decimals between 0-1 as floating point numbers taken from the CoCo taxRate (see docs below).
|
|
9
|
+
*
|
|
10
|
+
* @throw "Error" if the provided value is not between 0 and 1;
|
|
11
|
+
*
|
|
12
|
+
* @returns 0 if undefined is provided
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.commercetools.com/api/projects/taxCategories#ctp:api:type:TaxRate
|
|
15
|
+
*/
|
|
16
|
+
declare const convertCoCoTaxPercentage: (decimalTaxRate?: number) => number;
|
|
17
|
+
export { convertCoCoTaxPercentage };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertCoCoTaxPercentage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convert the CoCo tax percentage, for example found on "lineItems", which ranges from 0-1 as floating point numbers to the minor units.
|
|
6
|
+
*
|
|
7
|
+
* @example CoCo taxRate of 0.21, normalized is 21%, in minor-units = 2100
|
|
8
|
+
* @example CoCo taxRate of 0.07, normalized is 7%, in minor-units = 700
|
|
9
|
+
* @example CoCo taxRate of 0.489, normalized is 48.9%, in minor-units = 4891
|
|
10
|
+
*
|
|
11
|
+
* @param decimalTaxRate the tax rate expressed in decimals between 0-1 as floating point numbers taken from the CoCo taxRate (see docs below).
|
|
12
|
+
*
|
|
13
|
+
* @throw "Error" if the provided value is not between 0 and 1;
|
|
14
|
+
*
|
|
15
|
+
* @returns 0 if undefined is provided
|
|
16
|
+
*
|
|
17
|
+
* @see https://docs.commercetools.com/api/projects/taxCategories#ctp:api:type:TaxRate
|
|
18
|
+
*/
|
|
19
|
+
const convertCoCoTaxPercentage = (decimalTaxRate) => {
|
|
20
|
+
if (!decimalTaxRate) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
if (decimalTaxRate < 0 || decimalTaxRate > 1) {
|
|
24
|
+
throw new Error(`The provided decimal tax rate of ${decimalTaxRate} is invalid. Only allowed values between 0 and 1.0`);
|
|
25
|
+
}
|
|
26
|
+
// First go from the range of 0 - 1 decimal value, to value expressed as a "normal" percentage. I.e. 0.15% from CoCo becomes 15.
|
|
27
|
+
const taxRateNormalized = decimalTaxRate * Math.pow(10, 2);
|
|
28
|
+
// Apply conversion to make it a minor unit "minor-units" format. I.e. 15 becomes 1500.
|
|
29
|
+
const taxRateMinorUnitsFormat = taxRateNormalized * Math.pow(10, 2);
|
|
30
|
+
const taxRateMinorUnit = taxRateMinorUnitsFormat.toFixed(0);
|
|
31
|
+
return parseInt(taxRateMinorUnit);
|
|
32
|
+
};
|
|
33
|
+
exports.convertCoCoTaxPercentage = convertCoCoTaxPercentage;
|
|
@@ -6,3 +6,4 @@ export { OrderService as CommercetoolsOrderService } from './types/order.type';
|
|
|
6
6
|
export { CommercetoolsClient } from './types/api.type';
|
|
7
7
|
export { Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, } from '@commercetools/platform-sdk';
|
|
8
8
|
export * as CurrencyConverters from './helpers/currency.converter';
|
|
9
|
+
export * as TaxRateConverter from './helpers/taxrate.converter';
|
|
@@ -33,5 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.CurrencyConverters = void 0;
|
|
36
|
+
exports.TaxRateConverter = exports.CurrencyConverters = void 0;
|
|
37
37
|
exports.CurrencyConverters = __importStar(require("./helpers/currency.converter"));
|
|
38
|
+
exports.TaxRateConverter = __importStar(require("./helpers/taxrate.converter"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Payment SDK for commercetools payment connectors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@commercetools-backend/loggers": "22.
|
|
18
|
+
"@commercetools-backend/loggers": "22.41.0",
|
|
19
19
|
"@commercetools/platform-sdk": "8.1.0",
|
|
20
20
|
"@commercetools/sdk-client-v2": "2.5.0",
|
|
21
21
|
"jsonwebtoken": "9.0.2",
|