@commercetools/connect-payments-sdk 0.16.1 → 0.17.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
|
@@ -12,6 +12,7 @@ export declare class DefaultCartService implements CartService {
|
|
|
12
12
|
constructor(opts: CartServiceOptions);
|
|
13
13
|
getCartByPaymentId(opts: GetCartByPaymentIdRequest): Promise<Cart>;
|
|
14
14
|
getCart(opts: GetCart): Promise<Cart>;
|
|
15
|
+
getPlannedPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
|
|
15
16
|
getPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
|
|
16
17
|
/**
|
|
17
18
|
* Get only one shipping address from the cart. If the cart has multiple shipping addresses, it returns the first one.
|
|
@@ -32,7 +32,7 @@ class DefaultCartService {
|
|
|
32
32
|
async getCart(opts) {
|
|
33
33
|
return await this.ctAPI.cart.getCartById(opts.id);
|
|
34
34
|
}
|
|
35
|
-
async
|
|
35
|
+
async getPlannedPaymentAmount(opts) {
|
|
36
36
|
const giftCardPlannedAmount = (0, __1.getGiftCardPlannedAmountFromContext)(this.contextProvider.getContextData());
|
|
37
37
|
const paidAmount = await this.calculateTotalPaidAmount(opts.cart);
|
|
38
38
|
let cartAmount;
|
|
@@ -71,6 +71,42 @@ class DefaultCartService {
|
|
|
71
71
|
fractionDigits: cartAmount.fractionDigits,
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
async getPaymentAmount(opts) {
|
|
75
|
+
const paidAmount = await this.calculateTotalPaidAmount(opts.cart);
|
|
76
|
+
let cartAmount;
|
|
77
|
+
if (opts.cart.taxedPrice) {
|
|
78
|
+
cartAmount = {
|
|
79
|
+
currencyCode: opts.cart.taxedPrice.totalGross.currencyCode,
|
|
80
|
+
centAmount: opts.cart.taxedPrice.totalGross.centAmount,
|
|
81
|
+
fractionDigits: opts.cart.taxedPrice.totalGross.fractionDigits,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
cartAmount = {
|
|
86
|
+
currencyCode: opts.cart.totalPrice.currencyCode,
|
|
87
|
+
centAmount: opts.cart.totalPrice.centAmount,
|
|
88
|
+
fractionDigits: opts.cart.totalPrice.fractionDigits,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (paidAmount >= cartAmount.centAmount) {
|
|
92
|
+
throw new __1.ErrorInvalidOperation('The cart has already been paid in full', {
|
|
93
|
+
fields: {
|
|
94
|
+
resource: opts.cart.id,
|
|
95
|
+
paidAmount,
|
|
96
|
+
cartAmount,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const currentAmountToPay = cartAmount.centAmount - paidAmount;
|
|
101
|
+
this.logger.info({
|
|
102
|
+
currentAmountToPay,
|
|
103
|
+
}, 'current amount to pay');
|
|
104
|
+
return {
|
|
105
|
+
currencyCode: cartAmount.currencyCode,
|
|
106
|
+
centAmount: currentAmountToPay,
|
|
107
|
+
fractionDigits: cartAmount.fractionDigits,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
74
110
|
/**
|
|
75
111
|
* Get only one shipping address from the cart. If the cart has multiple shipping addresses, it returns the first one.
|
|
76
112
|
* @param cart
|
|
@@ -41,6 +41,18 @@ export type GetCartByPaymentIdRequest = {
|
|
|
41
41
|
export interface CartService {
|
|
42
42
|
getCartByPaymentId(opts: GetCartByPaymentIdRequest): Promise<Cart>;
|
|
43
43
|
getCart(opts: GetCart): Promise<Cart>;
|
|
44
|
+
/**
|
|
45
|
+
* Get payment amount for a cart. This method is used to calculate the payment amount for a cart.
|
|
46
|
+
* It takes into account existing successful payments.
|
|
47
|
+
* @param opts
|
|
48
|
+
*/
|
|
44
49
|
getPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
|
|
50
|
+
/**
|
|
51
|
+
* Get payment amount for a cart. This method is used to calculate the payment amount for a cart.
|
|
52
|
+
* It takes into account existing successful payments and giftcards connectors.
|
|
53
|
+
* This method is specifically used for calculating the payment amount for a cart when a giftcard is applied and the payment session is created upfront.
|
|
54
|
+
* @param opts
|
|
55
|
+
*/
|
|
56
|
+
getPlannedPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
|
|
45
57
|
addPayment(opts: AddPayment): Promise<Cart>;
|
|
46
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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.39.0",
|
|
19
19
|
"@commercetools/platform-sdk": "8.1.0",
|
|
20
20
|
"@commercetools/sdk-client-v2": "2.5.0",
|
|
21
21
|
"jsonwebtoken": "9.0.2",
|