@commercetools/connect-payments-sdk 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @commercetools/connect-payments-sdk
2
2
 
3
+ ## 0.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9946b9e: introduces hasTransactionInState method for checking if a payment has a transaction with some set filters, (type and state)
8
+
9
+ ## 0.20.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 7fc7ae1: Fix UpdatePayment type. Use CustomFieldsDraft instead of CustomFields
14
+
3
15
  ## 0.20.0
4
16
 
5
17
  ### Minor Changes
@@ -4,6 +4,6 @@ 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 { CommercetoolsClient } from './types/api.type';
7
- export { CustomFields, Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, } from '@commercetools/platform-sdk';
7
+ export { CustomFieldsDraft, Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, } from '@commercetools/platform-sdk';
8
8
  export * as CurrencyConverters from './helpers/currency.converter';
9
9
  export * as TaxRateConverter from './helpers/taxrate.converter';
@@ -1,5 +1,5 @@
1
1
  import { Payment, PaymentDraft, Transaction } from '@commercetools/platform-sdk';
2
- import { FindPaymentsByInterfaceId, GetPayment, PaymentService, PaymentServiceOptions, TransactionData, UpdatePayment } from '../types/payment.type';
2
+ import { FindPaymentsByInterfaceId, FindTransaction, GetPayment, PaymentService, PaymentServiceOptions, TransactionData, UpdatePayment } from '../types/payment.type';
3
3
  /**
4
4
  * This is the default implementation of the PaymentService interface.
5
5
  */
@@ -20,5 +20,6 @@ export declare class DefaultPaymentService implements PaymentService {
20
20
  private populateSetCustomType;
21
21
  private populateAddInterfaceInteractions;
22
22
  findMatchingTransactions(payment: Payment, transaction: TransactionData): Transaction[];
23
+ hasTransactionInState(opts: FindTransaction): boolean;
23
24
  private consolidateTransactionChanges;
24
25
  }
@@ -141,6 +141,9 @@ class DefaultPaymentService {
141
141
  tx.state === 'Initial')));
142
142
  });
143
143
  }
144
+ hasTransactionInState(opts) {
145
+ return opts.payment.transactions.some((tx) => tx.type === opts.transactionType && opts.states.includes(tx.state));
146
+ }
144
147
  consolidateTransactionChanges(payment, transaction) {
145
148
  const actions = [];
146
149
  // If the transaction is in Initial state and has no interactionId, we discard it as it does not provide any value
@@ -1,4 +1,4 @@
1
- import { CustomFields, Money, Payment, PaymentDraft, TransactionState, TransactionType } from '@commercetools/platform-sdk';
1
+ import { CustomFieldsDraft, Money, Payment, PaymentDraft, TransactionState, TransactionType } from '@commercetools/platform-sdk';
2
2
  import { CommercetoolsAPI } from './api.type';
3
3
  import { Logger } from '../../logger';
4
4
  export type PaymentAmount = {
@@ -30,10 +30,15 @@ export type TransactionData = {
30
30
  export type UpdatePayment = {
31
31
  id: string;
32
32
  pspReference?: string;
33
- pspInteractions?: CustomFields[];
33
+ pspInteractions?: CustomFieldsDraft[];
34
34
  transaction?: TransactionData;
35
35
  paymentMethod?: string;
36
- customFields?: CustomFields;
36
+ customFields?: CustomFieldsDraft;
37
+ };
38
+ export type FindTransaction = {
39
+ payment: Payment;
40
+ transactionType: TransactionType;
41
+ states: TransactionState[];
37
42
  };
38
43
  /**
39
44
  * Payment service interface exposes methods to interact with the commercetools platform API.
@@ -41,6 +46,7 @@ export type UpdatePayment = {
41
46
  export interface PaymentService {
42
47
  getPayment(opts: GetPayment): Promise<Payment>;
43
48
  findPaymentsByInterfaceId(opts: FindPaymentsByInterfaceId): Promise<Payment[]>;
49
+ hasTransactionInState(opts: FindTransaction): boolean;
44
50
  createPayment(draft: PaymentDraft): Promise<Payment>;
45
51
  updatePayment(opts: UpdatePayment): Promise<Payment>;
46
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/connect-payments-sdk",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Payment SDK for commercetools payment connectors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@commercetools-backend/loggers": "23.2.0",
18
+ "@commercetools-backend/loggers": "23.2.2",
19
19
  "@commercetools/platform-sdk": "8.5.0",
20
20
  "@commercetools/sdk-client-v2": "2.5.0",
21
21
  "jsonwebtoken": "9.0.2",