@commercetools/connect-payments-sdk 0.12.0 → 0.13.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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Cart } from '@commercetools/platform-sdk';
|
|
3
|
-
import { PaymentAmount } from '../types/payment.type';
|
|
1
|
+
import { Address, Cart } from '@commercetools/platform-sdk';
|
|
4
2
|
import { AddPayment } from '../types/api.type';
|
|
3
|
+
import { CartService, CartServiceOptions, GetCart, GetCartByPaymentIdRequest, GetNormalizedShipping, GetOneShippingAddress, GetPaymentAmount, NormalizedShipping } from '../types/cart.type';
|
|
4
|
+
import { PaymentAmount } from '../types/payment.type';
|
|
5
5
|
/**
|
|
6
6
|
* Default implementation of the CartService interface.
|
|
7
7
|
*/
|
|
@@ -12,6 +12,19 @@ export declare class DefaultCartService implements CartService {
|
|
|
12
12
|
getCartByPaymentId(opts: GetCartByPaymentIdRequest): Promise<Cart>;
|
|
13
13
|
getCart(opts: GetCart): Promise<Cart>;
|
|
14
14
|
getPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
|
|
15
|
+
/**
|
|
16
|
+
* Get only one shipping address from the cart. If the cart has multiple shipping addresses, it returns the first one.
|
|
17
|
+
* @param cart
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
getOneShippingAddress(opts: GetOneShippingAddress): Address | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes the shipping info from the cart. If the cart has a single shipping info, it returns an array with that shipping info.
|
|
23
|
+
* When the cart has multiple shipping infos, it returns an array with all the shipping infos.
|
|
24
|
+
* @param opts
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getNormalizedShipping(opts: GetNormalizedShipping): NormalizedShipping[];
|
|
15
28
|
addPayment(opts: AddPayment): Promise<Cart>;
|
|
16
29
|
private calculateTotalPaidAmount;
|
|
17
30
|
private calculatePaymentAmount;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultCartService = void 0;
|
|
4
|
-
const ct_api_error_1 = require("../errors/ct-api.error");
|
|
5
4
|
const __1 = require("../..");
|
|
5
|
+
const ct_api_error_1 = require("../errors/ct-api.error");
|
|
6
6
|
/**
|
|
7
7
|
* Default implementation of the CartService interface.
|
|
8
8
|
*/
|
|
@@ -61,6 +61,44 @@ class DefaultCartService {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Get only one shipping address from the cart. If the cart has multiple shipping addresses, it returns the first one.
|
|
66
|
+
* @param cart
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
getOneShippingAddress(opts) {
|
|
70
|
+
if (opts.cart.shippingMode === 'Single') {
|
|
71
|
+
return opts.cart.shippingAddress;
|
|
72
|
+
}
|
|
73
|
+
if (opts.cart.shippingMode === 'Multiple' && opts.cart.shipping && opts.cart.shipping.length > 0) {
|
|
74
|
+
return opts.cart.shipping[0].shippingAddress;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Normalizes the shipping info from the cart. If the cart has a single shipping info, it returns an array with that shipping info.
|
|
79
|
+
* When the cart has multiple shipping infos, it returns an array with all the shipping infos.
|
|
80
|
+
* @param opts
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
getNormalizedShipping(opts) {
|
|
84
|
+
if (opts.cart.shippingMode === 'Single' && opts.cart.shippingInfo) {
|
|
85
|
+
return opts.cart.shippingInfo && opts.cart.shippingAddress
|
|
86
|
+
? [
|
|
87
|
+
{
|
|
88
|
+
shippingAddress: opts.cart.shippingAddress,
|
|
89
|
+
shippingInfo: opts.cart.shippingInfo,
|
|
90
|
+
},
|
|
91
|
+
]
|
|
92
|
+
: [];
|
|
93
|
+
}
|
|
94
|
+
if (opts.cart.shippingMode === 'Multiple' && opts.cart.shipping && opts.cart.shipping.length > 0) {
|
|
95
|
+
return opts.cart.shipping.map((shipping) => ({
|
|
96
|
+
shippingAddress: shipping.shippingAddress,
|
|
97
|
+
shippingInfo: shipping.shippingInfo,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
64
102
|
async addPayment(opts) {
|
|
65
103
|
const maxRetries = 6;
|
|
66
104
|
let cartVersion = opts.resource.version;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Cart } from '@commercetools/platform-sdk';
|
|
1
|
+
import { Address, Cart, ShippingInfo } from '@commercetools/platform-sdk';
|
|
2
|
+
import { Logger } from '../../logger';
|
|
2
3
|
import { AddPayment, CommercetoolsAPI } from './api.type';
|
|
3
4
|
import { PaymentAmount } from './payment.type';
|
|
4
|
-
import { Logger } from '../../logger';
|
|
5
5
|
export type GetCart = {
|
|
6
6
|
id: string;
|
|
7
7
|
version?: number;
|
|
@@ -9,6 +9,23 @@ export type GetCart = {
|
|
|
9
9
|
export type GetPaymentAmount = {
|
|
10
10
|
cart: Cart;
|
|
11
11
|
};
|
|
12
|
+
export type GetOneShippingAddress = {
|
|
13
|
+
cart: Pick<Cart, 'shippingAddress' | 'shipping' | 'shippingMode'>;
|
|
14
|
+
};
|
|
15
|
+
export type GetNormalizedShipping = {
|
|
16
|
+
cart: Pick<Cart, 'shippingInfo' | 'shipping' | 'shippingMode' | 'shippingAddress'>;
|
|
17
|
+
};
|
|
18
|
+
export type NormalizedShipping = {
|
|
19
|
+
shippingAddress: Address;
|
|
20
|
+
shippingInfo: ShippingInfo;
|
|
21
|
+
};
|
|
22
|
+
export type ShippingAmounts = {
|
|
23
|
+
priceCentAmount: number;
|
|
24
|
+
taxRateAmount: number;
|
|
25
|
+
totalNetCentAmount: number;
|
|
26
|
+
totalGrossCentAmount: number;
|
|
27
|
+
totalTaxCentAmount: number;
|
|
28
|
+
};
|
|
12
29
|
export type CartServiceOptions = {
|
|
13
30
|
ctAPI: CommercetoolsAPI;
|
|
14
31
|
logger: Logger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Payment SDK for commercetools payment connectors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@commercetools-backend/loggers": "22.
|
|
19
|
-
"@commercetools/platform-sdk": "7.
|
|
18
|
+
"@commercetools-backend/loggers": "22.37.0",
|
|
19
|
+
"@commercetools/platform-sdk": "7.23.0",
|
|
20
20
|
"@commercetools/sdk-client-v2": "2.5.0",
|
|
21
21
|
"jsonwebtoken": "9.0.2",
|
|
22
22
|
"jwks-rsa": "3.1.0",
|