@commercetools/connect-payments-sdk 0.25.1 → 0.26.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,11 @@
1
1
  # @commercetools/connect-payments-sdk
2
2
 
3
+ ## 0.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d6a10eb: feat(cart): added a new method to the cart service to check whether the cart is a recurring cart
8
+
3
9
  ## 0.25.1
4
10
 
5
11
  ### Patch Changes
@@ -7,6 +7,6 @@ export { PaymentMethodService as CommercetoolsPaymentMethodService } from './typ
7
7
  export { CustomTypeService as CommercetoolsCustomTypeService } from './types/custom-type.type';
8
8
  export * as CommercetoolsPaymentMethodTypes from './types/payment-method.type';
9
9
  export { CommercetoolsClient } from './types/api.type';
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
+ export { CustomFields, CustomFieldsDraft, Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, PaymentMethodInfoDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, PaymentMethod, PaymentMethodPagedQueryResponse, PaymentMethodToken, PaymentMethodStatus, Type, TypeDraft, TypeUpdateAction, ProductTypeDraft, TypeAddFieldDefinitionAction, TypeRemoveFieldDefinitionAction, CustomerSetCustomFieldAction, CustomerSetCustomTypeAction, CustomerUpdateAction, TypePagedQueryResponse, LocalizedString, Customer, } from '@commercetools/platform-sdk';
11
11
  export * as CurrencyConverters from './helpers/currency.converter';
12
12
  export * as TaxRateConverter from './helpers/taxrate.converter';
@@ -28,6 +28,7 @@ export declare class DefaultCartService implements CartService {
28
28
  */
29
29
  getNormalizedShipping(opts: GetNormalizedShipping): NormalizedShipping[];
30
30
  addPayment(opts: AddPayment): Promise<Cart>;
31
+ isRecurringCart(cart: Cart): boolean;
31
32
  private calculateTotalPaidAmount;
32
33
  private calculatePaymentAmount;
33
34
  private wasPaymentReverted;
@@ -170,6 +170,14 @@ class DefaultCartService {
170
170
  }
171
171
  throw err;
172
172
  }
173
+ isRecurringCart(cart) {
174
+ if (!cart.customerId)
175
+ return false;
176
+ const cartOrigin = cart.origin === 'RecurringOrder';
177
+ const hasRecurringLineItems = cart.lineItems?.some((item) => item.recurrenceInfo) ?? false;
178
+ const hasRecurringCustomLineItems = cart.customLineItems?.some((item) => item.recurrenceInfo) ?? false;
179
+ return cartOrigin || hasRecurringLineItems || hasRecurringCustomLineItems;
180
+ }
173
181
  async calculateTotalPaidAmount(cart) {
174
182
  if (!cart.paymentInfo || cart.paymentInfo.payments.length === 0) {
175
183
  return 0;
@@ -55,4 +55,11 @@ export interface CartService {
55
55
  */
56
56
  getPlannedPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
57
57
  addPayment(opts: AddPayment): Promise<Cart>;
58
+ /**
59
+ * Checks if the given cart contains items configured for recurring orders.
60
+ *
61
+ * @param cart - The cart to check
62
+ * @returns true if the cart contains recurring items, false otherwise
63
+ */
64
+ isRecurringCart(cart: Cart): boolean;
58
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/connect-payments-sdk",
3
- "version": "0.25.1",
3
+ "version": "0.26.0",
4
4
  "description": "Payment SDK for commercetools payment connectors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",