@commercetools/connect-payments-sdk 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @commercetools/connect-payments-sdk
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - de97af3: Improve updatePayment for resolving conflicts updating the interfaceId
8
+
3
9
  ## 0.8.0
4
10
 
5
11
  ### Minor Changes
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { JWTAuthenticationManager } from '../../security/authn/jwt-authn-manager';
4
3
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { Oauth2AuthenticationManager } from '../../security/authn/oauth2-authn-manager';
4
3
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
4
3
  import { SessionHeaderAuthenticationManager } from '../../security';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
4
3
  import { SessionQueryParamAuthenticationManager } from '../../security';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IncomingHttpHeaders } from 'node:http';
3
2
  export interface AuthenticationHook {
4
3
  authenticate(): (request: {
@@ -24,7 +24,11 @@ class DefaultPaymentService {
24
24
  for (let retries = 0; retries < maxRetries; retries++) {
25
25
  const payment = await this.getPayment({ id: opts.id });
26
26
  const actions = this.consolidateUpdateActions(payment, opts);
27
- this.logger.info({ paymentId: payment.id, actions }, 'Updating payment with actions');
27
+ this.logger.info({ paymentId: payment.id, paymentVersion: payment.version, actions, retries }, 'Updating payment with actions');
28
+ if (actions.length === 0) {
29
+ this.logger.info({ paymentId: payment.id, paymentVersion: payment.version, retries }, 'Update payment skipped, no actions to perform');
30
+ return payment;
31
+ }
28
32
  try {
29
33
  const updatedPayment = await this.ctAPI.payment.updatePayment({
30
34
  resource: {
@@ -37,10 +41,14 @@ class DefaultPaymentService {
37
41
  }
38
42
  catch (e) {
39
43
  err = e;
40
- if (e instanceof ct_api_error_1.CommercetoolsAPIError && e.httpErrorStatus === 409) {
44
+ if (e instanceof ct_api_error_1.CommercetoolsAPIError &&
45
+ (e.httpErrorStatus === 409 ||
46
+ (e.httpErrorStatus === 400 && e.message.includes('already used without setting a payment interface')))) {
47
+ this.logger.warn({ paymentId: payment.id, paymentVersion: payment.version, retries, err }, 'Unable to update the payment, retrying');
41
48
  retries++;
42
49
  }
43
50
  else {
51
+ this.logger.error({ paymentId: payment.id, paymentVersion: payment.version, retries, err }, 'Unable to update the payment, abort');
44
52
  throw e;
45
53
  }
46
54
  }
@@ -52,7 +60,7 @@ class DefaultPaymentService {
52
60
  if (!payment.interfaceId && updateInfo.pspReference) {
53
61
  actions.push(this.populateSetInterfaceIdAction(updateInfo.pspReference));
54
62
  }
55
- if (!payment.paymentMethodInfo.method && updateInfo.paymentMethod) {
63
+ if (!payment.paymentMethodInfo?.method && updateInfo.paymentMethod) {
56
64
  actions.push(this.populateSetPaymentMethod(updateInfo.paymentMethod));
57
65
  }
58
66
  if (updateInfo.transaction) {
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Fetcher } from '../types/fetch.type';
4
2
  /**
5
3
  * Basic fetcher implementation
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { ContextProvider, RequestContextData } from '../../api';
4
2
  import { Fetcher } from '../types/fetch.type';
5
3
  /**
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  export interface Fetcher {
4
2
  run(input: string | URL | globalThis.Request, init?: RequestInit): Promise<Response>;
5
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/connect-payments-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Payment SDK for commercetools payment connectors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@commercetools-backend/loggers": "22.27.0",
18
+ "@commercetools-backend/loggers": "22.29.0",
19
19
  "@commercetools/platform-sdk": "7.9.0",
20
20
  "@commercetools/sdk-client-v2": "2.5.0",
21
21
  "jsonwebtoken": "9.0.2",