@commercetools/connect-payments-sdk 0.28.0 → 1.0.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 +7 -0
- package/README.md +134 -7
- package/dist/commercetools/api/cart-api.d.ts +1 -1
- package/dist/commercetools/api/cart-api.js +6 -2
- package/dist/commercetools/services/ct-cart.service.js +1 -1
- package/dist/commercetools/services/ct-custom-type.service.d.ts +5 -5
- package/dist/commercetools/services/ct-custom-type.service.js +7 -7
- package/dist/commercetools/types/api.type.d.ts +1 -1
- package/dist/commercetools/types/cart.type.d.ts +8 -0
- package/dist/commercetools/types/custom-type.type.d.ts +16 -0
- package/dist/commercetools/types/payment.type.d.ts +9 -0
- package/dist/commercetools/types/session.type.d.ts +13 -0
- package/dist/custom-types/payment-interface-interactions.d.ts +6 -0
- package/dist/custom-types/payment-interface-interactions.js +6 -0
- package/dist/custom-types/payment-methods/card.d.ts +6 -0
- package/dist/custom-types/payment-methods/card.js +6 -0
- package/dist/custom-types/payment-methods/sepa.d.ts +6 -0
- package/dist/custom-types/payment-methods/sepa.js +6 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -0
- package/package.json +4 -4
- package/pnpm-workspace.yaml +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
# @commercetools/connect-payments-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 9079420: Graduate to stable release
|
|
8
|
+
|
|
3
9
|
## 0.28.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
12
|
+
|
|
6
13
|
- 9e2f639: chore(deps): upgrade dependencies to latest stable versions, including security patches
|
|
7
14
|
|
|
8
15
|
## 0.27.2
|
package/README.md
CHANGED
|
@@ -1,19 +1,146 @@
|
|
|
1
|
-
# @commercetools/connect-payments-sdk
|
|
1
|
+
# @commercetools/connect-payments-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The foundation library for building commercetools payment connectors. It handles all the boilerplate that every connector needs: commercetools API clients, session verification, JWT authentication, request context propagation, custom type management, and retry logic on concurrent modifications so connector authors can focus on PSP-specific business logic.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Install the package using npm:
|
|
8
|
-
|
|
9
7
|
```bash
|
|
10
8
|
npm install @commercetools/connect-payments-sdk
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
##
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
Call `setupPaymentSDK` once at application startup. It wires together all services and authentication hooks and returns them as a single object.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import {
|
|
17
|
+
setupPaymentSDK,
|
|
18
|
+
Logger,
|
|
19
|
+
RequestContextData,
|
|
20
|
+
} from '@commercetools/connect-payments-sdk';
|
|
21
|
+
import { getRequestContext, updateRequestContext } from './context';
|
|
22
|
+
import { config } from './config';
|
|
23
|
+
|
|
24
|
+
// Adapt your application logger to the SDK Logger interface
|
|
25
|
+
class AppLogger implements Logger {
|
|
26
|
+
debug = (obj: object, msg: string) => console.debug(msg, obj);
|
|
27
|
+
info = (obj: object, msg: string) => console.info(msg, obj);
|
|
28
|
+
warn = (obj: object, msg: string) => console.warn(msg, obj);
|
|
29
|
+
error = (obj: object, msg: string) => console.error(msg, obj);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const paymentSDK = setupPaymentSDK({
|
|
33
|
+
apiUrl: config.apiUrl,
|
|
34
|
+
authUrl: config.authUrl,
|
|
35
|
+
clientId: config.clientId,
|
|
36
|
+
clientSecret: config.clientSecret,
|
|
37
|
+
projectKey: config.projectKey,
|
|
38
|
+
sessionUrl: config.sessionUrl,
|
|
39
|
+
checkoutUrl: config.checkoutUrl,
|
|
40
|
+
jwksUrl: config.jwksUrl,
|
|
41
|
+
jwtIssuer: config.jwtIssuer,
|
|
42
|
+
|
|
43
|
+
// Return the current request context (called on every incoming request)
|
|
44
|
+
getContextFn: (): RequestContextData => {
|
|
45
|
+
const { correlationId, requestId, authentication } = getRequestContext();
|
|
46
|
+
return {
|
|
47
|
+
correlationId: correlationId || '',
|
|
48
|
+
requestId: requestId || '',
|
|
49
|
+
authentication,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// Merge updated fields back into the request context store
|
|
54
|
+
updateContextFn: (context: Partial<RequestContextData>) => {
|
|
55
|
+
updateRequestContext({
|
|
56
|
+
...(context.correlationId ? { correlationId: context.correlationId } : {}),
|
|
57
|
+
...(context.requestId ? { requestId: context.requestId } : {}),
|
|
58
|
+
...(context.authentication ? { authentication: context.authentication } : {}),
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
logger: new AppLogger(),
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
| Option | Description |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `apiUrl` | commercetools REST API URL (e.g. `https://api.europe-west1.gcp.commercetools.com`) |
|
|
71
|
+
| `authUrl` | commercetools auth URL (e.g. `https://auth.europe-west1.gcp.commercetools.com`) |
|
|
72
|
+
| `clientId` | commercetools API client ID with `manage_payments`, `view_sessions` and `introspect_oauth_tokens` scopes |
|
|
73
|
+
| `clientSecret` | commercetools API client secret |
|
|
74
|
+
| `projectKey` | commercetools project key |
|
|
75
|
+
| `sessionUrl` | commercetools Session API URL (e.g. `https://session.europe-west1.gcp.commercetools.com`) |
|
|
76
|
+
| `checkoutUrl` | commercetools Checkout API URL (e.g. `https://checkout.europe-west1.gcp.commercetools.com`) |
|
|
77
|
+
| `jwksUrl` | JWKS endpoint used to verify incoming JWTs (e.g. `https://mc-api.europe-west1.gcp.commercetools.com/.well-known/jwks.json`) |
|
|
78
|
+
| `jwtIssuer` | Expected `iss` claim in JWTs issued by commercetools (e.g. `https://mc-api.europe-west1.gcp.commercetools.com`) |
|
|
79
|
+
| `getContextFn` | Function that returns the current `RequestContextData` from your request-scoped store |
|
|
80
|
+
| `updateContextFn` | Function that merges partial data into your request-scoped store (used by the SDK to propagate `correlationId` etc.) |
|
|
81
|
+
| `logger` | Optional. Custom logger implementing the `Logger` interface. Defaults to the built-in commercetools structured logger. |
|
|
82
|
+
|
|
83
|
+
## What `setupPaymentSDK` returns
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const {
|
|
87
|
+
// commercetools API services
|
|
88
|
+
ctCartService, // get carts, calculate payment amounts, add payments
|
|
89
|
+
ctPaymentService, // create/update commercetools payments and transactions
|
|
90
|
+
ctOrderService, // find orders
|
|
91
|
+
ctPaymentMethodService, // manage stored payment methods (tokenization)
|
|
92
|
+
ctCustomTypeService, // create/update commercetools custom types (used in post-deploy)
|
|
93
|
+
ctAuthorizationService, // obtain OAuth2 tokens for outbound calls
|
|
94
|
+
ctRecurringPaymentJobService,
|
|
95
|
+
|
|
96
|
+
// Raw commercetools API client (escape hatch for unsupported operations)
|
|
97
|
+
ctAPI,
|
|
98
|
+
|
|
99
|
+
// Request context provider
|
|
100
|
+
contextProvider,
|
|
101
|
+
|
|
102
|
+
// Fastify hooks — register these on your routes
|
|
103
|
+
sessionHeaderAuthHookFn, // verifies the commercetools session ID from the `x-session-id` header
|
|
104
|
+
sessionQueryParamAuthHookFn, // verifies the commercetools session ID from a query parameter
|
|
105
|
+
jwtAuthHookFn, // verifies a commercetools-issued JWT
|
|
106
|
+
oauth2AuthHookFn, // verifies a connector OAuth2 token
|
|
107
|
+
authorityAuthorizationHookFn, // checks the caller has the required authority
|
|
108
|
+
} = paymentSDK;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Custom types
|
|
112
|
+
|
|
113
|
+
The SDK ships predefined commercetools custom type drafts for storing payment method details. Register them during connector post-deploy:
|
|
14
114
|
|
|
15
|
-
|
|
115
|
+
```typescript
|
|
116
|
+
import {
|
|
117
|
+
GenerateCardDetailsCustomFieldsDraft,
|
|
118
|
+
GenerateSepaDetailsCustomFieldsDraft,
|
|
119
|
+
GenerateInterfaceInteractionCustomFieldsDraft,
|
|
120
|
+
} from '@commercetools/connect-payments-sdk';
|
|
121
|
+
|
|
122
|
+
// In post-deploy:
|
|
123
|
+
await paymentSDK.ctCustomTypeService.createOrUpdatePredefinedPaymentMethodTypes();
|
|
124
|
+
await paymentSDK.ctCustomTypeService.createOrUpdatePredefinedInterfaceInteractionType();
|
|
125
|
+
|
|
126
|
+
// When processing a notification for a card payment:
|
|
127
|
+
const customFields = GenerateCardDetailsCustomFieldsDraft({
|
|
128
|
+
brand: 'Visa',
|
|
129
|
+
lastFour: '4242',
|
|
130
|
+
expiryMonth: 12,
|
|
131
|
+
expiryYear: 2027,
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
For connector-specific custom types, use `createOrUpdate` directly:
|
|
16
136
|
|
|
17
137
|
```typescript
|
|
18
|
-
|
|
138
|
+
await paymentSDK.ctCustomTypeService.createOrUpdate(myConnectorTypeDraft);
|
|
19
139
|
```
|
|
140
|
+
|
|
141
|
+
## Key behaviours
|
|
142
|
+
|
|
143
|
+
- **Consolidated payment updates** — `ctPaymentService.updatePayment` handles PSP reference, interface interactions, transaction state transitions, payment method info and custom fields in a single commercetools API call, so you never need to chain multiple update requests for a single PSP notification.
|
|
144
|
+
- **Retry on concurrent modification** — `ctCartService.addPayment` and `ctPaymentService.updatePayment` automatically retry with a fresh version on HTTP 409.
|
|
145
|
+
- **Planned payment amount** — `ctCartService.getPlannedPaymentAmount` deducts already-approved payments from the cart total, so you always get the remaining amount to charge. Pass `expand: ['paymentInfo.payments[*]']` to `getCart` to avoid N+1 payment fetches.
|
|
146
|
+
- **Request context propagation** — correlation IDs, authentication data and session information flow through every SDK call via `getContextFn`/`updateContextFn`, which you back with a Fastify `AsyncLocalStorage` or equivalent.
|
|
@@ -4,6 +4,6 @@ import { CommercetoolsBaseAPI } from './base-api';
|
|
|
4
4
|
export declare class CommercetoolsCartAPI extends CommercetoolsBaseAPI implements CartAPI {
|
|
5
5
|
constructor(opts: APIOpts);
|
|
6
6
|
find(queryPredicate: string): Promise<CartPagedQueryResponse>;
|
|
7
|
-
getCartById(id: string): Promise<Cart>;
|
|
7
|
+
getCartById(id: string, expand?: string[]): Promise<Cart>;
|
|
8
8
|
addPayment(opts: AddPayment): Promise<Cart>;
|
|
9
9
|
}
|
|
@@ -13,8 +13,12 @@ class CommercetoolsCartAPI extends base_api_1.CommercetoolsBaseAPI {
|
|
|
13
13
|
.get({ queryArgs: { where: queryPredicate } })
|
|
14
14
|
.execute());
|
|
15
15
|
}
|
|
16
|
-
async getCartById(id) {
|
|
17
|
-
return this.executeCall(this.client
|
|
16
|
+
async getCartById(id, expand) {
|
|
17
|
+
return this.executeCall(this.client
|
|
18
|
+
.carts()
|
|
19
|
+
.withId({ ID: id })
|
|
20
|
+
.get({ queryArgs: expand ? { expand } : undefined })
|
|
21
|
+
.execute());
|
|
18
22
|
}
|
|
19
23
|
async addPayment(opts) {
|
|
20
24
|
return this.executeCall(this.client
|
|
@@ -30,7 +30,7 @@ class DefaultCartService {
|
|
|
30
30
|
return result.results[0];
|
|
31
31
|
}
|
|
32
32
|
async getCart(opts) {
|
|
33
|
-
return await this.ctAPI.cart.getCartById(opts.id);
|
|
33
|
+
return await this.ctAPI.cart.getCartById(opts.id, opts.expand);
|
|
34
34
|
}
|
|
35
35
|
async getPlannedPaymentAmount(opts) {
|
|
36
36
|
const giftCardPlannedAmount = (0, __1.getGiftCardPlannedAmountFromContext)(this.contextProvider.getContextData());
|
|
@@ -15,15 +15,15 @@ export declare class DefaultCustomTypeService implements CustomTypeService {
|
|
|
15
15
|
createOrUpdatePredefinedPaymentMethodTypes(): Promise<Type[]>;
|
|
16
16
|
createOrUpdatePredefinedInterfaceInteractionType(): Promise<Type>;
|
|
17
17
|
/**
|
|
18
|
-
* Based on the given TypeDraft this will either create or update the custom type in
|
|
18
|
+
* Based on the given TypeDraft this will either create or update the custom type in commercetools based on the provided "key".
|
|
19
19
|
*
|
|
20
|
-
* - if a custom-type by key does not exist in
|
|
21
|
-
* - if a custom-type by key does exist in
|
|
20
|
+
* - if a custom-type by key does not exist in commercetools then it will create it using the given draft
|
|
21
|
+
* - if a custom-type by key does exist in commercetools it will gather a set of update actions to try and sync up the definitions
|
|
22
22
|
*
|
|
23
23
|
* The update currently supports:
|
|
24
|
-
* - adding missing field definitions. If the given draft contains field definitions that the custom-type in
|
|
24
|
+
* - adding missing field definitions. If the given draft contains field definitions that the custom-type in commercetools 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
25
|
*
|
|
26
|
-
* Differences between the TypeDraft and existing custom-type in
|
|
26
|
+
* Differences between the TypeDraft and existing custom-type in commercetools such as are not supported yet but could be added in the future.
|
|
27
27
|
* - remove field definition if they no longer exist in the TypeDraft
|
|
28
28
|
* - update/sync the possible enum values for a field definition
|
|
29
29
|
* - update/sync the actual field definition properties. Such as "localized label", "type" or "required" value
|
|
@@ -33,15 +33,15 @@ class DefaultCustomTypeService {
|
|
|
33
33
|
return await this.createOrUpdate(custom_types_1.PaymentInterfaceInteractionTypeDraft);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* Based on the given TypeDraft this will either create or update the custom type in
|
|
36
|
+
* Based on the given TypeDraft this will either create or update the custom type in commercetools based on the provided "key".
|
|
37
37
|
*
|
|
38
|
-
* - if a custom-type by key does not exist in
|
|
39
|
-
* - if a custom-type by key does exist in
|
|
38
|
+
* - if a custom-type by key does not exist in commercetools then it will create it using the given draft
|
|
39
|
+
* - if a custom-type by key does exist in commercetools it will gather a set of update actions to try and sync up the definitions
|
|
40
40
|
*
|
|
41
41
|
* The update currently supports:
|
|
42
|
-
* - adding missing field definitions. If the given draft contains field definitions that the custom-type in
|
|
42
|
+
* - adding missing field definitions. If the given draft contains field definitions that the custom-type in commercetools 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
43
|
*
|
|
44
|
-
* Differences between the TypeDraft and existing custom-type in
|
|
44
|
+
* Differences between the TypeDraft and existing custom-type in commercetools such as are not supported yet but could be added in the future.
|
|
45
45
|
* - remove field definition if they no longer exist in the TypeDraft
|
|
46
46
|
* - update/sync the possible enum values for a field definition
|
|
47
47
|
* - update/sync the actual field definition properties. Such as "localized label", "type" or "required" value
|
|
@@ -49,7 +49,7 @@ class DefaultCustomTypeService {
|
|
|
49
49
|
async createOrUpdate(customTypeDraft) {
|
|
50
50
|
const exists = await this.existsByKey({ key: customTypeDraft.key });
|
|
51
51
|
if (!exists) {
|
|
52
|
-
this.logger.info({ key: customTypeDraft.key }, 'Custom type by key does not exist in
|
|
52
|
+
this.logger.info({ key: customTypeDraft.key }, 'Custom type by key does not exist in commercetools, creating it');
|
|
53
53
|
return await this.create(customTypeDraft);
|
|
54
54
|
}
|
|
55
55
|
const customTypeFromCT = await this.getByKey({ key: customTypeDraft.key });
|
|
@@ -83,7 +83,7 @@ class DefaultCustomTypeService {
|
|
|
83
83
|
key: customTypeDraft.key,
|
|
84
84
|
missingFieldsCount: addFieldDefinitionUpdateActions.length,
|
|
85
85
|
fieldNames: missingFieldDefinitions.map((fd) => fd.name),
|
|
86
|
-
}, 'Custom type in
|
|
86
|
+
}, 'Custom type in commercetools is missing field definition from the draft, adding them');
|
|
87
87
|
}
|
|
88
88
|
return addFieldDefinitionUpdateActions;
|
|
89
89
|
}
|
|
@@ -45,7 +45,7 @@ export interface AuthorizationAPI {
|
|
|
45
45
|
getToken(): Promise<OauthToken>;
|
|
46
46
|
}
|
|
47
47
|
export interface CartAPI {
|
|
48
|
-
getCartById(id: string): Promise<Cart>;
|
|
48
|
+
getCartById(id: string, expand?: string[]): Promise<Cart>;
|
|
49
49
|
find(queryPredicate: string): Promise<CartPagedQueryResponse>;
|
|
50
50
|
addPayment(opts: AddPayment): Promise<Cart>;
|
|
51
51
|
}
|
|
@@ -6,6 +6,8 @@ import { ContextProvider, RequestContextData } from '../../api';
|
|
|
6
6
|
export type GetCart = {
|
|
7
7
|
id: string;
|
|
8
8
|
version?: number;
|
|
9
|
+
/** commercetools expand paths to include in the response, e.g. `['paymentInfo.payments[*]']` */
|
|
10
|
+
expand?: string[];
|
|
9
11
|
};
|
|
10
12
|
export type GetPaymentAmount = {
|
|
11
13
|
cart: Cart;
|
|
@@ -39,7 +41,12 @@ export type GetCartByPaymentIdRequest = {
|
|
|
39
41
|
* Cart service interface exposes methods to interact with the commercetools platform API.
|
|
40
42
|
*/
|
|
41
43
|
export interface CartService {
|
|
44
|
+
/** Finds the cart that contains the given payment ID. Throws if no cart is found. */
|
|
42
45
|
getCartByPaymentId(opts: GetCartByPaymentIdRequest): Promise<Cart>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a cart by ID. Pass `expand` to hydrate referenced resources in a single API call
|
|
48
|
+
* instead of fetching them individually afterwards (e.g. `['paymentInfo.payments[*]']`).
|
|
49
|
+
*/
|
|
43
50
|
getCart(opts: GetCart): Promise<Cart>;
|
|
44
51
|
/**
|
|
45
52
|
* Get payment amount for a cart. This method is used to calculate the payment amount for a cart.
|
|
@@ -54,6 +61,7 @@ export interface CartService {
|
|
|
54
61
|
* @param opts
|
|
55
62
|
*/
|
|
56
63
|
getPlannedPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
|
|
64
|
+
/** Adds a payment reference to the cart. Retries automatically on concurrent modification. */
|
|
57
65
|
addPayment(opts: AddPayment): Promise<Cart>;
|
|
58
66
|
/**
|
|
59
67
|
* Checks if the given cart contains items configured for recurring orders.
|
|
@@ -10,11 +10,27 @@ export type UpdateCustomType = {
|
|
|
10
10
|
updateActions: TypeUpdate;
|
|
11
11
|
};
|
|
12
12
|
export interface CustomTypeService {
|
|
13
|
+
/** Returns a commercetools custom type by key. Throws if not found. */
|
|
13
14
|
getByKey(opts: GetByKeyCustomType): Promise<Type>;
|
|
15
|
+
/** Returns true if a commercetools custom type with the given key exists. */
|
|
14
16
|
existsByKey(opts: GetByKeyCustomType): Promise<boolean>;
|
|
17
|
+
/** Creates a new commercetools custom type from the provided draft. */
|
|
15
18
|
create(draft: TypeDraft): Promise<Type>;
|
|
19
|
+
/** Applies update actions to an existing commercetools custom type. */
|
|
16
20
|
update(opts: UpdateCustomType): Promise<Type>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates the custom type if it does not exist, or adds any field definitions present in
|
|
23
|
+
* the draft but missing in the existing type. Field removals and type changes are not applied.
|
|
24
|
+
*/
|
|
17
25
|
createOrUpdate(customTypeDraft: TypeDraft): Promise<Type>;
|
|
26
|
+
/**
|
|
27
|
+
* Ensures the predefined payment method custom types (card, SEPA) exist in commercetools.
|
|
28
|
+
* Called during connector post-deploy when `ADYEN_STORE_PAYMENT_METHOD_DETAILS_ENABLED` is true.
|
|
29
|
+
*/
|
|
18
30
|
createOrUpdatePredefinedPaymentMethodTypes(): Promise<Type[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Ensures the predefined interface interaction custom type exists in commercetools.
|
|
33
|
+
* Used to record raw PSP request/response pairs on the commercetools payment.
|
|
34
|
+
*/
|
|
19
35
|
createOrUpdatePredefinedInterfaceInteractionType(): Promise<Type>;
|
|
20
36
|
}
|
|
@@ -47,9 +47,18 @@ export type FindTransaction = {
|
|
|
47
47
|
* Payment service interface exposes methods to interact with the commercetools platform API.
|
|
48
48
|
*/
|
|
49
49
|
export interface PaymentService {
|
|
50
|
+
/** Returns a payment by ID. Throws if not found. */
|
|
50
51
|
getPayment(opts: GetPayment): Promise<Payment>;
|
|
52
|
+
/** Finds all payments whose `interfaceId` matches the given PSP reference. */
|
|
51
53
|
findPaymentsByInterfaceId(opts: FindPaymentsByInterfaceId): Promise<Payment[]>;
|
|
54
|
+
/** Returns true if the payment has at least one transaction of the given type in any of the given states. */
|
|
52
55
|
hasTransactionInState(opts: FindTransaction): boolean;
|
|
56
|
+
/** Creates a new commercetools payment from the provided draft. */
|
|
53
57
|
createPayment(draft: PaymentDraft): Promise<Payment>;
|
|
58
|
+
/**
|
|
59
|
+
* Applies changes to an existing commercetools payment. Handles PSP reference, interface interactions,
|
|
60
|
+
* transaction state transitions, payment method info and custom fields in a single update call.
|
|
61
|
+
* Retries automatically on concurrent modification.
|
|
62
|
+
*/
|
|
54
63
|
updatePayment(opts: UpdatePayment): Promise<Payment>;
|
|
55
64
|
}
|
|
@@ -23,14 +23,27 @@ export type Session = {
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
export interface SessionService {
|
|
26
|
+
/** Verifies a session ID against the commercetools Session API and returns the session object. Throws if invalid or expired. */
|
|
26
27
|
verifySession(sessionId: string): Promise<Session>;
|
|
28
|
+
/** Returns the cart ID associated with the session. */
|
|
27
29
|
getCartFromSession(session: Session): string;
|
|
30
|
+
/** Returns the list of payment method keys the merchant has allowed for this session. */
|
|
28
31
|
getAllowedPaymentMethodsFromSession(session: Session): string[];
|
|
32
|
+
/** Returns the processor URL stored in the session metadata. */
|
|
29
33
|
getProcessorUrlFromSession(session: Session): string;
|
|
34
|
+
/** Returns the payment interface identifier stored in the session, if present. */
|
|
30
35
|
getPaymentInterfaceFromSession(session: Session): string | undefined;
|
|
36
|
+
/** Returns the checkout transaction item ID stored in the session, if present. */
|
|
31
37
|
getCheckoutTransactionItemIdFromSession(session: Session): string | undefined;
|
|
38
|
+
/** Returns the merchant return URL stored in the session, if present. */
|
|
32
39
|
getMerchantReturnUrlFromSession(session: Session): string | undefined;
|
|
40
|
+
/** Returns the future order number stored in the session, if present. */
|
|
33
41
|
getFutureOrderNumberFromSession(session: Session): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the gift card planned amount stored in the session, if present.
|
|
44
|
+
* Used by `getPlannedPaymentAmount` to deduct the gift card portion from the total.
|
|
45
|
+
*/
|
|
34
46
|
getGiftCardPlannedAmountFromSession(session: Session): Money | undefined;
|
|
47
|
+
/** Returns the correlation ID stored in the session, if present. */
|
|
35
48
|
getCorrelationIdFromSession(session: Session): string | undefined;
|
|
36
49
|
}
|
|
@@ -8,4 +8,10 @@ export type InterfaceInteractionFields = {
|
|
|
8
8
|
response?: string;
|
|
9
9
|
type: string;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Builds a `CustomFieldsDraft` that records a raw PSP request/response pair as a
|
|
13
|
+
* `payment-interface-interaction` on a commercetools payment.
|
|
14
|
+
* Requires the `commercetools-checkout-payment-interface-interaction` custom type to exist
|
|
15
|
+
* (created by `createOrUpdatePredefinedInterfaceInteractionType`).
|
|
16
|
+
*/
|
|
11
17
|
export declare const GenerateInterfaceInteractionCustomFieldsDraft: (fields: InterfaceInteractionFields) => CustomFieldsDraft;
|
|
@@ -66,6 +66,12 @@ exports.PaymentInterfaceInteractionTypeDraft = {
|
|
|
66
66
|
},
|
|
67
67
|
],
|
|
68
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Builds a `CustomFieldsDraft` that records a raw PSP request/response pair as a
|
|
71
|
+
* `payment-interface-interaction` on a commercetools payment.
|
|
72
|
+
* Requires the `commercetools-checkout-payment-interface-interaction` custom type to exist
|
|
73
|
+
* (created by `createOrUpdatePredefinedInterfaceInteractionType`).
|
|
74
|
+
*/
|
|
69
75
|
const GenerateInterfaceInteractionCustomFieldsDraft = (fields) => {
|
|
70
76
|
return {
|
|
71
77
|
type: {
|
|
@@ -9,4 +9,10 @@ export type CardDetailsFields = {
|
|
|
9
9
|
expiryYear?: number;
|
|
10
10
|
storePaymentMethod?: boolean;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Builds a `CustomFieldsDraft` that sets the card details custom fields on a
|
|
14
|
+
* `payment-method-info` or `payment-method` resource.
|
|
15
|
+
* Requires the `commercetools-checkout-card-details` custom type to exist (created by
|
|
16
|
+
* `createOrUpdatePredefinedPaymentMethodTypes`).
|
|
17
|
+
*/
|
|
12
18
|
export declare const GenerateCardDetailsCustomFieldsDraft: (fields: CardDetailsFields) => CustomFieldsDraft;
|
|
@@ -63,6 +63,12 @@ exports.CardDetailsTypeDraft = {
|
|
|
63
63
|
shared_1.StorePaymentMethodFieldDefinition,
|
|
64
64
|
],
|
|
65
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Builds a `CustomFieldsDraft` that sets the card details custom fields on a
|
|
68
|
+
* `payment-method-info` or `payment-method` resource.
|
|
69
|
+
* Requires the `commercetools-checkout-card-details` custom type to exist (created by
|
|
70
|
+
* `createOrUpdatePredefinedPaymentMethodTypes`).
|
|
71
|
+
*/
|
|
66
72
|
const GenerateCardDetailsCustomFieldsDraft = (fields) => {
|
|
67
73
|
return {
|
|
68
74
|
type: {
|
|
@@ -5,4 +5,10 @@ export type SepaDetailsFields = {
|
|
|
5
5
|
lastFour?: string;
|
|
6
6
|
storePaymentMethod?: boolean;
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Builds a `CustomFieldsDraft` that sets the SEPA details custom fields on a
|
|
10
|
+
* `payment-method-info` or `payment-method` resource.
|
|
11
|
+
* Requires the `commercetools-checkout-sepa-details` custom type to exist (created by
|
|
12
|
+
* `createOrUpdatePredefinedPaymentMethodTypes`).
|
|
13
|
+
*/
|
|
8
14
|
export declare const GenerateSepaDetailsCustomFieldsDraft: (fields: SepaDetailsFields) => CustomFieldsDraft;
|
|
@@ -23,6 +23,12 @@ exports.SepaDetailsTypeDraft = {
|
|
|
23
23
|
shared_1.StorePaymentMethodFieldDefinition,
|
|
24
24
|
],
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Builds a `CustomFieldsDraft` that sets the SEPA details custom fields on a
|
|
28
|
+
* `payment-method-info` or `payment-method` resource.
|
|
29
|
+
* Requires the `commercetools-checkout-sepa-details` custom type to exist (created by
|
|
30
|
+
* `createOrUpdatePredefinedPaymentMethodTypes`).
|
|
31
|
+
*/
|
|
26
32
|
const GenerateSepaDetailsCustomFieldsDraft = (fields) => {
|
|
27
33
|
return {
|
|
28
34
|
type: {
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,23 @@ export * from './errorx';
|
|
|
14
14
|
export * from './logger';
|
|
15
15
|
export * from './security';
|
|
16
16
|
export * from './custom-types';
|
|
17
|
+
/**
|
|
18
|
+
* Initialises and wires together all SDK services and authentication hooks.
|
|
19
|
+
* Call this once at application startup and use the returned object throughout the connector.
|
|
20
|
+
*
|
|
21
|
+
* @param opts.authUrl - commercetools auth URL (e.g. `https://auth.europe-west1.gcp.commercetools.com`)
|
|
22
|
+
* @param opts.apiUrl - commercetools API URL
|
|
23
|
+
* @param opts.sessionUrl - commercetools Session API URL
|
|
24
|
+
* @param opts.checkoutUrl - commercetools Checkout API URL
|
|
25
|
+
* @param opts.jwksUrl - JWKS endpoint used to verify incoming JWTs
|
|
26
|
+
* @param opts.clientId - commercetools API client ID
|
|
27
|
+
* @param opts.clientSecret - commercetools API client secret
|
|
28
|
+
* @param opts.projectKey - commercetools project key
|
|
29
|
+
* @param opts.jwtIssuer - Expected `iss` claim in incoming JWTs
|
|
30
|
+
* @param opts.getContextFn - Returns the current request context (called on every request)
|
|
31
|
+
* @param opts.updateContextFn - Merges partial data into the current request context
|
|
32
|
+
* @param opts.logger - Optional custom logger; defaults to the built-in commercetools logger
|
|
33
|
+
*/
|
|
17
34
|
export declare const setupPaymentSDK: (opts: {
|
|
18
35
|
authUrl: string;
|
|
19
36
|
apiUrl: string;
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,23 @@ __exportStar(require("./errorx"), exports);
|
|
|
35
35
|
__exportStar(require("./logger"), exports);
|
|
36
36
|
__exportStar(require("./security"), exports);
|
|
37
37
|
__exportStar(require("./custom-types"), exports);
|
|
38
|
+
/**
|
|
39
|
+
* Initialises and wires together all SDK services and authentication hooks.
|
|
40
|
+
* Call this once at application startup and use the returned object throughout the connector.
|
|
41
|
+
*
|
|
42
|
+
* @param opts.authUrl - commercetools auth URL (e.g. `https://auth.europe-west1.gcp.commercetools.com`)
|
|
43
|
+
* @param opts.apiUrl - commercetools API URL
|
|
44
|
+
* @param opts.sessionUrl - commercetools Session API URL
|
|
45
|
+
* @param opts.checkoutUrl - commercetools Checkout API URL
|
|
46
|
+
* @param opts.jwksUrl - JWKS endpoint used to verify incoming JWTs
|
|
47
|
+
* @param opts.clientId - commercetools API client ID
|
|
48
|
+
* @param opts.clientSecret - commercetools API client secret
|
|
49
|
+
* @param opts.projectKey - commercetools project key
|
|
50
|
+
* @param opts.jwtIssuer - Expected `iss` claim in incoming JWTs
|
|
51
|
+
* @param opts.getContextFn - Returns the current request context (called on every request)
|
|
52
|
+
* @param opts.updateContextFn - Merges partial data into the current request context
|
|
53
|
+
* @param opts.logger - Optional custom logger; defaults to the built-in commercetools logger
|
|
54
|
+
*/
|
|
38
55
|
const setupPaymentSDK = (opts) => {
|
|
39
56
|
const contextProvider = new api_1.RequestContextProvider({
|
|
40
57
|
getContextFn: opts.getContextFn,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/connect-payments-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Payment SDK for commercetools payment connectors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@commercetools-backend/loggers": "27.
|
|
19
|
-
"@commercetools/platform-sdk": "8.
|
|
20
|
-
"@commercetools/ts-client": "4.
|
|
18
|
+
"@commercetools-backend/loggers": "27.6.3",
|
|
19
|
+
"@commercetools/platform-sdk": "8.27.0",
|
|
20
|
+
"@commercetools/ts-client": "4.10.0",
|
|
21
21
|
"jsonwebtoken": "9.0.3",
|
|
22
22
|
"jwks-rsa": "3.2.0",
|
|
23
23
|
"lodash": "4.18.1",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
overrides:
|
|
2
|
+
handlebars: "4.7.9"
|
|
3
|
+
jws: "3.2.3"
|
|
4
|
+
flatted: "3.4.2"
|
|
5
|
+
"picomatch@^2": "2.3.2"
|
|
6
|
+
"picomatch@^4": "4.0.4"
|
|
7
|
+
"minimatch@^3": "3.1.5"
|
|
8
|
+
"minimatch@^9": "9.0.9"
|
|
9
|
+
"@babel/helpers": "7.26.10"
|
|
10
|
+
"js-yaml@^3": "3.14.2"
|
|
11
|
+
"js-yaml@^4": "4.1.1"
|
|
12
|
+
"ajv@^6": "6.14.0"
|
|
13
|
+
"brace-expansion@^1": "1.1.14"
|
|
14
|
+
"@typescript-eslint/utils": "8.61.0"
|
|
15
|
+
|
|
16
|
+
allowBuilds:
|
|
17
|
+
'@swc/core': true
|
|
18
|
+
core-js-pure: true
|
|
19
|
+
msw: true
|
|
20
|
+
unrs-resolver: true
|