@commercetools/connect-payments-sdk 0.14.0 → 0.15.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 +6 -0
- package/dist/api/context/request-context.helper.d.ts +9 -0
- package/dist/api/context/request-context.helper.js +59 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/commercetools/services/ct-cart.service.d.ts +1 -0
- package/dist/commercetools/services/ct-cart.service.js +14 -7
- package/dist/commercetools/services/ct-session.service.d.ts +2 -0
- package/dist/commercetools/services/ct-session.service.js +3 -0
- package/dist/commercetools/types/cart.type.d.ts +2 -0
- package/dist/commercetools/types/session.type.d.ts +2 -0
- package/dist/index.js +3 -3
- package/dist/security/authn/session-header-authn-manager.js +1 -0
- package/dist/security/authn/types/authn.type.d.ts +2 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Money, RequestContextData } from '../..';
|
|
2
|
+
export declare function getGiftCardPlannedAmountFromContext(context: RequestContextData): Money | undefined;
|
|
3
|
+
export declare function getCtSessionIdFromContext(context: RequestContextData): string | undefined;
|
|
4
|
+
export declare function getCartIdFromContext(context: RequestContextData): string | undefined;
|
|
5
|
+
export declare function getAllowedPaymentMethodsFromContext(context: RequestContextData): string[] | undefined;
|
|
6
|
+
export declare function getPaymentInterfaceFromContext(context: RequestContextData): string | undefined;
|
|
7
|
+
export declare function getProcessorUrlFromContext(context: RequestContextData): string | undefined;
|
|
8
|
+
export declare function getMerchantReturnUrlFromContext(context: RequestContextData): string | undefined;
|
|
9
|
+
export declare function getFutureOrderNumberFromContext(context: RequestContextData): string | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGiftCardPlannedAmountFromContext = getGiftCardPlannedAmountFromContext;
|
|
4
|
+
exports.getCtSessionIdFromContext = getCtSessionIdFromContext;
|
|
5
|
+
exports.getCartIdFromContext = getCartIdFromContext;
|
|
6
|
+
exports.getAllowedPaymentMethodsFromContext = getAllowedPaymentMethodsFromContext;
|
|
7
|
+
exports.getPaymentInterfaceFromContext = getPaymentInterfaceFromContext;
|
|
8
|
+
exports.getProcessorUrlFromContext = getProcessorUrlFromContext;
|
|
9
|
+
exports.getMerchantReturnUrlFromContext = getMerchantReturnUrlFromContext;
|
|
10
|
+
exports.getFutureOrderNumberFromContext = getFutureOrderNumberFromContext;
|
|
11
|
+
const __1 = require("../..");
|
|
12
|
+
function getGiftCardPlannedAmountFromContext(context) {
|
|
13
|
+
const authentication = context.authentication;
|
|
14
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
15
|
+
return authentication?.getPrincipal().giftCardPlannedAmount;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function getCtSessionIdFromContext(context) {
|
|
19
|
+
const authentication = context.authentication;
|
|
20
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
21
|
+
return authentication?.getCredentials();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function getCartIdFromContext(context) {
|
|
25
|
+
const authentication = context.authentication;
|
|
26
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
27
|
+
return authentication?.getPrincipal().cartId;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function getAllowedPaymentMethodsFromContext(context) {
|
|
31
|
+
const authentication = context.authentication;
|
|
32
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
33
|
+
return authentication?.getPrincipal().allowedPaymentMethods;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function getPaymentInterfaceFromContext(context) {
|
|
37
|
+
const authentication = context.authentication;
|
|
38
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
39
|
+
return authentication?.getPrincipal().paymentInterface;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function getProcessorUrlFromContext(context) {
|
|
43
|
+
const authentication = context.authentication;
|
|
44
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
45
|
+
return authentication?.getPrincipal().processorUrl;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function getMerchantReturnUrlFromContext(context) {
|
|
49
|
+
const authentication = context.authentication;
|
|
50
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
51
|
+
return authentication?.getPrincipal().merchantReturnUrl;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function getFutureOrderNumberFromContext(context) {
|
|
55
|
+
const authentication = context.authentication;
|
|
56
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
57
|
+
return authentication?.getPrincipal().futureOrderNumber;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./context/request-context.provider"), exports);
|
|
18
|
+
__exportStar(require("./context/request-context.helper"), exports);
|
|
18
19
|
__exportStar(require("./context/types/request-context.type"), exports);
|
|
19
20
|
__exportStar(require("./handlers/config.handler"), exports);
|
|
20
21
|
__exportStar(require("./handlers/status.handler"), exports);
|
|
@@ -8,6 +8,7 @@ import { PaymentAmount } from '../types/payment.type';
|
|
|
8
8
|
export declare class DefaultCartService implements CartService {
|
|
9
9
|
private ctAPI;
|
|
10
10
|
private logger;
|
|
11
|
+
private contextProvider;
|
|
11
12
|
constructor(opts: CartServiceOptions);
|
|
12
13
|
getCartByPaymentId(opts: GetCartByPaymentIdRequest): Promise<Cart>;
|
|
13
14
|
getCart(opts: GetCart): Promise<Cart>;
|
|
@@ -9,9 +9,11 @@ const ct_api_error_1 = require("../errors/ct-api.error");
|
|
|
9
9
|
class DefaultCartService {
|
|
10
10
|
ctAPI;
|
|
11
11
|
logger;
|
|
12
|
+
contextProvider;
|
|
12
13
|
constructor(opts) {
|
|
13
14
|
this.ctAPI = opts.ctAPI;
|
|
14
15
|
this.logger = opts.logger;
|
|
16
|
+
this.contextProvider = opts.contextProvider;
|
|
15
17
|
}
|
|
16
18
|
async getCartByPaymentId(opts) {
|
|
17
19
|
const queryPredicate = `paymentInfo(payments(id = "${opts.paymentId}"))`;
|
|
@@ -31,6 +33,7 @@ class DefaultCartService {
|
|
|
31
33
|
return await this.ctAPI.cart.getCartById(opts.id);
|
|
32
34
|
}
|
|
33
35
|
async getPaymentAmount(opts) {
|
|
36
|
+
const giftCardPlannedAmount = (0, __1.getGiftCardPlannedAmountFromContext)(this.contextProvider.getContextData());
|
|
34
37
|
const paidAmount = await this.calculateTotalPaidAmount(opts.cart);
|
|
35
38
|
let cartAmount;
|
|
36
39
|
if (opts.cart.taxedPrice) {
|
|
@@ -56,13 +59,17 @@ class DefaultCartService {
|
|
|
56
59
|
},
|
|
57
60
|
});
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const currentAmountToPay = giftCardPlannedAmount && giftCardPlannedAmount.currencyCode === cartAmount.currencyCode
|
|
63
|
+
? cartAmount.centAmount - giftCardPlannedAmount.centAmount
|
|
64
|
+
: cartAmount.centAmount;
|
|
65
|
+
this.logger.info({
|
|
66
|
+
currentAmountToPay,
|
|
67
|
+
}, 'current amount to pay after gift card amount deduction');
|
|
68
|
+
return {
|
|
69
|
+
currencyCode: cartAmount.currencyCode,
|
|
70
|
+
centAmount: currentAmountToPay - paidAmount,
|
|
71
|
+
fractionDigits: cartAmount.fractionDigits,
|
|
72
|
+
};
|
|
66
73
|
}
|
|
67
74
|
/**
|
|
68
75
|
* Get only one shipping address from the cart. If the cart has multiple shipping addresses, it returns the first one.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Money } from '@commercetools/platform-sdk';
|
|
1
2
|
import { Logger } from '../..';
|
|
2
3
|
import { AuthorizationService, CommercetoolsToken } from '../types/authorization.type';
|
|
3
4
|
import { Session, SessionService } from '../types/session.type';
|
|
@@ -20,5 +21,6 @@ export declare class DefaultSessionService implements SessionService {
|
|
|
20
21
|
getPaymentInterfaceFromSession(session: Session): string | undefined;
|
|
21
22
|
getMerchantReturnUrlFromSession(session: Session): string | undefined;
|
|
22
23
|
getFutureOrderNumberFromSession(session: Session): string | undefined;
|
|
24
|
+
getGiftCardPlannedAmountFromSession(session: Session): Money | undefined;
|
|
23
25
|
private getSession;
|
|
24
26
|
}
|
|
@@ -75,6 +75,9 @@ class DefaultSessionService {
|
|
|
75
75
|
getFutureOrderNumberFromSession(session) {
|
|
76
76
|
return session.metadata?.futureOrderNumber;
|
|
77
77
|
}
|
|
78
|
+
getGiftCardPlannedAmountFromSession(session) {
|
|
79
|
+
return session.metadata?.giftCardPlannedAmount;
|
|
80
|
+
}
|
|
78
81
|
async getSession(sessionId) {
|
|
79
82
|
return await fetch(`${this.sessionUrl}/${this.projectKey}/sessions/${sessionId}`, {
|
|
80
83
|
method: 'GET',
|
|
@@ -2,6 +2,7 @@ import { Address, Cart, ShippingInfo } from '@commercetools/platform-sdk';
|
|
|
2
2
|
import { Logger } from '../../logger';
|
|
3
3
|
import { AddPayment, CommercetoolsAPI } from './api.type';
|
|
4
4
|
import { PaymentAmount } from './payment.type';
|
|
5
|
+
import { ContextProvider, RequestContextData } from '../../api';
|
|
5
6
|
export type GetCart = {
|
|
6
7
|
id: string;
|
|
7
8
|
version?: number;
|
|
@@ -29,6 +30,7 @@ export type ShippingAmounts = {
|
|
|
29
30
|
export type CartServiceOptions = {
|
|
30
31
|
ctAPI: CommercetoolsAPI;
|
|
31
32
|
logger: Logger;
|
|
33
|
+
contextProvider: ContextProvider<RequestContextData>;
|
|
32
34
|
};
|
|
33
35
|
export type GetCartByPaymentIdRequest = {
|
|
34
36
|
paymentId: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Money } from '@commercetools/platform-sdk';
|
|
1
2
|
export type Session = {
|
|
2
3
|
id: string;
|
|
3
4
|
version: number;
|
|
@@ -29,4 +30,5 @@ export interface SessionService {
|
|
|
29
30
|
getPaymentInterfaceFromSession(session: Session): string | undefined;
|
|
30
31
|
getMerchantReturnUrlFromSession(session: Session): string | undefined;
|
|
31
32
|
getFutureOrderNumberFromSession(session: Session): string | undefined;
|
|
33
|
+
getGiftCardPlannedAmountFromSession(session: Session): Money | undefined;
|
|
32
34
|
}
|
package/dist/index.js
CHANGED
|
@@ -48,9 +48,6 @@ const setupPaymentSDK = (opts) => {
|
|
|
48
48
|
contextProvider,
|
|
49
49
|
logger,
|
|
50
50
|
});
|
|
51
|
-
const ctCartService = new ct_cart_service_1.DefaultCartService({ ctAPI, logger });
|
|
52
|
-
const ctOrderService = new ct_order_service_1.DefaultOrderService({ ctAPI, logger });
|
|
53
|
-
const ctPaymentService = new ct_payment_service_1.DefaultPaymentService({ ctAPI, logger });
|
|
54
51
|
const ctAuthorizationService = new ct_authorization_service_1.DefaultAuthorizationService({
|
|
55
52
|
authUrl: opts.authUrl,
|
|
56
53
|
clientId: opts.clientId,
|
|
@@ -64,6 +61,9 @@ const setupPaymentSDK = (opts) => {
|
|
|
64
61
|
projectKey: opts.projectKey,
|
|
65
62
|
logger,
|
|
66
63
|
});
|
|
64
|
+
const ctCartService = new ct_cart_service_1.DefaultCartService({ ctAPI, logger, contextProvider });
|
|
65
|
+
const ctOrderService = new ct_order_service_1.DefaultOrderService({ ctAPI, logger });
|
|
66
|
+
const ctPaymentService = new ct_payment_service_1.DefaultPaymentService({ ctAPI, logger });
|
|
67
67
|
const oauth2Service = new security_1.DefaultOauth2Service({ logger });
|
|
68
68
|
const jwtService = new security_1.DefaultJWTService({
|
|
69
69
|
jwksUrl: opts.jwksUrl,
|
|
@@ -21,6 +21,7 @@ class SessionHeaderAuthenticationManager {
|
|
|
21
21
|
paymentInterface: this.sessionService.getPaymentInterfaceFromSession(session),
|
|
22
22
|
merchantReturnUrl: this.sessionService.getMerchantReturnUrlFromSession(session),
|
|
23
23
|
futureOrderNumber: this.sessionService.getFutureOrderNumberFromSession(session),
|
|
24
|
+
giftCardPlannedAmount: this.sessionService.getGiftCardPlannedAmountFromSession(session),
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
catch (e) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Money } from '@commercetools/platform-sdk';
|
|
1
2
|
export interface AuthenticationManager {
|
|
2
3
|
authenticate(authentication: Authentication): Promise<Authentication> | Authentication;
|
|
3
4
|
}
|
|
@@ -22,6 +23,7 @@ export type SessionPrincipal = {
|
|
|
22
23
|
paymentInterface?: string;
|
|
23
24
|
merchantReturnUrl?: string;
|
|
24
25
|
futureOrderNumber?: string;
|
|
26
|
+
giftCardPlannedAmount?: Money;
|
|
25
27
|
};
|
|
26
28
|
export type Oauth2Principal = {
|
|
27
29
|
clientId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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": "
|
|
18
|
+
"@commercetools-backend/loggers": "22.38.1",
|
|
19
|
+
"@commercetools/platform-sdk": "8.0.0",
|
|
20
20
|
"@commercetools/sdk-client-v2": "2.5.0",
|
|
21
21
|
"jsonwebtoken": "9.0.2",
|
|
22
22
|
"jwks-rsa": "3.1.0",
|