From 33c04478cccd2aa8a7703a73289c9cfd60747bb3 Mon Sep 17 00:00:00 2001 From: Johnson Ogwuru Date: Tue, 5 Mar 2024 13:28:14 +0100 Subject: [PATCH] chore(processor): update repo from upstream (#41) * Write unit test for getStatus * Add unit test cases and sinon dependency for stub purpose * Update operation.service.spec.ts * Bump msw from 2.2.0 to 2.2.1 in /processor Bumps [msw](https://github.com/mswjs/msw) from 2.2.0 to 2.2.1. - [Release notes](https://github.com/mswjs/msw/releases) - [Changelog](https://github.com/mswjs/msw/blob/main/CHANGELOG.md) - [Commits](https://github.com/mswjs/msw/compare/v2.2.0...v2.2.1) --- updated-dependencies: - dependency-name: msw dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump eslint-plugin-jest from 27.8.0 to 27.9.0 in /processor Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 27.8.0 to 27.9.0. - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v27.8.0...v27.9.0) --- updated-dependencies: - dependency-name: eslint-plugin-jest dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * fix(connector): config type and details field (#49) * Add unit test for cancel payment * Refactor the mock data * Remove skipped unit test * Update operation.route.ts * Avoid using sinon * Bump dotenv from 16.4.4 to 16.4.5 in /processor Bumps [dotenv](https://github.com/motdotla/dotenv) from 16.4.4 to 16.4.5. - [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md) - [Commits](https://github.com/motdotla/dotenv/compare/v16.4.4...v16.4.5) --- updated-dependencies: - dependency-name: dotenv dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump @typescript-eslint/parser from 7.0.1 to 7.0.2 in /processor Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 7.0.1 to 7.0.2. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.0.2/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump sass from 1.71.0 to 1.71.1 in /enabler Bumps [sass](https://github.com/sass/dart-sass) from 1.71.0 to 1.71.1. - [Release notes](https://github.com/sass/dart-sass/releases) - [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md) - [Commits](https://github.com/sass/dart-sass/compare/1.71.0...1.71.1) --- updated-dependencies: - dependency-name: sass dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump vite from 5.1.3 to 5.1.4 in /enabler Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 5.1.3 to 5.1.4. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v5.1.4/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump @commercetools-backend/loggers in /processor Bumps [@commercetools-backend/loggers](https://github.com/commercetools/merchant-center-application-kit/tree/HEAD/packages-backend/loggers) from 22.17.2 to 22.18.0. - [Release notes](https://github.com/commercetools/merchant-center-application-kit/releases) - [Changelog](https://github.com/commercetools/merchant-center-application-kit/blob/main/packages-backend/loggers/CHANGELOG.md) - [Commits](https://github.com/commercetools/merchant-center-application-kit/commits/@commercetools-backend/loggers@22.18.0/packages-backend/loggers) --- updated-dependencies: - dependency-name: "@commercetools-backend/loggers" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump nodemon from 3.0.3 to 3.1.0 in /processor Bumps [nodemon](https://github.com/remy/nodemon) from 3.0.3 to 3.1.0. - [Release notes](https://github.com/remy/nodemon/releases) - [Commits](https://github.com/remy/nodemon/compare/v3.0.3...v3.1.0) --- updated-dependencies: - dependency-name: nodemon dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump @types/node from 20.11.19 to 20.11.20 in /processor Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.11.19 to 20.11.20. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump @types/node from 20.11.19 to 20.11.20 in /enabler Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.11.19 to 20.11.20. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump eslint from 8.56.0 to 8.57.0 in /processor Bumps [eslint](https://github.com/eslint/eslint) from 8.56.0 to 8.57.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v8.56.0...v8.57.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump @commercetools/connect-payments-sdk in /processor Bumps @commercetools/connect-payments-sdk from 0.1.0 to 0.2.0. --- updated-dependencies: - dependency-name: "@commercetools/connect-payments-sdk" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump @typescript-eslint/eslint-plugin from 7.0.1 to 7.1.0 in /processor Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 7.0.1 to 7.1.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.1.0/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump @typescript-eslint/parser from 7.0.2 to 7.1.0 in /processor Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 7.0.2 to 7.1.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.1.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump @commercetools/platform-sdk from 7.3.0 to 7.4.0 in /processor Bumps [@commercetools/platform-sdk](https://github.com/commercetools/commercetools-typescript-sdks) from 7.3.0 to 7.4.0. - [Release notes](https://github.com/commercetools/commercetools-typescript-sdks/releases) - [Changelog](https://github.com/commercetools/commercetools-sdk-typescript/blob/master/changes.md) - [Commits](https://github.com/commercetools/commercetools-typescript-sdks/compare/@commercetools/platform-sdk@7.3.0...@commercetools/platform-sdk@7.4.0) --- updated-dependencies: - dependency-name: "@commercetools/platform-sdk" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Modify the configurations of required environment variables * Update ci.yml * Update ci.yml * Update connect.yaml * Remove unnecessary environment variable from CI/CD pipeline * fix(enabler): SessionId example usage * Bump msw from 2.2.1 to 2.2.2 in /processor Bumps [msw](https://github.com/mswjs/msw) from 2.2.1 to 2.2.2. - [Release notes](https://github.com/mswjs/msw/releases) - [Changelog](https://github.com/mswjs/msw/blob/main/CHANGELOG.md) - [Commits](https://github.com/mswjs/msw/compare/v2.2.1...v2.2.2) --- updated-dependencies: - dependency-name: msw dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Refactor abstract payment service * Fix build failure * Bump @commercetools-backend/loggers in /processor Bumps [@commercetools-backend/loggers](https://github.com/commercetools/merchant-center-application-kit/tree/HEAD/packages-backend/loggers) from 22.18.0 to 22.19.0. - [Release notes](https://github.com/commercetools/merchant-center-application-kit/releases) - [Changelog](https://github.com/commercetools/merchant-center-application-kit/blob/main/packages-backend/loggers/CHANGELOG.md) - [Commits](https://github.com/commercetools/merchant-center-application-kit/commits/@commercetools-backend/loggers@22.19.0/packages-backend/loggers) --- updated-dependencies: - dependency-name: "@commercetools-backend/loggers" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump @types/node from 20.11.20 to 20.11.24 in /processor Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.11.20 to 20.11.24. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump @types/node from 20.11.20 to 20.11.24 in /enabler Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.11.20 to 20.11.24. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Fix unit test * Update abstract-payment.service.ts * Add function document to mock-payment service * Bump @sinclair/typebox from 0.32.14 to 0.32.15 in /processor Bumps [@sinclair/typebox](https://github.com/sinclairzx81/typebox) from 0.32.14 to 0.32.15. - [Commits](https://github.com/sinclairzx81/typebox/compare/0.32.14...0.32.15) --- updated-dependencies: - dependency-name: "@sinclair/typebox" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Update typescript doc * feat(payments): set the payment interface from the context * chore(paypal-connector): rename instances of mock to paypal (#5) * chore(paypal-connector): implement config endpoint * feat(connector): implement status endpoint (#12) * feat(connector): payment intents (#18) * feat(connector): payment intents * wip: save point * wip: save point * wip: save point * wip: save point * wip: save point * wip: save point * wip: save point * pr feedback * remove nock * wip: save changes * graceful error handling * chore(deps-dev): bump @typescript-eslint/parser in /processor (#27) Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 7.0.2 to 7.1.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.1.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @typescript-eslint/eslint-plugin in /processor (#25) Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 7.0.2 to 7.1.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.1.0/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Merge changes from upstream (#28) * Write unit test for getStatus * Add unit test cases and sinon dependency for stub purpose * Update operation.service.spec.ts * Add unit test for cancel payment * Refactor the mock data * Remove skipped unit test * Update operation.route.ts * Avoid using sinon * fix(connector): config type and details field (#49) * Bump dotenv from 16.4.4 to 16.4.5 in /processor Bumps [dotenv](https://github.com/motdotla/dotenv) from 16.4.4 to 16.4.5. - [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md) - [Commits](https://github.com/motdotla/dotenv/compare/v16.4.4...v16.4.5) --- updated-dependencies: - dependency-name: dotenv dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Modify the configurations of required environment variables * Update ci.yml * Update ci.yml * Update connect.yaml * Remove unnecessary environment variable from CI/CD pipeline * Bump @typescript-eslint/parser from 7.0.2 to 7.1.0 in /processor Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 7.0.2 to 7.1.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.1.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump @commercetools/platform-sdk from 7.3.0 to 7.4.0 in /processor Bumps [@commercetools/platform-sdk](https://github.com/commercetools/commercetools-typescript-sdks) from 7.3.0 to 7.4.0. - [Release notes](https://github.com/commercetools/commercetools-typescript-sdks/releases) - [Changelog](https://github.com/commercetools/commercetools-sdk-typescript/blob/master/changes.md) - [Commits](https://github.com/commercetools/commercetools-typescript-sdks/compare/@commercetools/platform-sdk@7.3.0...@commercetools/platform-sdk@7.4.0) --- updated-dependencies: - dependency-name: "@commercetools/platform-sdk" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * feat(connector): payment intents (#18) * feat(connector): payment intents * wip: save point * wip: save point * wip: save point * wip: save point * wip: save point * wip: save point * wip: save point * pr feedback * remove nock * wip: save changes * graceful error handling * update healthcheck method * fix tests --------- Signed-off-by: dependabot[bot] Co-authored-by: King-Hin Leung Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump @commercetools-backend/loggers in /processor (#34) Bumps [@commercetools-backend/loggers](https://github.com/commercetools/merchant-center-application-kit/tree/HEAD/packages-backend/loggers) from 22.18.0 to 22.19.0. - [Release notes](https://github.com/commercetools/merchant-center-application-kit/releases) - [Changelog](https://github.com/commercetools/merchant-center-application-kit/blob/main/packages-backend/loggers/CHANGELOG.md) - [Commits](https://github.com/commercetools/merchant-center-application-kit/commits/@commercetools-backend/loggers@22.19.0/packages-backend/loggers) --- updated-dependencies: - dependency-name: "@commercetools-backend/loggers" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(template): refactor operations to be included in abstract class (#35) * feat(connectors): Implement notification endpoint (#38) * feat(connectors): Implement notification endpoint * fix notification schema * fix notification schema 2 * improve error thrown * update errors and test * pr feedback * chore(deps): bump fastify from 4.26.1 to 4.26.2 in /processor (#40) Bumps [fastify](https://github.com/fastify/fastify) from 4.26.1 to 4.26.2. - [Release notes](https://github.com/fastify/fastify/releases) - [Commits](https://github.com/fastify/fastify/compare/v4.26.1...v4.26.2) --- updated-dependencies: - dependency-name: fastify dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix failing test * tiny fixes --------- Signed-off-by: dependabot[bot] Co-authored-by: King-Hin Leung Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: King-Hin Leung <35692276+leungkinghin@users.noreply.github.com> Co-authored-by: Juan J. Campos Co-authored-by: david sanchez ortiz <100843283+dasanorct@users.noreply.github.com> Co-authored-by: dasanor --- .../src/services/abstract-payment.service.ts | 1 + .../src/services/paypal-payment.service.ts | 84 +++++++++++++++---- .../src/services/types/paypal-payment.type.ts | 6 ++ ...spec.ts => paypal-payment.service.spec.ts} | 14 ++-- 4 files changed, 85 insertions(+), 20 deletions(-) rename processor/test/{operation.service.spec.ts => paypal-payment.service.spec.ts} (91%) diff --git a/processor/src/services/abstract-payment.service.ts b/processor/src/services/abstract-payment.service.ts index b0eab2c..470bdd7 100644 --- a/processor/src/services/abstract-payment.service.ts +++ b/processor/src/services/abstract-payment.service.ts @@ -18,6 +18,7 @@ import { PaymentIntentResponseSchemaDTO, PaymentModificationStatus, } from '../dtos/operations/payment-intents.dto'; + import { Payment } from '@commercetools/platform-sdk'; import { SupportedPaymentComponentsSchemaDTO } from '../dtos/operations/payment-componets.dto'; diff --git a/processor/src/services/paypal-payment.service.ts b/processor/src/services/paypal-payment.service.ts index d3503ce..3887838 100644 --- a/processor/src/services/paypal-payment.service.ts +++ b/processor/src/services/paypal-payment.service.ts @@ -1,10 +1,4 @@ -import { - CommercetoolsCartService, - CommercetoolsPaymentService, - ErrorGeneral, - healthCheckCommercetoolsPermissions, - statusHandler, -} from '@commercetools/connect-payments-sdk'; +import { ErrorGeneral, healthCheckCommercetoolsPermissions, statusHandler } from '@commercetools/connect-payments-sdk'; import { CreateOrderRequestDTO, CreateOrderResponseDTO, @@ -12,13 +6,18 @@ import { NotificationPayloadDTO, } from '../dtos/paypal-payment.dto'; -import { getCartIdFromContext } from '../libs/fastify/context/context'; +import { getCartIdFromContext, getPaymentInterfaceFromContext } from '../libs/fastify/context/context'; import { PaypalAPI } from '../clients/paypal.client'; import { Address, Cart, Money, Payment } from '@commercetools/platform-sdk'; import { CreateOrderRequest, PaypalShipping, parseAmount } from '../clients/types/paypal.client.type'; import { PaymentModificationStatus } from '../dtos/operations/payment-intents.dto'; import { randomUUID } from 'crypto'; -import { TransactionStates, OrderConfirmation, PaymentOutcome } from './types/paypal-payment.type'; +import { + TransactionStates, + OrderConfirmation, + PaymentOutcome, + PaypalPaymentServiceOptions, +} from './types/paypal-payment.type'; import { getConfig } from '../config/config'; import { CancelPaymentRequest, @@ -34,11 +33,6 @@ import { AbstractPaymentService } from './abstract-payment.service'; import { NotificationConverter } from './converters/notification.converter'; const packageJSON = require('../../package.json'); -export type PaypalPaymentServiceOptions = { - ctCartService: CommercetoolsCartService; - ctPaymentService: CommercetoolsPaymentService; -}; - export class PaypalPaymentService extends AbstractPaymentService { private paypalClient: PaypalAPI; private notificationConverter: NotificationConverter; @@ -49,6 +43,14 @@ export class PaypalPaymentService extends AbstractPaymentService { this.notificationConverter = new NotificationConverter(); } + /** + * Get configurations + * + * @remarks + * Implementation to provide mocking configuration information + * + * @returns Promise with mocking object containing configuration information + */ async config(): Promise { return { clientId: getConfig().paypalClientId, @@ -56,6 +58,14 @@ export class PaypalPaymentService extends AbstractPaymentService { }; } + /** + * Get status + * + * @remarks + * Implementation to provide mocking status of external systems + * + * @returns Promise with mocking data containing a list of status from different external systems + */ async status(): Promise { const handler = await statusHandler({ timeout: getConfig().healthCheckTimeout, @@ -102,6 +112,14 @@ export class PaypalPaymentService extends AbstractPaymentService { return handler.body; } + /** + * Get supported payment components + * + * @remarks + * Implementation to provide the mocking payment components supported by the processor. + * + * @returns Promise with mocking data containing a list of supported payment components + */ public async getSupportedPaymentComponents(): Promise { return { components: [ @@ -112,6 +130,15 @@ export class PaypalPaymentService extends AbstractPaymentService { }; } + /** + * Create payment + * + * @remarks + * Implementation to provide the mocking data for payment creation in external PSPs + * + * @param request - contains amount and {@link https://docs.commercetools.com/api/projects/payments | Payment } defined in composable commerce + * @returns Promise with mocking data containing order id and PSP reference + */ public async createPayment(data: CreateOrderRequestDTO): Promise { const ctCart = await this.ctCartService.getCart({ id: getCartIdFromContext(), @@ -123,7 +150,7 @@ export class PaypalPaymentService extends AbstractPaymentService { const ctPayment = await this.ctPaymentService.createPayment({ amountPlanned, paymentMethodInfo: { - paymentInterface: 'paypal', + paymentInterface: getPaymentInterfaceFromContext() || 'paypal', }, ...(ctCart.customerId && { customer: { @@ -225,10 +252,28 @@ export class PaypalPaymentService extends AbstractPaymentService { await this.ctPaymentService.updatePayment(updateData); } + /** + * Capture payment + * + * @remarks + * Implementation to provide the mocking data for payment capture in external PSPs + * + * @param request - contains the amount and {@link https://docs.commercetools.com/api/projects/payments | Payment } defined in composable commerce + * @returns Promise with mocking data containing operation status and PSP reference + */ async capturePayment(request: CapturePaymentRequest): Promise { return await this.paypalClient.captureOrder(request.payment.interfaceId); } + /** + * Cancel payment + * + * @remarks + * Implementation to provide the mocking data for payment cancel in external PSPs + * + * @param request - contains {@link https://docs.commercetools.com/api/projects/payments | Payment } defined in composable commerce + * @returns Promise with mocking data containing operation status and PSP reference + */ async cancelPayment(request: CancelPaymentRequest): Promise { throw new ErrorGeneral('operation not supported', { fields: { @@ -238,6 +283,15 @@ export class PaypalPaymentService extends AbstractPaymentService { }); } + /** + * Refund payment + * + * @remarks + * Implementation to provide the mocking data for payment refund in external PSPs + * + * @param request - contains amount and {@link https://docs.commercetools.com/api/projects/payments | Payment } defined in composable commerce + * @returns Promise with mocking data containing operation status and PSP reference + */ async refundPayment(request: RefundPaymentRequest): Promise { const transaction = request.payment.transactions.find((t) => t.type === 'Charge' && t.state === 'Success'); const captureId = transaction?.interactionId; diff --git a/processor/src/services/types/paypal-payment.type.ts b/processor/src/services/types/paypal-payment.type.ts index 16b189d..6e0ac04 100644 --- a/processor/src/services/types/paypal-payment.type.ts +++ b/processor/src/services/types/paypal-payment.type.ts @@ -1,3 +1,4 @@ +import { CommercetoolsCartService, CommercetoolsPaymentService } from '@commercetools/connect-payments-sdk'; import { CaptureOrderRequestDTO } from '../../dtos/paypal-payment.dto'; export type OrderConfirmation = { @@ -9,6 +10,11 @@ export enum PaymentOutcome { REJECTED = 'Rejected', } +export type PaypalPaymentServiceOptions = { + ctCartService: CommercetoolsCartService; + ctPaymentService: CommercetoolsPaymentService; +}; + export enum TransactionStates { SUCCESS = 'Success', FAILURE = 'Failure', diff --git a/processor/test/operation.service.spec.ts b/processor/test/paypal-payment.service.spec.ts similarity index 91% rename from processor/test/operation.service.spec.ts rename to processor/test/paypal-payment.service.spec.ts index cb585be..ba54e25 100644 --- a/processor/test/operation.service.spec.ts +++ b/processor/test/paypal-payment.service.spec.ts @@ -1,14 +1,17 @@ import { describe, test, expect, afterEach, jest, afterAll, beforeAll, beforeEach } from '@jest/globals'; import { ConfigResponse, ModifyPayment } from '../src/services/types/operation.type'; -import { PaypalPaymentService } from '../src/services/paypal-payment.service'; + import { paymentSDK } from '../src/payment-sdk'; import { DefaultPaymentService } from '@commercetools/connect-payments-sdk/dist/commercetools/services/ct-payment.service'; import { mockGetPaymentResult, mockUpdatePaymentResult } from './utils/mock-payment-data'; import * as Config from '../src/config/config'; +import { PaypalPaymentServiceOptions } from '../src/services/types/paypal-payment.type'; +import { AbstractPaymentService } from '../src/services/abstract-payment.service'; +import { PaypalPaymentService } from '../src/services/paypal-payment.service'; import { setupServer } from 'msw/node'; +import { PaypalUrls, PaypalBasePath } from '../src/clients/types/paypal.client.type'; import { paypalAuthenticationResponse, paypalCaptureOrderOkResponse } from './utils/mock-paypal-response-data'; import { mockPaypalRequest } from './utils/paypal-request.mock'; -import { PaypalUrls, PaypalBasePath } from '../src/clients/types/paypal.client.type'; interface FlexibleConfig { [key: string]: string | number | undefined; // Adjust the type according to your config values @@ -23,12 +26,13 @@ function setupMockConfig(keysAndValues: Record) { jest.spyOn(Config, 'getConfig').mockReturnValue(mockConfig as any); } -describe('operation.service', () => { +describe('paypal-payment.service', () => { const mockServer = setupServer(); - const paymentService = new PaypalPaymentService({ + const opts: PaypalPaymentServiceOptions = { ctCartService: paymentSDK.ctCartService, ctPaymentService: paymentSDK.ctPaymentService, - }); + }; + const paymentService: AbstractPaymentService = new PaypalPaymentService(opts); beforeAll(() => { mockServer.listen({