@commercetools/connect-payments-sdk 0.18.1 → 0.20.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 +12 -0
- package/dist/commercetools/helpers/taxrate.converter.d.ts +17 -0
- package/dist/commercetools/helpers/taxrate.converter.js +33 -0
- package/dist/commercetools/index.d.ts +2 -1
- package/dist/commercetools/index.js +2 -1
- package/dist/commercetools/services/ct-payment.service.d.ts +1 -0
- package/dist/commercetools/services/ct-payment.service.js +12 -5
- package/dist/commercetools/types/payment.type.d.ts +3 -7
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @commercetools/connect-payments-sdk
|
|
2
2
|
|
|
3
|
+
## 0.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 772d5be: Add support for updating payment interface interactions. It introduces a breaking change, the CustomFieldsData type has been removed.
|
|
8
|
+
|
|
9
|
+
## 0.19.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 16d7341: feat(sdk): add and export function to convert coco line item tax rate into minor units
|
|
14
|
+
|
|
3
15
|
## 0.18.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -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;
|
|
@@ -4,5 +4,6 @@ export { SessionService as CommercetoolsSessionService, Session } from './types/
|
|
|
4
4
|
export { AuthorizationService as CommercetoolsAuthorizationService } from './types/authorization.type';
|
|
5
5
|
export { OrderService as CommercetoolsOrderService } from './types/order.type';
|
|
6
6
|
export { CommercetoolsClient } from './types/api.type';
|
|
7
|
-
export { Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, } from '@commercetools/platform-sdk';
|
|
7
|
+
export { CustomFields, 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"));
|
|
@@ -18,6 +18,7 @@ export declare class DefaultPaymentService implements PaymentService {
|
|
|
18
18
|
private populateChangeTransactionState;
|
|
19
19
|
private populateSetPaymentMethod;
|
|
20
20
|
private populateSetCustomType;
|
|
21
|
+
private populateAddInterfaceInteractions;
|
|
21
22
|
findMatchingTransactions(payment: Payment, transaction: TransactionData): Transaction[];
|
|
22
23
|
private consolidateTransactionChanges;
|
|
23
24
|
}
|
|
@@ -76,6 +76,9 @@ class DefaultPaymentService {
|
|
|
76
76
|
if (updateInfo.customFields) {
|
|
77
77
|
actions.push(this.populateSetCustomType(updateInfo.customFields));
|
|
78
78
|
}
|
|
79
|
+
if (updateInfo.pspInteractions && updateInfo.pspInteractions.length > 0) {
|
|
80
|
+
actions.push(...this.populateAddInterfaceInteractions(updateInfo.pspInteractions));
|
|
81
|
+
}
|
|
79
82
|
return actions;
|
|
80
83
|
}
|
|
81
84
|
populateSetInterfaceIdAction(interfaceId) {
|
|
@@ -116,13 +119,17 @@ class DefaultPaymentService {
|
|
|
116
119
|
populateSetCustomType(customFields) {
|
|
117
120
|
return {
|
|
118
121
|
action: 'setCustomType',
|
|
119
|
-
|
|
120
|
-
typeId: 'type',
|
|
121
|
-
key: customFields.typeKey,
|
|
122
|
-
},
|
|
123
|
-
fields: customFields.fields,
|
|
122
|
+
...customFields,
|
|
124
123
|
};
|
|
125
124
|
}
|
|
125
|
+
populateAddInterfaceInteractions(pspInteractions) {
|
|
126
|
+
return pspInteractions.map((interaction) => {
|
|
127
|
+
return {
|
|
128
|
+
action: 'addInterfaceInteraction',
|
|
129
|
+
...interaction,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
}
|
|
126
133
|
findMatchingTransactions(payment, transaction) {
|
|
127
134
|
return payment.transactions.filter((tx) => {
|
|
128
135
|
return (tx.type === transaction.type &&
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Money, Payment, PaymentDraft, TransactionState, TransactionType } from '@commercetools/platform-sdk';
|
|
1
|
+
import { CustomFields, Money, Payment, PaymentDraft, TransactionState, TransactionType } from '@commercetools/platform-sdk';
|
|
2
2
|
import { CommercetoolsAPI } from './api.type';
|
|
3
3
|
import { Logger } from '../../logger';
|
|
4
4
|
export type PaymentAmount = {
|
|
@@ -27,17 +27,13 @@ export type TransactionData = {
|
|
|
27
27
|
interactionId?: string;
|
|
28
28
|
state: TransactionState;
|
|
29
29
|
};
|
|
30
|
-
export type CustomFieldsData = {
|
|
31
|
-
typeKey: string;
|
|
32
|
-
fields: Record<string, unknown>;
|
|
33
|
-
};
|
|
34
30
|
export type UpdatePayment = {
|
|
35
31
|
id: string;
|
|
36
32
|
pspReference?: string;
|
|
37
|
-
|
|
33
|
+
pspInteractions?: CustomFields[];
|
|
38
34
|
transaction?: TransactionData;
|
|
39
35
|
paymentMethod?: string;
|
|
40
|
-
customFields?:
|
|
36
|
+
customFields?: CustomFields;
|
|
41
37
|
};
|
|
42
38
|
/**
|
|
43
39
|
* Payment service interface exposes methods to interact with the commercetools platform API.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Payment SDK for commercetools payment connectors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@commercetools-backend/loggers": "
|
|
19
|
-
"@commercetools/platform-sdk": "8.
|
|
18
|
+
"@commercetools-backend/loggers": "23.2.0",
|
|
19
|
+
"@commercetools/platform-sdk": "8.5.0",
|
|
20
20
|
"@commercetools/sdk-client-v2": "2.5.0",
|
|
21
21
|
"jsonwebtoken": "9.0.2",
|
|
22
|
-
"jwks-rsa": "3.
|
|
22
|
+
"jwks-rsa": "3.2.0",
|
|
23
23
|
"lodash": "4.17.21",
|
|
24
24
|
"logform": "2.7.0"
|
|
25
25
|
}
|