@commercetools/connect-payments-sdk 0.24.0 → 0.25.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/api/context/request-context.helper.d.ts +6 -0
- package/dist/api/context/request-context.helper.js +12 -0
- package/dist/commercetools/api/custom-type-api.d.ts +10 -0
- package/dist/commercetools/api/custom-type-api.js +45 -0
- package/dist/commercetools/api/payment-method-api.js +11 -20
- package/dist/commercetools/api/root-api.d.ts +2 -1
- package/dist/commercetools/api/root-api.js +4 -0
- package/dist/commercetools/index.d.ts +2 -1
- package/dist/commercetools/services/ct-custom-type.service.d.ts +34 -0
- package/dist/commercetools/services/ct-custom-type.service.js +91 -0
- package/dist/commercetools/services/ct-payment-method.service.js +1 -0
- package/dist/commercetools/services/ct-payment.service.d.ts +15 -0
- package/dist/commercetools/services/ct-payment.service.js +90 -7
- package/dist/commercetools/types/api.type.d.ts +8 -1
- package/dist/commercetools/types/custom-type.type.d.ts +20 -0
- package/dist/commercetools/types/custom-type.type.js +2 -0
- package/dist/commercetools/types/payment-method.type.d.ts +2 -1
- package/dist/commercetools/types/payment.type.d.ts +3 -1
- package/dist/custom-types/index.d.ts +4 -0
- package/dist/custom-types/index.js +20 -0
- package/dist/custom-types/payment-interface-interactions.d.ts +11 -0
- package/dist/custom-types/payment-interface-interactions.js +78 -0
- package/dist/custom-types/payment-methods/card.d.ts +12 -0
- package/dist/custom-types/payment-methods/card.js +75 -0
- package/dist/custom-types/payment-methods/sepa.d.ts +8 -0
- package/dist/custom-types/payment-methods/sepa.js +35 -0
- package/dist/custom-types/payment-methods/shared.d.ts +2 -0
- package/dist/custom-types/payment-methods/shared.js +13 -0
- package/dist/errorx/errorx.d.ts +2 -0
- package/dist/errorx/errorx.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/security/authn/types/authn.type.d.ts +4 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @commercetools/connect-payments-sdk
|
|
2
2
|
|
|
3
|
+
## 0.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 511fbef: - Add new api and service for interacting with CT custom-types APIs.
|
|
8
|
+
- Add predefined Checkout custom-types.
|
|
9
|
+
- d28fe6d: support use of transaction interface id and checkoutTransactionItemsIds
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5d0e4c2: chore(sdk): for CT API sdk mask sensitive data in error object
|
|
14
|
+
|
|
3
15
|
## 0.24.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -3,7 +3,13 @@ export declare function getGiftCardPlannedAmountFromContext(context: RequestCont
|
|
|
3
3
|
export declare function getCtSessionIdFromContext(context: RequestContextData): string | undefined;
|
|
4
4
|
export declare function getCartIdFromContext(context: RequestContextData): string | undefined;
|
|
5
5
|
export declare function getAllowedPaymentMethodsFromContext(context: RequestContextData): string[] | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use getCheckoutTransactionItemIdFromContext instead
|
|
8
|
+
* @param context
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
6
11
|
export declare function getPaymentInterfaceFromContext(context: RequestContextData): string | undefined;
|
|
12
|
+
export declare function getCheckoutTransactionItemIdFromContext(context: RequestContextData): string | undefined;
|
|
7
13
|
export declare function getProcessorUrlFromContext(context: RequestContextData): string | undefined;
|
|
8
14
|
export declare function getMerchantReturnUrlFromContext(context: RequestContextData): string | undefined;
|
|
9
15
|
export declare function getFutureOrderNumberFromContext(context: RequestContextData): string | undefined;
|
|
@@ -5,6 +5,7 @@ exports.getCtSessionIdFromContext = getCtSessionIdFromContext;
|
|
|
5
5
|
exports.getCartIdFromContext = getCartIdFromContext;
|
|
6
6
|
exports.getAllowedPaymentMethodsFromContext = getAllowedPaymentMethodsFromContext;
|
|
7
7
|
exports.getPaymentInterfaceFromContext = getPaymentInterfaceFromContext;
|
|
8
|
+
exports.getCheckoutTransactionItemIdFromContext = getCheckoutTransactionItemIdFromContext;
|
|
8
9
|
exports.getProcessorUrlFromContext = getProcessorUrlFromContext;
|
|
9
10
|
exports.getMerchantReturnUrlFromContext = getMerchantReturnUrlFromContext;
|
|
10
11
|
exports.getFutureOrderNumberFromContext = getFutureOrderNumberFromContext;
|
|
@@ -33,12 +34,23 @@ function getAllowedPaymentMethodsFromContext(context) {
|
|
|
33
34
|
return authentication?.getPrincipal().allowedPaymentMethods;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated use getCheckoutTransactionItemIdFromContext instead
|
|
39
|
+
* @param context
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
36
42
|
function getPaymentInterfaceFromContext(context) {
|
|
37
43
|
const authentication = context.authentication;
|
|
38
44
|
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
39
45
|
return authentication?.getPrincipal().paymentInterface;
|
|
40
46
|
}
|
|
41
47
|
}
|
|
48
|
+
function getCheckoutTransactionItemIdFromContext(context) {
|
|
49
|
+
const authentication = context.authentication;
|
|
50
|
+
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
51
|
+
return authentication?.getPrincipal().checkoutTransactionItemId;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
42
54
|
function getProcessorUrlFromContext(context) {
|
|
43
55
|
const authentication = context.authentication;
|
|
44
56
|
if (authentication && authentication instanceof __1.SessionAuthentication) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Type, TypeDraft, TypeUpdate } from '@commercetools/platform-sdk';
|
|
2
|
+
import { APIOpts, CustomTypeAPI } from '../types/api.type';
|
|
3
|
+
import { CommercetoolsBaseAPI } from './base-api';
|
|
4
|
+
export declare class CommercetoolsCustomTypeAPI extends CommercetoolsBaseAPI implements CustomTypeAPI {
|
|
5
|
+
constructor(opts: APIOpts);
|
|
6
|
+
getByKey(key: string): Promise<Type>;
|
|
7
|
+
existsByKey(key: string): Promise<boolean>;
|
|
8
|
+
create(draft: TypeDraft): Promise<Type>;
|
|
9
|
+
update(key: string, update: TypeUpdate): Promise<Type>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommercetoolsCustomTypeAPI = void 0;
|
|
4
|
+
const base_api_1 = require("./base-api");
|
|
5
|
+
class CommercetoolsCustomTypeAPI extends base_api_1.CommercetoolsBaseAPI {
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
super(opts);
|
|
8
|
+
Object.setPrototypeOf(this, CommercetoolsCustomTypeAPI.prototype);
|
|
9
|
+
}
|
|
10
|
+
async getByKey(key) {
|
|
11
|
+
return this.executeCall(this.client.types().withKey({ key }).get().execute());
|
|
12
|
+
}
|
|
13
|
+
async existsByKey(key) {
|
|
14
|
+
try {
|
|
15
|
+
await this.client.types().withKey({ key }).get().execute();
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error instanceof Object && 'statusCode' in error && error['statusCode'] === 404) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async create(draft) {
|
|
28
|
+
return this.executeCall(this.client
|
|
29
|
+
.types()
|
|
30
|
+
.post({
|
|
31
|
+
body: draft,
|
|
32
|
+
})
|
|
33
|
+
.execute());
|
|
34
|
+
}
|
|
35
|
+
async update(key, update) {
|
|
36
|
+
return this.executeCall(this.client
|
|
37
|
+
.types()
|
|
38
|
+
.withKey({ key })
|
|
39
|
+
.post({
|
|
40
|
+
body: update,
|
|
41
|
+
})
|
|
42
|
+
.execute());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.CommercetoolsCustomTypeAPI = CommercetoolsCustomTypeAPI;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommercetoolsPaymentMethodAPI = void 0;
|
|
4
4
|
const base_api_1 = require("./base-api");
|
|
5
|
-
const ct_api_error_1 = require("../errors/ct-api.error");
|
|
6
5
|
class CommercetoolsPaymentMethodAPI extends base_api_1.CommercetoolsBaseAPI {
|
|
7
6
|
constructor(opts) {
|
|
8
7
|
super(opts);
|
|
@@ -12,26 +11,18 @@ class CommercetoolsPaymentMethodAPI extends base_api_1.CommercetoolsBaseAPI {
|
|
|
12
11
|
return this.executeCall(this.client.paymentMethods().withId({ ID: opts.id }).get().execute());
|
|
13
12
|
}
|
|
14
13
|
async checkIfExistsByPredicate(opts) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
// The HEAD call returns a 404 if the paymentMethod does not exist
|
|
28
|
-
if (error instanceof ct_api_error_1.CommercetoolsAPIError && error.httpErrorStatus === 404) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
14
|
+
const result = await this.executeCall(this.client
|
|
15
|
+
.paymentMethods()
|
|
16
|
+
.get({
|
|
17
|
+
queryArgs: {
|
|
18
|
+
where: opts.queryString,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
.execute());
|
|
22
|
+
if (result.total === 0) {
|
|
23
|
+
return false;
|
|
34
24
|
}
|
|
25
|
+
return true;
|
|
35
26
|
}
|
|
36
27
|
find(opts) {
|
|
37
28
|
return this.executeCall(this.client
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContextProvider, RequestContextData } from '../../api';
|
|
2
|
-
import { CartAPI, CommercetoolsAPI, CommercetoolsClient, OrderAPI, PaymentAPI, PaymentMethodAPI } from '../types/api.type';
|
|
2
|
+
import { CartAPI, CommercetoolsAPI, CommercetoolsClient, CustomTypeAPI, OrderAPI, PaymentAPI, PaymentMethodAPI } from '../types/api.type';
|
|
3
3
|
import { Logger } from '../..';
|
|
4
4
|
export declare class DefaultCommercetoolsAPI implements CommercetoolsAPI {
|
|
5
5
|
client: CommercetoolsClient;
|
|
@@ -7,6 +7,7 @@ export declare class DefaultCommercetoolsAPI implements CommercetoolsAPI {
|
|
|
7
7
|
payment: PaymentAPI;
|
|
8
8
|
order: OrderAPI;
|
|
9
9
|
paymentMethod: PaymentMethodAPI;
|
|
10
|
+
customType: CustomTypeAPI;
|
|
10
11
|
private logger;
|
|
11
12
|
constructor(opts: {
|
|
12
13
|
clientId: string;
|
|
@@ -7,6 +7,7 @@ const cart_api_1 = require("./cart-api");
|
|
|
7
7
|
const payment_api_1 = require("./payment-api");
|
|
8
8
|
const payment_method_api_1 = require("./payment-method-api");
|
|
9
9
|
const order_api_1 = require("./order-api");
|
|
10
|
+
const custom_type_api_1 = require("./custom-type-api");
|
|
10
11
|
const crypto_1 = require("crypto");
|
|
11
12
|
class DefaultCommercetoolsAPI {
|
|
12
13
|
client;
|
|
@@ -14,6 +15,7 @@ class DefaultCommercetoolsAPI {
|
|
|
14
15
|
payment;
|
|
15
16
|
order;
|
|
16
17
|
paymentMethod;
|
|
18
|
+
customType;
|
|
17
19
|
logger;
|
|
18
20
|
constructor(opts) {
|
|
19
21
|
this.client = createClient(opts);
|
|
@@ -21,6 +23,7 @@ class DefaultCommercetoolsAPI {
|
|
|
21
23
|
this.payment = new payment_api_1.CommercetoolsPaymentAPI({ client: this.client });
|
|
22
24
|
this.order = new order_api_1.CommercetoolsOrderAPI({ client: this.client });
|
|
23
25
|
this.paymentMethod = new payment_method_api_1.CommercetoolsPaymentMethodAPI({ client: this.client });
|
|
26
|
+
this.customType = new custom_type_api_1.CommercetoolsCustomTypeAPI({ client: this.client });
|
|
24
27
|
this.logger = opts.logger;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
@@ -40,6 +43,7 @@ const createClient = (opts) => {
|
|
|
40
43
|
//Enables SDK retries when CoCo returns a 503 error. It retries up to 10 times with an 200ms backoff.
|
|
41
44
|
enableRetry: true,
|
|
42
45
|
...(opts.httpClient ? { httpClient: opts.httpClient } : {}),
|
|
46
|
+
maskSensitiveHeaderData: true,
|
|
43
47
|
};
|
|
44
48
|
const correlationIdMiddlewareOptions = {
|
|
45
49
|
generate: () => {
|
|
@@ -4,8 +4,9 @@ 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 { PaymentMethodService as CommercetoolsPaymentMethodService } from './types/payment-method.type';
|
|
7
|
+
export { CustomTypeService as CommercetoolsCustomTypeService } from './types/custom-type.type';
|
|
7
8
|
export * as CommercetoolsPaymentMethodTypes from './types/payment-method.type';
|
|
8
9
|
export { CommercetoolsClient } from './types/api.type';
|
|
9
|
-
export { CustomFieldsDraft, Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, PaymentMethod, PaymentMethodToken, PaymentMethodStatus, } from '@commercetools/platform-sdk';
|
|
10
|
+
export { CustomFieldsDraft, Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, PaymentMethodInfoDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, PaymentMethod, PaymentMethodPagedQueryResponse, PaymentMethodToken, PaymentMethodStatus, Type, TypeDraft, TypePagedQueryResponse, LocalizedString, } from '@commercetools/platform-sdk';
|
|
10
11
|
export * as CurrencyConverters from './helpers/currency.converter';
|
|
11
12
|
export * as TaxRateConverter from './helpers/taxrate.converter';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Type, TypeDraft } from '@commercetools/platform-sdk';
|
|
2
|
+
import { PaymentServiceOptions } from '../types/payment.type';
|
|
3
|
+
import { CustomTypeService, GetByKeyCustomType, UpdateCustomType } from '../types/custom-type.type';
|
|
4
|
+
/**
|
|
5
|
+
* This is the default implementation of the CustomTypeService interface.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DefaultCustomTypeService implements CustomTypeService {
|
|
8
|
+
private ctAPI;
|
|
9
|
+
private logger;
|
|
10
|
+
constructor(opts: PaymentServiceOptions);
|
|
11
|
+
getByKey(opts: GetByKeyCustomType): Promise<Type>;
|
|
12
|
+
existsByKey(opts: GetByKeyCustomType): Promise<boolean>;
|
|
13
|
+
create(draft: TypeDraft): Promise<Type>;
|
|
14
|
+
update(opts: UpdateCustomType): Promise<Type>;
|
|
15
|
+
createOrUpdatePredefinedPaymentMethodTypes(): Promise<Type[]>;
|
|
16
|
+
createOrUpdatePredefinedInterfaceInteractionType(): Promise<Type>;
|
|
17
|
+
/**
|
|
18
|
+
* Based on the given TypeDraft this will either create or update the custom type in CT based on the provided "key".
|
|
19
|
+
*
|
|
20
|
+
* - if a custom-type by key does not exist in CT then it will create it using the given draft
|
|
21
|
+
* - if a custom-type by key does exist in CT it will gather a set of update actions to try and sync up the definitions
|
|
22
|
+
*
|
|
23
|
+
* The update currently supports:
|
|
24
|
+
* - adding missing field definitions. If the given draft contains field definitions that the custom-type in CT does not have, it will for each missing field definition perform an "addFieldDefinition" update action. Purely by checking the "name" of the field definitions.
|
|
25
|
+
*
|
|
26
|
+
* Differences between the TypeDraft and existing custom-type in CT such as are not supported yet but could be added in the future.
|
|
27
|
+
* - remove field definition if they no longer exist in the TypeDraft
|
|
28
|
+
* - update/sync the possible enum values for a field definition
|
|
29
|
+
* - update/sync the actual field definition properties. Such as "localized label", "type" or "required" value
|
|
30
|
+
*/
|
|
31
|
+
createOrUpdate(customTypeDraft: TypeDraft): Promise<Type>;
|
|
32
|
+
private consolidateUpdateActions;
|
|
33
|
+
private getMissingFieldDefinitionsUpdateActions;
|
|
34
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultCustomTypeService = void 0;
|
|
4
|
+
const custom_types_1 = require("../../custom-types");
|
|
5
|
+
/**
|
|
6
|
+
* This is the default implementation of the CustomTypeService interface.
|
|
7
|
+
*/
|
|
8
|
+
class DefaultCustomTypeService {
|
|
9
|
+
ctAPI;
|
|
10
|
+
logger;
|
|
11
|
+
constructor(opts) {
|
|
12
|
+
this.ctAPI = opts.ctAPI;
|
|
13
|
+
this.logger = opts.logger;
|
|
14
|
+
}
|
|
15
|
+
async getByKey(opts) {
|
|
16
|
+
return await this.ctAPI.customType.getByKey(opts.key);
|
|
17
|
+
}
|
|
18
|
+
async existsByKey(opts) {
|
|
19
|
+
return await this.ctAPI.customType.existsByKey(opts.key);
|
|
20
|
+
}
|
|
21
|
+
async create(draft) {
|
|
22
|
+
return await this.ctAPI.customType.create(draft);
|
|
23
|
+
}
|
|
24
|
+
async update(opts) {
|
|
25
|
+
return await this.ctAPI.customType.update(opts.key, opts.updateActions);
|
|
26
|
+
}
|
|
27
|
+
async createOrUpdatePredefinedPaymentMethodTypes() {
|
|
28
|
+
const cardDetailsType = await this.createOrUpdate(custom_types_1.CardDetailsTypeDraft);
|
|
29
|
+
const sepaDetailsType = await this.createOrUpdate(custom_types_1.SepaDetailsTypeDraft);
|
|
30
|
+
return [cardDetailsType, sepaDetailsType];
|
|
31
|
+
}
|
|
32
|
+
async createOrUpdatePredefinedInterfaceInteractionType() {
|
|
33
|
+
return await this.createOrUpdate(custom_types_1.PaymentInterfaceInteractionTypeDraft);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Based on the given TypeDraft this will either create or update the custom type in CT based on the provided "key".
|
|
37
|
+
*
|
|
38
|
+
* - if a custom-type by key does not exist in CT then it will create it using the given draft
|
|
39
|
+
* - if a custom-type by key does exist in CT it will gather a set of update actions to try and sync up the definitions
|
|
40
|
+
*
|
|
41
|
+
* The update currently supports:
|
|
42
|
+
* - adding missing field definitions. If the given draft contains field definitions that the custom-type in CT does not have, it will for each missing field definition perform an "addFieldDefinition" update action. Purely by checking the "name" of the field definitions.
|
|
43
|
+
*
|
|
44
|
+
* Differences between the TypeDraft and existing custom-type in CT such as are not supported yet but could be added in the future.
|
|
45
|
+
* - remove field definition if they no longer exist in the TypeDraft
|
|
46
|
+
* - update/sync the possible enum values for a field definition
|
|
47
|
+
* - update/sync the actual field definition properties. Such as "localized label", "type" or "required" value
|
|
48
|
+
*/
|
|
49
|
+
async createOrUpdate(customTypeDraft) {
|
|
50
|
+
const exists = await this.existsByKey({ key: customTypeDraft.key });
|
|
51
|
+
if (!exists) {
|
|
52
|
+
this.logger.info({ key: customTypeDraft.key }, 'Custom type by key does not exist in CT, creating it');
|
|
53
|
+
return await this.create(customTypeDraft);
|
|
54
|
+
}
|
|
55
|
+
const customTypeFromCT = await this.getByKey({ key: customTypeDraft.key });
|
|
56
|
+
const updateActions = this.consolidateUpdateActions(customTypeDraft, customTypeFromCT);
|
|
57
|
+
if (updateActions.actions.length > 0) {
|
|
58
|
+
this.logger.info({ key: customTypeDraft.key, updateActions: { total: updateActions.actions.length } }, 'Updating existing custom-type by key');
|
|
59
|
+
return await this.update({ key: customTypeFromCT.key, updateActions: updateActions });
|
|
60
|
+
}
|
|
61
|
+
this.logger.info({ key: customTypeDraft.key }, 'Custom type exists but no update is required, doing nothing.');
|
|
62
|
+
return customTypeFromCT;
|
|
63
|
+
}
|
|
64
|
+
consolidateUpdateActions(customTypeDraft, existingType) {
|
|
65
|
+
const updateActions = [];
|
|
66
|
+
updateActions.push(...this.getMissingFieldDefinitionsUpdateActions(customTypeDraft, existingType));
|
|
67
|
+
return {
|
|
68
|
+
version: existingType.version,
|
|
69
|
+
actions: updateActions,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
getMissingFieldDefinitionsUpdateActions(customTypeDraft, existingType) {
|
|
73
|
+
const draftFieldDefinitions = customTypeDraft.fieldDefinitions || [];
|
|
74
|
+
const missingFieldDefinitions = draftFieldDefinitions.filter((fd) => !existingType.fieldDefinitions.some((existingFD) => fd.name === existingFD.name));
|
|
75
|
+
const addFieldDefinitionUpdateActions = missingFieldDefinitions.map((fd) => {
|
|
76
|
+
return {
|
|
77
|
+
action: 'addFieldDefinition',
|
|
78
|
+
fieldDefinition: fd,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
if (addFieldDefinitionUpdateActions.length > 0) {
|
|
82
|
+
this.logger.info({
|
|
83
|
+
key: customTypeDraft.key,
|
|
84
|
+
missingFieldsCount: addFieldDefinitionUpdateActions.length,
|
|
85
|
+
fieldNames: missingFieldDefinitions.map((fd) => fd.name),
|
|
86
|
+
}, 'Custom type in CT is missing field definition from the draft, adding them');
|
|
87
|
+
}
|
|
88
|
+
return addFieldDefinitionUpdateActions;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.DefaultCustomTypeService = DefaultCustomTypeService;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { Payment, PaymentDraft, PaymentUpdateAction, Transaction } from '@commercetools/platform-sdk';
|
|
2
2
|
import { FindPaymentsByInterfaceId, FindTransaction, GetPayment, PaymentService, PaymentServiceOptions, TransactionData, UpdatePayment } from '../types/payment.type';
|
|
3
|
+
declare module '@commercetools/platform-sdk' {
|
|
4
|
+
interface PaymentDraft {
|
|
5
|
+
checkoutTransactionItemId?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Payment {
|
|
8
|
+
checkoutTransactionItemId?: string;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
3
11
|
/**
|
|
4
12
|
* This is the default implementation of the PaymentService interface.
|
|
5
13
|
*/
|
|
@@ -14,10 +22,16 @@ export declare class DefaultPaymentService implements PaymentService {
|
|
|
14
22
|
private consolidateUpdateActions;
|
|
15
23
|
private populateSetInterfaceIdAction;
|
|
16
24
|
private populateChangeTransactionInteractionId;
|
|
25
|
+
private populateSetTransactionInterfaceId;
|
|
17
26
|
private populateAddTransactionAction;
|
|
18
27
|
private populateChangeTransactionState;
|
|
19
28
|
private populateSetPaymentMethod;
|
|
20
29
|
private populateSetMethodInfoToken;
|
|
30
|
+
private populateSetMethodInfoInterface;
|
|
31
|
+
private populateSetMethodInfoName;
|
|
32
|
+
private populateSetMethodInfoInterfaceAccount;
|
|
33
|
+
private populateSetMethodInfoCustomType;
|
|
34
|
+
private populateSetMethodInfoCustomField;
|
|
21
35
|
private populateSetCustomType;
|
|
22
36
|
private populateAddInterfaceInteractions;
|
|
23
37
|
findMatchingTransactions(payment: Payment, transaction: TransactionData): Transaction[];
|
|
@@ -27,5 +41,6 @@ export declare class DefaultPaymentService implements PaymentService {
|
|
|
27
41
|
private handleTransactionUpdates;
|
|
28
42
|
private shouldUpdateTransactionState;
|
|
29
43
|
private shouldUpdateInteractionId;
|
|
44
|
+
private shouldUpdateTransactionInterfaceId;
|
|
30
45
|
private throwMultipleMatchingTransactionsError;
|
|
31
46
|
}
|
|
@@ -64,12 +64,36 @@ class DefaultPaymentService {
|
|
|
64
64
|
if (!payment.interfaceId && updateInfo.pspReference) {
|
|
65
65
|
actions.push(this.populateSetInterfaceIdAction(updateInfo.pspReference));
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* old way
|
|
69
|
+
*/
|
|
67
70
|
if (!payment.paymentMethodInfo?.method && updateInfo.paymentMethod) {
|
|
68
71
|
actions.push(this.populateSetPaymentMethod(updateInfo.paymentMethod));
|
|
69
72
|
}
|
|
70
73
|
if (!payment.paymentMethodInfo?.token && updateInfo.token) {
|
|
71
74
|
actions.push(this.populateSetMethodInfoToken(updateInfo.token));
|
|
72
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* New way
|
|
78
|
+
*/
|
|
79
|
+
if (!payment.paymentMethodInfo?.method && updateInfo.paymentMethodInfo?.method) {
|
|
80
|
+
actions.push(this.populateSetPaymentMethod(updateInfo.paymentMethodInfo.method));
|
|
81
|
+
}
|
|
82
|
+
if (!payment.paymentMethodInfo?.token && updateInfo.paymentMethodInfo?.token?.value) {
|
|
83
|
+
actions.push(this.populateSetMethodInfoToken(updateInfo.paymentMethodInfo.token.value));
|
|
84
|
+
}
|
|
85
|
+
if (!payment.paymentMethodInfo?.name && updateInfo.paymentMethodInfo?.name) {
|
|
86
|
+
actions.push(this.populateSetMethodInfoName(updateInfo.paymentMethodInfo.name));
|
|
87
|
+
}
|
|
88
|
+
if (!payment.paymentMethodInfo?.paymentInterface && updateInfo.paymentMethodInfo?.paymentInterface) {
|
|
89
|
+
actions.push(this.populateSetMethodInfoInterface(updateInfo.paymentMethodInfo.paymentInterface));
|
|
90
|
+
}
|
|
91
|
+
if (!payment.paymentMethodInfo?.interfaceAccount && updateInfo.paymentMethodInfo?.interfaceAccount) {
|
|
92
|
+
actions.push(this.populateSetMethodInfoInterfaceAccount(updateInfo.paymentMethodInfo.interfaceAccount));
|
|
93
|
+
}
|
|
94
|
+
if (updateInfo.paymentMethodInfo?.custom) {
|
|
95
|
+
actions.push(this.populateSetMethodInfoCustomType(updateInfo.paymentMethodInfo.custom));
|
|
96
|
+
}
|
|
73
97
|
if (updateInfo.transaction) {
|
|
74
98
|
const transactionChanges = this.consolidateTransactionChanges(payment, updateInfo.transaction);
|
|
75
99
|
if (transactionChanges.length > 0) {
|
|
@@ -97,6 +121,13 @@ class DefaultPaymentService {
|
|
|
97
121
|
interactionId,
|
|
98
122
|
};
|
|
99
123
|
}
|
|
124
|
+
populateSetTransactionInterfaceId(txId, interfaceId) {
|
|
125
|
+
return {
|
|
126
|
+
action: 'setTransactionInterfaceId',
|
|
127
|
+
transactionId: txId,
|
|
128
|
+
interfaceId,
|
|
129
|
+
}; // TypeScript does not have this action in the SDK yet
|
|
130
|
+
}
|
|
100
131
|
populateAddTransactionAction(draft) {
|
|
101
132
|
return {
|
|
102
133
|
action: 'addTransaction',
|
|
@@ -127,6 +158,37 @@ class DefaultPaymentService {
|
|
|
127
158
|
},
|
|
128
159
|
};
|
|
129
160
|
}
|
|
161
|
+
populateSetMethodInfoInterface(paymentInterface) {
|
|
162
|
+
return {
|
|
163
|
+
action: 'setMethodInfoInterface',
|
|
164
|
+
interface: paymentInterface,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
populateSetMethodInfoName(name) {
|
|
168
|
+
return {
|
|
169
|
+
action: 'setMethodInfoName',
|
|
170
|
+
name,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
populateSetMethodInfoInterfaceAccount(interfaceAccount) {
|
|
174
|
+
return {
|
|
175
|
+
action: 'setMethodInfoInterfaceAccount',
|
|
176
|
+
interfaceAccount,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
populateSetMethodInfoCustomType(customType) {
|
|
180
|
+
return {
|
|
181
|
+
action: 'setMethodInfoCustomType',
|
|
182
|
+
...customType,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
populateSetMethodInfoCustomField(name, value) {
|
|
186
|
+
return {
|
|
187
|
+
action: 'setMethodInfoCustomField',
|
|
188
|
+
name,
|
|
189
|
+
value,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
130
192
|
populateSetCustomType(customFields) {
|
|
131
193
|
return {
|
|
132
194
|
action: 'setCustomType',
|
|
@@ -143,13 +205,28 @@ class DefaultPaymentService {
|
|
|
143
205
|
}
|
|
144
206
|
findMatchingTransactions(payment, transaction) {
|
|
145
207
|
return payment.transactions.filter((tx) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
208
|
+
// Must match transaction type
|
|
209
|
+
if (tx.type !== transaction.type) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
// New transaction must have at least one PSP identifier. InteractionId is for retro compatibility.
|
|
213
|
+
if (!transaction.interactionId && !transaction.interfaceId) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
// Match by interactionId
|
|
217
|
+
if (transaction.interactionId && tx.interactionId === transaction.interactionId) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
// Match by interfaceId
|
|
221
|
+
if (transaction.interfaceId && tx.interfaceId === transaction.interfaceId) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
// Match Initial transactions missing at least one ID by amount
|
|
225
|
+
// This allows reusing an Initial transaction when we get a PSP response with an ID
|
|
226
|
+
const isInitialMissingIds = tx.state === 'Initial' && (!tx.interactionId || !tx.interfaceId);
|
|
227
|
+
const hasMatchingAmount = tx.amount.centAmount === transaction.amount.centAmount &&
|
|
228
|
+
tx.amount.currencyCode === transaction.amount.currencyCode;
|
|
229
|
+
return isInitialMissingIds && hasMatchingAmount;
|
|
153
230
|
});
|
|
154
231
|
}
|
|
155
232
|
hasTransactionInState(opts) {
|
|
@@ -187,6 +264,9 @@ class DefaultPaymentService {
|
|
|
187
264
|
if (this.shouldUpdateInteractionId(existingTx, newTransaction)) {
|
|
188
265
|
actions.push(this.populateChangeTransactionInteractionId(existingTx.id, newTransaction.interactionId));
|
|
189
266
|
}
|
|
267
|
+
if (this.shouldUpdateTransactionInterfaceId(existingTx, newTransaction)) {
|
|
268
|
+
actions.push(this.populateSetTransactionInterfaceId(existingTx.id, newTransaction.interfaceId));
|
|
269
|
+
}
|
|
190
270
|
}
|
|
191
271
|
shouldUpdateTransactionState(existingTx, newTransaction) {
|
|
192
272
|
const { state: currentState } = existingTx;
|
|
@@ -203,6 +283,9 @@ class DefaultPaymentService {
|
|
|
203
283
|
shouldUpdateInteractionId(existingTx, newTransaction) {
|
|
204
284
|
return !existingTx.interactionId && !!newTransaction.interactionId;
|
|
205
285
|
}
|
|
286
|
+
shouldUpdateTransactionInterfaceId(existingTx, newTransaction) {
|
|
287
|
+
return !existingTx.interfaceId && !!newTransaction.interfaceId;
|
|
288
|
+
}
|
|
206
289
|
throwMultipleMatchingTransactionsError(payment, newTransaction, matchingTxs) {
|
|
207
290
|
this.logger.error({
|
|
208
291
|
paymentId: payment.id,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cart, CartPagedQueryResponse, OrderPagedQueryResponse, Payment, PaymentDraft, PaymentPagedQueryResponse, PaymentUpdateAction, PaymentMethod, PaymentMethodDraft, PaymentMethodPagedQueryResponse, PaymentMethodUpdateAction } from '@commercetools/platform-sdk';
|
|
1
|
+
import { Cart, CartPagedQueryResponse, OrderPagedQueryResponse, Payment, PaymentDraft, PaymentPagedQueryResponse, PaymentUpdateAction, PaymentMethod, PaymentMethodDraft, PaymentMethodPagedQueryResponse, PaymentMethodUpdateAction, Type, TypeDraft, TypeUpdate } from '@commercetools/platform-sdk';
|
|
2
2
|
import { ByProjectKeyRequestBuilder } from '@commercetools/platform-sdk/dist/declarations/src/generated/client/by-project-key-request-builder';
|
|
3
3
|
export type CommercetoolsClient = ByProjectKeyRequestBuilder;
|
|
4
4
|
export type CommercetoolsSessionClient = ByProjectKeyRequestBuilder;
|
|
@@ -66,9 +66,16 @@ export interface PaymentMethodAPI {
|
|
|
66
66
|
export interface OrderAPI {
|
|
67
67
|
find(queryPredicate: string): Promise<OrderPagedQueryResponse>;
|
|
68
68
|
}
|
|
69
|
+
export interface CustomTypeAPI {
|
|
70
|
+
getByKey(key: string): Promise<Type>;
|
|
71
|
+
existsByKey(key: string): Promise<boolean>;
|
|
72
|
+
create(draft: TypeDraft): Promise<Type>;
|
|
73
|
+
update(key: string, update: TypeUpdate): Promise<Type>;
|
|
74
|
+
}
|
|
69
75
|
export interface CommercetoolsAPI {
|
|
70
76
|
cart: CartAPI;
|
|
71
77
|
payment: PaymentAPI;
|
|
72
78
|
order: OrderAPI;
|
|
73
79
|
paymentMethod: PaymentMethodAPI;
|
|
80
|
+
customType: CustomTypeAPI;
|
|
74
81
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Type, TypeDraft, TypeUpdate } from '@commercetools/platform-sdk';
|
|
2
|
+
export type GetByKeyCustomType = {
|
|
3
|
+
key: string;
|
|
4
|
+
};
|
|
5
|
+
export type ExistsByKeyCustomType = {
|
|
6
|
+
key: string;
|
|
7
|
+
};
|
|
8
|
+
export type UpdateCustomType = {
|
|
9
|
+
key: string;
|
|
10
|
+
updateActions: TypeUpdate;
|
|
11
|
+
};
|
|
12
|
+
export interface CustomTypeService {
|
|
13
|
+
getByKey(opts: GetByKeyCustomType): Promise<Type>;
|
|
14
|
+
existsByKey(opts: GetByKeyCustomType): Promise<boolean>;
|
|
15
|
+
create(draft: TypeDraft): Promise<Type>;
|
|
16
|
+
update(opts: UpdateCustomType): Promise<Type>;
|
|
17
|
+
createOrUpdate(customTypeDraft: TypeDraft): Promise<Type>;
|
|
18
|
+
createOrUpdatePredefinedPaymentMethodTypes(): Promise<Type[]>;
|
|
19
|
+
createOrUpdatePredefinedInterfaceInteractionType(): Promise<Type>;
|
|
20
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommercetoolsAPI, UpdateResource } from './api.type';
|
|
2
2
|
import { Logger } from '../../logger';
|
|
3
|
-
import { PaymentMethod, PaymentMethodPagedQueryResponse, PaymentMethodUpdateAction } from '@commercetools/platform-sdk';
|
|
3
|
+
import { CustomFieldsDraft, PaymentMethod, PaymentMethodPagedQueryResponse, PaymentMethodUpdateAction } from '@commercetools/platform-sdk';
|
|
4
4
|
export type PaymentMethodServiceOptions = {
|
|
5
5
|
ctAPI: CommercetoolsAPI;
|
|
6
6
|
logger: Logger;
|
|
@@ -44,6 +44,7 @@ export type SavePaymentMethodDraft = {
|
|
|
44
44
|
paymentInterface: string;
|
|
45
45
|
interfaceAccount?: string;
|
|
46
46
|
method: string;
|
|
47
|
+
customFields?: CustomFieldsDraft;
|
|
47
48
|
};
|
|
48
49
|
/**
|
|
49
50
|
* Payment methods service interface exposes methods to interact with the commercetools platform API.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomFieldsDraft, Money, Payment, PaymentDraft, TransactionState, TransactionType } from '@commercetools/platform-sdk';
|
|
1
|
+
import { CustomFieldsDraft, Money, Payment, PaymentDraft, PaymentMethodInfoDraft, TransactionState, TransactionType } from '@commercetools/platform-sdk';
|
|
2
2
|
import { CommercetoolsAPI } from './api.type';
|
|
3
3
|
import { Logger } from '../../logger';
|
|
4
4
|
export type PaymentAmount = {
|
|
@@ -25,6 +25,7 @@ export type TransactionData = {
|
|
|
25
25
|
type: TransactionType;
|
|
26
26
|
amount: Money;
|
|
27
27
|
interactionId?: string;
|
|
28
|
+
interfaceId?: string;
|
|
28
29
|
state: TransactionState;
|
|
29
30
|
};
|
|
30
31
|
export type UpdatePayment = {
|
|
@@ -33,6 +34,7 @@ export type UpdatePayment = {
|
|
|
33
34
|
pspInteractions?: CustomFieldsDraft[];
|
|
34
35
|
transaction?: TransactionData;
|
|
35
36
|
paymentMethod?: string;
|
|
37
|
+
paymentMethodInfo?: PaymentMethodInfoDraft;
|
|
36
38
|
customFields?: CustomFieldsDraft;
|
|
37
39
|
token?: string;
|
|
38
40
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./payment-methods/card"), exports);
|
|
18
|
+
__exportStar(require("./payment-methods/sepa"), exports);
|
|
19
|
+
__exportStar(require("./payment-methods/shared"), exports);
|
|
20
|
+
__exportStar(require("./payment-interface-interactions"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CustomFieldsDraft, TypeDraft } from '@commercetools/platform-sdk';
|
|
2
|
+
export declare const PaymentInterfaceInteractionTypeKey = "commercetools-checkout-payment-interface-interaction";
|
|
3
|
+
export declare const PaymentInterfaceInteractionTypeDraft: TypeDraft;
|
|
4
|
+
export type InterfaceInteractionFields = {
|
|
5
|
+
interactionId: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
request?: string;
|
|
8
|
+
response?: string;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const GenerateInterfaceInteractionCustomFieldsDraft: (fields: InterfaceInteractionFields) => CustomFieldsDraft;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerateInterfaceInteractionCustomFieldsDraft = exports.PaymentInterfaceInteractionTypeDraft = exports.PaymentInterfaceInteractionTypeKey = void 0;
|
|
4
|
+
exports.PaymentInterfaceInteractionTypeKey = 'commercetools-checkout-payment-interface-interaction';
|
|
5
|
+
exports.PaymentInterfaceInteractionTypeDraft = {
|
|
6
|
+
key: exports.PaymentInterfaceInteractionTypeKey,
|
|
7
|
+
name: {
|
|
8
|
+
en: 'commercetools Checkout Payment Interface Interaction Type',
|
|
9
|
+
},
|
|
10
|
+
resourceTypeIds: ['payment-interface-interaction'],
|
|
11
|
+
fieldDefinitions: [
|
|
12
|
+
{
|
|
13
|
+
name: 'interactionId',
|
|
14
|
+
label: {
|
|
15
|
+
en: 'Interaction ID',
|
|
16
|
+
},
|
|
17
|
+
required: true,
|
|
18
|
+
type: {
|
|
19
|
+
name: 'String',
|
|
20
|
+
},
|
|
21
|
+
inputHint: 'SingleLine',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'createdAt',
|
|
25
|
+
label: {
|
|
26
|
+
en: 'Created At',
|
|
27
|
+
},
|
|
28
|
+
required: true,
|
|
29
|
+
type: {
|
|
30
|
+
name: 'DateTime',
|
|
31
|
+
},
|
|
32
|
+
inputHint: 'SingleLine',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'request',
|
|
36
|
+
label: {
|
|
37
|
+
en: 'Request',
|
|
38
|
+
},
|
|
39
|
+
required: false,
|
|
40
|
+
type: {
|
|
41
|
+
name: 'String',
|
|
42
|
+
},
|
|
43
|
+
inputHint: 'MultiLine',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'response',
|
|
47
|
+
label: {
|
|
48
|
+
en: 'Response',
|
|
49
|
+
},
|
|
50
|
+
required: false,
|
|
51
|
+
type: {
|
|
52
|
+
name: 'String',
|
|
53
|
+
},
|
|
54
|
+
inputHint: 'MultiLine',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'type',
|
|
58
|
+
label: {
|
|
59
|
+
en: 'Type',
|
|
60
|
+
},
|
|
61
|
+
required: true,
|
|
62
|
+
type: {
|
|
63
|
+
name: 'String',
|
|
64
|
+
},
|
|
65
|
+
inputHint: 'SingleLine',
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
const GenerateInterfaceInteractionCustomFieldsDraft = (fields) => {
|
|
70
|
+
return {
|
|
71
|
+
type: {
|
|
72
|
+
key: exports.PaymentInterfaceInteractionTypeKey,
|
|
73
|
+
typeId: 'type',
|
|
74
|
+
},
|
|
75
|
+
fields: fields,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
exports.GenerateInterfaceInteractionCustomFieldsDraft = GenerateInterfaceInteractionCustomFieldsDraft;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CustomFieldsDraft, TypeDraft } from '@commercetools/platform-sdk';
|
|
2
|
+
export declare const CardDetailsTypeKey = "commercetools-checkout-card-details";
|
|
3
|
+
export declare const CardDetailsTypeDraft: TypeDraft;
|
|
4
|
+
export type CardDetailsFields = {
|
|
5
|
+
brand?: string;
|
|
6
|
+
lastFour?: string;
|
|
7
|
+
bin?: string;
|
|
8
|
+
expiryMonth?: number;
|
|
9
|
+
expiryYear?: number;
|
|
10
|
+
storePaymentMethod?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const GenerateCardDetailsCustomFieldsDraft: (fields: CardDetailsFields) => CustomFieldsDraft;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerateCardDetailsCustomFieldsDraft = exports.CardDetailsTypeDraft = exports.CardDetailsTypeKey = void 0;
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
exports.CardDetailsTypeKey = 'commercetools-checkout-card-details';
|
|
6
|
+
exports.CardDetailsTypeDraft = {
|
|
7
|
+
key: exports.CardDetailsTypeKey,
|
|
8
|
+
name: {
|
|
9
|
+
en: 'Card payment details',
|
|
10
|
+
},
|
|
11
|
+
resourceTypeIds: ['payment-method-info', 'payment-method'],
|
|
12
|
+
fieldDefinitions: [
|
|
13
|
+
{
|
|
14
|
+
name: 'brand',
|
|
15
|
+
label: {
|
|
16
|
+
en: 'Card Brand',
|
|
17
|
+
},
|
|
18
|
+
type: {
|
|
19
|
+
name: 'String',
|
|
20
|
+
},
|
|
21
|
+
required: false,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'lastFour',
|
|
25
|
+
label: {
|
|
26
|
+
en: 'Last four digits of the card',
|
|
27
|
+
},
|
|
28
|
+
type: {
|
|
29
|
+
name: 'String',
|
|
30
|
+
},
|
|
31
|
+
required: false,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'bin',
|
|
35
|
+
label: {
|
|
36
|
+
en: 'Card BIN',
|
|
37
|
+
},
|
|
38
|
+
type: {
|
|
39
|
+
name: 'String',
|
|
40
|
+
},
|
|
41
|
+
required: false,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'expiryMonth',
|
|
45
|
+
label: {
|
|
46
|
+
en: 'Expiry Month',
|
|
47
|
+
},
|
|
48
|
+
type: {
|
|
49
|
+
name: 'Number',
|
|
50
|
+
},
|
|
51
|
+
required: false,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'expiryYear',
|
|
55
|
+
label: {
|
|
56
|
+
en: 'Expiry Year',
|
|
57
|
+
},
|
|
58
|
+
type: {
|
|
59
|
+
name: 'Number',
|
|
60
|
+
},
|
|
61
|
+
required: false,
|
|
62
|
+
},
|
|
63
|
+
shared_1.StorePaymentMethodFieldDefinition,
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
const GenerateCardDetailsCustomFieldsDraft = (fields) => {
|
|
67
|
+
return {
|
|
68
|
+
type: {
|
|
69
|
+
key: exports.CardDetailsTypeKey,
|
|
70
|
+
typeId: 'type',
|
|
71
|
+
},
|
|
72
|
+
fields: fields,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exports.GenerateCardDetailsCustomFieldsDraft = GenerateCardDetailsCustomFieldsDraft;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CustomFieldsDraft, TypeDraft } from '@commercetools/platform-sdk';
|
|
2
|
+
export declare const SepaDetailsTypeKey = "commercetools-checkout-sepa-details";
|
|
3
|
+
export declare const SepaDetailsTypeDraft: TypeDraft;
|
|
4
|
+
export type SepaDetailsFields = {
|
|
5
|
+
lastFour?: string;
|
|
6
|
+
storePaymentMethod?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const GenerateSepaDetailsCustomFieldsDraft: (fields: SepaDetailsFields) => CustomFieldsDraft;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerateSepaDetailsCustomFieldsDraft = exports.SepaDetailsTypeDraft = exports.SepaDetailsTypeKey = void 0;
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
exports.SepaDetailsTypeKey = 'commercetools-checkout-sepa-details';
|
|
6
|
+
exports.SepaDetailsTypeDraft = {
|
|
7
|
+
key: exports.SepaDetailsTypeKey,
|
|
8
|
+
name: {
|
|
9
|
+
en: 'SEPA Direct Debit details',
|
|
10
|
+
},
|
|
11
|
+
resourceTypeIds: ['payment-method-info', 'payment-method'],
|
|
12
|
+
fieldDefinitions: [
|
|
13
|
+
{
|
|
14
|
+
name: 'lastFour',
|
|
15
|
+
label: {
|
|
16
|
+
en: 'Last four digits of IBAN',
|
|
17
|
+
},
|
|
18
|
+
type: {
|
|
19
|
+
name: 'String',
|
|
20
|
+
},
|
|
21
|
+
required: false,
|
|
22
|
+
},
|
|
23
|
+
shared_1.StorePaymentMethodFieldDefinition,
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
const GenerateSepaDetailsCustomFieldsDraft = (fields) => {
|
|
27
|
+
return {
|
|
28
|
+
type: {
|
|
29
|
+
key: exports.SepaDetailsTypeKey,
|
|
30
|
+
typeId: 'type',
|
|
31
|
+
},
|
|
32
|
+
fields: fields,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.GenerateSepaDetailsCustomFieldsDraft = GenerateSepaDetailsCustomFieldsDraft;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StorePaymentMethodFieldDefinition = void 0;
|
|
4
|
+
exports.StorePaymentMethodFieldDefinition = {
|
|
5
|
+
name: 'storePaymentMethod',
|
|
6
|
+
label: {
|
|
7
|
+
en: 'Store the payment method',
|
|
8
|
+
},
|
|
9
|
+
type: {
|
|
10
|
+
name: 'Boolean',
|
|
11
|
+
},
|
|
12
|
+
required: false,
|
|
13
|
+
};
|
package/dist/errorx/errorx.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type ErrorxBaseOpts = {
|
|
|
9
9
|
message: string;
|
|
10
10
|
code: string;
|
|
11
11
|
httpErrorStatus: number;
|
|
12
|
+
detailedErrorMessage?: string;
|
|
12
13
|
};
|
|
13
14
|
export type ErrorxOpts = ErrorxBaseOpts & ErrorxAdditionalOpts;
|
|
14
15
|
/**
|
|
@@ -18,6 +19,7 @@ export declare class Errorx extends Error {
|
|
|
18
19
|
code: string;
|
|
19
20
|
httpErrorStatus: number;
|
|
20
21
|
cause?: Error | unknown;
|
|
22
|
+
detailedErrorMessage?: string;
|
|
21
23
|
privateFields?: object;
|
|
22
24
|
privateMessage?: string;
|
|
23
25
|
fields?: object;
|
package/dist/errorx/errorx.js
CHANGED
|
@@ -8,6 +8,7 @@ class Errorx extends Error {
|
|
|
8
8
|
code;
|
|
9
9
|
httpErrorStatus;
|
|
10
10
|
cause;
|
|
11
|
+
detailedErrorMessage;
|
|
11
12
|
privateFields;
|
|
12
13
|
privateMessage;
|
|
13
14
|
fields;
|
|
@@ -20,6 +21,9 @@ class Errorx extends Error {
|
|
|
20
21
|
if (opts.cause) {
|
|
21
22
|
this.cause = opts.cause;
|
|
22
23
|
}
|
|
24
|
+
if (opts.detailedErrorMessage) {
|
|
25
|
+
this.detailedErrorMessage = opts.detailedErrorMessage;
|
|
26
|
+
}
|
|
23
27
|
if (opts.privateFields) {
|
|
24
28
|
this.privateFields = opts.privateFields;
|
|
25
29
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ import { DefaultCartService } from './commercetools/services/ct-cart.service';
|
|
|
5
5
|
import { DefaultOrderService } from './commercetools/services/ct-order.service';
|
|
6
6
|
import { DefaultPaymentService } from './commercetools/services/ct-payment.service';
|
|
7
7
|
import { DefaultPaymentMethodService } from './commercetools/services/ct-payment-method.service';
|
|
8
|
+
import { DefaultCustomTypeService } from './commercetools/services/ct-custom-type.service';
|
|
8
9
|
import { Logger } from './logger';
|
|
9
10
|
export * from './api';
|
|
10
11
|
export * from './commercetools';
|
|
11
12
|
export * from './errorx';
|
|
12
13
|
export * from './logger';
|
|
13
14
|
export * from './security';
|
|
15
|
+
export * from './custom-types';
|
|
14
16
|
export declare const setupPaymentSDK: (opts: {
|
|
15
17
|
authUrl: string;
|
|
16
18
|
apiUrl: string;
|
|
@@ -29,6 +31,7 @@ export declare const setupPaymentSDK: (opts: {
|
|
|
29
31
|
ctOrderService: DefaultOrderService;
|
|
30
32
|
ctPaymentService: DefaultPaymentService;
|
|
31
33
|
ctPaymentMethodService: DefaultPaymentMethodService;
|
|
34
|
+
ctCustomTypeService: DefaultCustomTypeService;
|
|
32
35
|
ctAuthorizationService: DefaultAuthorizationService;
|
|
33
36
|
contextProvider: RequestContextProvider;
|
|
34
37
|
sessionHeaderAuthHookFn: SessionHeaderAuthenticationHook;
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const ct_order_service_1 = require("./commercetools/services/ct-order.service");
|
|
|
23
23
|
const ct_payment_service_1 = require("./commercetools/services/ct-payment.service");
|
|
24
24
|
const ct_payment_method_service_1 = require("./commercetools/services/ct-payment-method.service");
|
|
25
25
|
const ct_session_service_1 = require("./commercetools/services/ct-session.service");
|
|
26
|
+
const ct_custom_type_service_1 = require("./commercetools/services/ct-custom-type.service");
|
|
26
27
|
const base_decorator_1 = require("./fetch/decorators/base.decorator");
|
|
27
28
|
const monitoring_decorator_1 = require("./fetch/decorators/monitoring.decorator");
|
|
28
29
|
const logger_1 = require("./logger");
|
|
@@ -32,6 +33,7 @@ __exportStar(require("./commercetools"), exports);
|
|
|
32
33
|
__exportStar(require("./errorx"), exports);
|
|
33
34
|
__exportStar(require("./logger"), exports);
|
|
34
35
|
__exportStar(require("./security"), exports);
|
|
36
|
+
__exportStar(require("./custom-types"), exports);
|
|
35
37
|
const setupPaymentSDK = (opts) => {
|
|
36
38
|
const contextProvider = new api_1.RequestContextProvider({
|
|
37
39
|
getContextFn: opts.getContextFn,
|
|
@@ -66,6 +68,7 @@ const setupPaymentSDK = (opts) => {
|
|
|
66
68
|
const ctOrderService = new ct_order_service_1.DefaultOrderService({ ctAPI, logger });
|
|
67
69
|
const ctPaymentService = new ct_payment_service_1.DefaultPaymentService({ ctAPI, logger });
|
|
68
70
|
const ctPaymentMethodService = new ct_payment_method_service_1.DefaultPaymentMethodService({ ctAPI, logger });
|
|
71
|
+
const ctCustomTypeService = new ct_custom_type_service_1.DefaultCustomTypeService({ ctAPI, logger });
|
|
69
72
|
const oauth2Service = new security_1.DefaultOauth2Service({ logger });
|
|
70
73
|
const jwtService = new security_1.DefaultJWTService({
|
|
71
74
|
jwksUrl: opts.jwksUrl,
|
|
@@ -135,6 +138,7 @@ const setupPaymentSDK = (opts) => {
|
|
|
135
138
|
ctOrderService,
|
|
136
139
|
ctPaymentService,
|
|
137
140
|
ctPaymentMethodService,
|
|
141
|
+
ctCustomTypeService,
|
|
138
142
|
ctAuthorizationService,
|
|
139
143
|
contextProvider,
|
|
140
144
|
sessionHeaderAuthHookFn,
|
|
@@ -20,7 +20,11 @@ export type SessionPrincipal = {
|
|
|
20
20
|
cartId: string;
|
|
21
21
|
allowedPaymentMethods: string[];
|
|
22
22
|
processorUrl: string;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated use checkoutTransactionItemId instead
|
|
25
|
+
*/
|
|
23
26
|
paymentInterface?: string;
|
|
27
|
+
checkoutTransactionItemId?: string;
|
|
24
28
|
merchantReturnUrl?: string;
|
|
25
29
|
futureOrderNumber?: string;
|
|
26
30
|
giftCardPlannedAmount?: Money;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Payment SDK for commercetools payment connectors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@commercetools-backend/loggers": "24.5.0",
|
|
19
|
-
"@commercetools/platform-sdk": "8.
|
|
19
|
+
"@commercetools/platform-sdk": "8.18.0",
|
|
20
20
|
"@commercetools/ts-client": "3.4.1",
|
|
21
21
|
"jsonwebtoken": "9.0.2",
|
|
22
22
|
"jwks-rsa": "3.2.0",
|