@commercetools/connect-payments-sdk 0.7.0 → 0.8.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,13 @@
1
1
  # @commercetools/connect-payments-sdk
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ae4e53a: - Add and expose a new order-service and order-api
8
+ - Add functionality to retrieve a order via a paymentId
9
+ - Add functionality to retrieve a cart via a paymentId
10
+
3
11
  ## 0.7.0
4
12
 
5
13
  ### Minor Changes
@@ -1,8 +1,9 @@
1
- import { Cart } from '@commercetools/platform-sdk';
1
+ import { Cart, CartPagedQueryResponse } from '@commercetools/platform-sdk';
2
2
  import { APIOpts, AddPayment, CartAPI } from '../types/api.type';
3
3
  import { CommercetoolsBaseAPI } from './base-api';
4
4
  export declare class CommercetoolsCartAPI extends CommercetoolsBaseAPI implements CartAPI {
5
5
  constructor(opts: APIOpts);
6
+ find(queryPredicate: string): Promise<CartPagedQueryResponse>;
6
7
  getCartById(id: string): Promise<Cart>;
7
8
  addPayment(opts: AddPayment): Promise<Cart>;
8
9
  }
@@ -7,6 +7,12 @@ class CommercetoolsCartAPI extends base_api_1.CommercetoolsBaseAPI {
7
7
  super(opts);
8
8
  Object.setPrototypeOf(this, CommercetoolsCartAPI.prototype);
9
9
  }
10
+ async find(queryPredicate) {
11
+ return this.executeCall(this.client
12
+ .carts()
13
+ .get({ queryArgs: { where: queryPredicate } })
14
+ .execute());
15
+ }
10
16
  async getCartById(id) {
11
17
  return this.executeCall(this.client.carts().withId({ ID: id }).get().execute());
12
18
  }
@@ -0,0 +1,7 @@
1
+ import { OrderPagedQueryResponse } from '@commercetools/platform-sdk';
2
+ import { APIOpts, OrderAPI } from '../types/api.type';
3
+ import { CommercetoolsBaseAPI } from './base-api';
4
+ export declare class CommercetoolsOrderAPI extends CommercetoolsBaseAPI implements OrderAPI {
5
+ constructor(opts: APIOpts);
6
+ find(queryPredicate: string): Promise<OrderPagedQueryResponse>;
7
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommercetoolsOrderAPI = void 0;
4
+ const base_api_1 = require("./base-api");
5
+ class CommercetoolsOrderAPI extends base_api_1.CommercetoolsBaseAPI {
6
+ constructor(opts) {
7
+ super(opts);
8
+ Object.setPrototypeOf(this, CommercetoolsOrderAPI.prototype);
9
+ }
10
+ async find(queryPredicate) {
11
+ return this.executeCall(this.client
12
+ .orders()
13
+ .get({ queryArgs: { where: queryPredicate } })
14
+ .execute());
15
+ }
16
+ }
17
+ exports.CommercetoolsOrderAPI = CommercetoolsOrderAPI;
@@ -1,10 +1,11 @@
1
1
  import { ContextProvider, RequestContextData } from '../../api';
2
- import { CartAPI, CommercetoolsAPI, CommercetoolsClient, PaymentAPI } from '../types/api.type';
2
+ import { CartAPI, CommercetoolsAPI, CommercetoolsClient, OrderAPI, PaymentAPI } from '../types/api.type';
3
3
  import { Logger } from '../..';
4
4
  export declare class DefaultCommercetoolsAPI implements CommercetoolsAPI {
5
5
  client: CommercetoolsClient;
6
6
  cart: CartAPI;
7
7
  payment: PaymentAPI;
8
+ order: OrderAPI;
8
9
  private logger;
9
10
  constructor(opts: {
10
11
  clientId: string;
@@ -5,15 +5,18 @@ const platform_sdk_1 = require("@commercetools/platform-sdk");
5
5
  const sdk_client_v2_1 = require("@commercetools/sdk-client-v2");
6
6
  const cart_api_1 = require("./cart-api");
7
7
  const payment_api_1 = require("./payment-api");
8
+ const order_api_1 = require("./order-api");
8
9
  class DefaultCommercetoolsAPI {
9
10
  client;
10
11
  cart;
11
12
  payment;
13
+ order;
12
14
  logger;
13
15
  constructor(opts) {
14
16
  this.client = createClient(opts);
15
17
  this.cart = new cart_api_1.CommercetoolsCartAPI({ client: this.client });
16
18
  this.payment = new payment_api_1.CommercetoolsPaymentAPI({ client: this.client });
19
+ this.order = new order_api_1.CommercetoolsOrderAPI({ client: this.client });
17
20
  this.logger = opts.logger;
18
21
  }
19
22
  }
@@ -2,4 +2,5 @@ export { CartService as CommercetoolsCartService } from './types/cart.type';
2
2
  export { PaymentService as CommercetoolsPaymentService, TransactionData, UpdatePayment } from './types/payment.type';
3
3
  export { SessionService as CommercetoolsSessionService, Session } from './types/session.type';
4
4
  export { AuthorizationService as CommercetoolsAuthorizationService } from './types/authorization.type';
5
- export { Cart, Payment, PaymentDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, } from '@commercetools/platform-sdk';
5
+ export { OrderService as CommercetoolsOrderService } from './types/order.type';
6
+ export { Cart, Order, OrderPagedQueryResponse, Payment, PaymentDraft, Money, LineItem, CustomLineItem, Address, Transaction, TransactionType, TransactionState, ShippingInfo, } from '@commercetools/platform-sdk';
@@ -1,4 +1,4 @@
1
- import { CartService, CartServiceOptions, GetCart, GetPaymentAmount } from '../types/cart.type';
1
+ import { CartService, CartServiceOptions, GetCart, GetCartByPaymentIdRequest, GetPaymentAmount } from '../types/cart.type';
2
2
  import { Cart } from '@commercetools/platform-sdk';
3
3
  import { PaymentAmount } from '../types/payment.type';
4
4
  import { AddPayment } from '../types/api.type';
@@ -9,6 +9,7 @@ export declare class DefaultCartService implements CartService {
9
9
  private ctAPI;
10
10
  private logger;
11
11
  constructor(opts: CartServiceOptions);
12
+ getCartByPaymentId(opts: GetCartByPaymentIdRequest): Promise<Cart>;
12
13
  getCart(opts: GetCart): Promise<Cart>;
13
14
  getPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
14
15
  addPayment(opts: AddPayment): Promise<Cart>;
@@ -13,6 +13,20 @@ class DefaultCartService {
13
13
  this.ctAPI = opts.ctAPI;
14
14
  this.logger = opts.logger;
15
15
  }
16
+ async getCartByPaymentId(opts) {
17
+ const queryPredicate = `paymentInfo(payments(id = "${opts.paymentId}"))`;
18
+ const result = await this.ctAPI.cart.find(queryPredicate);
19
+ if (result.count != 1) {
20
+ throw new __1.ErrorReferencedResourceNotFound('cart', queryPredicate, {
21
+ privateFields: {
22
+ queryPredicate,
23
+ paymentId: opts.paymentId,
24
+ },
25
+ privateMessage: 'Could not find a cart with the given paymentId',
26
+ });
27
+ }
28
+ return result.results[0];
29
+ }
16
30
  async getCart(opts) {
17
31
  return await this.ctAPI.cart.getCartById(opts.id);
18
32
  }
@@ -0,0 +1,11 @@
1
+ import { GetOrderByPaymentIdRequest, OrderService, OrderServiceOptions } from '../types/order.type';
2
+ import { Order } from '@commercetools/platform-sdk';
3
+ /**
4
+ * This is the default implementation of the OrderService interface.
5
+ */
6
+ export declare class DefaultOrderService implements OrderService {
7
+ private ctAPI;
8
+ private logger;
9
+ constructor(opts: OrderServiceOptions);
10
+ getOrderByPaymentId(opts: GetOrderByPaymentIdRequest): Promise<Order>;
11
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultOrderService = void 0;
4
+ const errorx_1 = require("../../errorx");
5
+ /**
6
+ * This is the default implementation of the OrderService interface.
7
+ */
8
+ class DefaultOrderService {
9
+ ctAPI;
10
+ logger;
11
+ constructor(opts) {
12
+ this.ctAPI = opts.ctAPI;
13
+ this.logger = opts.logger;
14
+ }
15
+ async getOrderByPaymentId(opts) {
16
+ const queryPredicate = `paymentInfo(payments(id = "${opts.paymentId}"))`;
17
+ const result = await this.ctAPI.order.find(queryPredicate);
18
+ if (result.count != 1) {
19
+ throw new errorx_1.ErrorReferencedResourceNotFound('order', queryPredicate, {
20
+ privateFields: {
21
+ queryPredicate,
22
+ paymentId: opts.paymentId,
23
+ },
24
+ privateMessage: 'Could not find a order with the given paymentId',
25
+ });
26
+ }
27
+ return result.results[0];
28
+ }
29
+ }
30
+ exports.DefaultOrderService = DefaultOrderService;
@@ -1,4 +1,4 @@
1
- import { Cart, Payment, PaymentDraft, PaymentPagedQueryResponse, PaymentUpdateAction } from '@commercetools/platform-sdk';
1
+ import { Cart, CartPagedQueryResponse, OrderPagedQueryResponse, Payment, PaymentDraft, PaymentPagedQueryResponse, PaymentUpdateAction } 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;
@@ -29,6 +29,7 @@ export interface AuthorizationAPI {
29
29
  }
30
30
  export interface CartAPI {
31
31
  getCartById(id: string): Promise<Cart>;
32
+ find(queryPredicate: string): Promise<CartPagedQueryResponse>;
32
33
  addPayment(opts: AddPayment): Promise<Cart>;
33
34
  }
34
35
  export interface PaymentAPI {
@@ -37,7 +38,11 @@ export interface PaymentAPI {
37
38
  createPayment(paymentDraft: PaymentDraft): Promise<Payment>;
38
39
  updatePayment(opts: UpdatePayment): Promise<Payment>;
39
40
  }
41
+ export interface OrderAPI {
42
+ find(queryPredicate: string): Promise<OrderPagedQueryResponse>;
43
+ }
40
44
  export interface CommercetoolsAPI {
41
45
  cart: CartAPI;
42
46
  payment: PaymentAPI;
47
+ order: OrderAPI;
43
48
  }
@@ -13,10 +13,14 @@ export type CartServiceOptions = {
13
13
  ctAPI: CommercetoolsAPI;
14
14
  logger: Logger;
15
15
  };
16
+ export type GetCartByPaymentIdRequest = {
17
+ paymentId: string;
18
+ };
16
19
  /**
17
20
  * Cart service interface exposes methods to interact with the commercetools platform API.
18
21
  */
19
22
  export interface CartService {
23
+ getCartByPaymentId(opts: GetCartByPaymentIdRequest): Promise<Cart>;
20
24
  getCart(opts: GetCart): Promise<Cart>;
21
25
  getPaymentAmount(opts: GetPaymentAmount): Promise<PaymentAmount>;
22
26
  addPayment(opts: AddPayment): Promise<Cart>;
@@ -0,0 +1,16 @@
1
+ import { Order } from '@commercetools/platform-sdk';
2
+ import { CommercetoolsAPI } from './api.type';
3
+ import { Logger } from '../../logger';
4
+ export type OrderServiceOptions = {
5
+ ctAPI: CommercetoolsAPI;
6
+ logger: Logger;
7
+ };
8
+ export type GetOrderByPaymentIdRequest = {
9
+ paymentId: string;
10
+ };
11
+ /**
12
+ * Order service interface exposes methods to interact with the commercetools platform API.
13
+ */
14
+ export interface OrderService {
15
+ getOrderByPaymentId(opts: GetOrderByPaymentIdRequest): Promise<Order>;
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -118,7 +118,7 @@ export declare class ErrorReferenceExists extends Errorx {
118
118
  * Returned when a resource referenced by a Reference or a ResourceIdentifier could not be found.
119
119
  */
120
120
  export declare class ErrorReferencedResourceNotFound extends Errorx {
121
- constructor(typeId: string, id?: string, key?: string, additionalOpts?: ErrorxAdditionalOpts);
121
+ constructor(typeId: string, predicate: string, additionalOpts?: ErrorxAdditionalOpts);
122
122
  }
123
123
  /**
124
124
  * ReferencedResourceNotFound (https://docs.commercetools.com/api/errors#referencedresourcenotfound)
@@ -233,16 +233,15 @@ exports.ErrorReferenceExists = ErrorReferenceExists;
233
233
  * Returned when a resource referenced by a Reference or a ResourceIdentifier could not be found.
234
234
  */
235
235
  class ErrorReferencedResourceNotFound extends Errorx {
236
- constructor(typeId, id, key, additionalOpts) {
236
+ constructor(typeId, predicate, additionalOpts) {
237
237
  const { fields, ...rest } = additionalOpts || {};
238
238
  super({
239
239
  code: 'ReferencedResourceNotFound',
240
240
  httpErrorStatus: 400,
241
- message: `The referenced object of type ${typeId} ${id || key} was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
241
+ message: `The referenced object of type '${typeId}' '${predicate}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
242
242
  fields: {
243
243
  ...fields,
244
- id,
245
- key,
244
+ predicate,
246
245
  typeId,
247
246
  },
248
247
  ...rest,
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { JWTAuthenticationHook, Oauth2AuthenticationHook, RequestContextData, Re
2
2
  import { DefaultCommercetoolsAPI } from './commercetools/api/root-api';
3
3
  import { DefaultAuthorizationService } from './commercetools/services/ct-authorization.service';
4
4
  import { DefaultCartService } from './commercetools/services/ct-cart.service';
5
+ import { DefaultOrderService } from './commercetools/services/ct-order.service';
5
6
  import { DefaultPaymentService } from './commercetools/services/ct-payment.service';
6
7
  import { Logger } from './logger';
7
8
  export * from './api';
@@ -24,6 +25,7 @@ export declare const setupPaymentSDK: (opts: {
24
25
  }) => {
25
26
  ctAPI: DefaultCommercetoolsAPI;
26
27
  ctCartService: DefaultCartService;
28
+ ctOrderService: DefaultOrderService;
27
29
  ctPaymentService: DefaultPaymentService;
28
30
  ctAuthorizationService: DefaultAuthorizationService;
29
31
  contextProvider: RequestContextProvider;
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ const api_1 = require("./api");
19
19
  const root_api_1 = require("./commercetools/api/root-api");
20
20
  const ct_authorization_service_1 = require("./commercetools/services/ct-authorization.service");
21
21
  const ct_cart_service_1 = require("./commercetools/services/ct-cart.service");
22
+ const ct_order_service_1 = require("./commercetools/services/ct-order.service");
22
23
  const ct_payment_service_1 = require("./commercetools/services/ct-payment.service");
23
24
  const ct_session_service_1 = require("./commercetools/services/ct-session.service");
24
25
  const base_decorator_1 = require("./fetch/decorators/base.decorator");
@@ -48,6 +49,7 @@ const setupPaymentSDK = (opts) => {
48
49
  logger,
49
50
  });
50
51
  const ctCartService = new ct_cart_service_1.DefaultCartService({ ctAPI, logger });
52
+ const ctOrderService = new ct_order_service_1.DefaultOrderService({ ctAPI, logger });
51
53
  const ctPaymentService = new ct_payment_service_1.DefaultPaymentService({ ctAPI, logger });
52
54
  const ctAuthorizationService = new ct_authorization_service_1.DefaultAuthorizationService({
53
55
  authUrl: opts.authUrl,
@@ -128,6 +130,7 @@ const setupPaymentSDK = (opts) => {
128
130
  return {
129
131
  ctAPI,
130
132
  ctCartService,
133
+ ctOrderService,
131
134
  ctPaymentService,
132
135
  ctAuthorizationService,
133
136
  contextProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/connect-payments-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.8.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": "22.27.0",
19
- "@commercetools/platform-sdk": "7.8.0",
19
+ "@commercetools/platform-sdk": "7.9.0",
20
20
  "@commercetools/sdk-client-v2": "2.5.0",
21
21
  "jsonwebtoken": "9.0.2",
22
22
  "jwks-rsa": "3.1.0",