Skip to content

Commit

Permalink
chore(processor): update repo from upstream (#41)
Browse files Browse the repository at this point in the history
* 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](mswjs/msw@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] <[email protected]>

* 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](jest-community/eslint-plugin-jest@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] <[email protected]>

* 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](motdotla/dotenv@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] <[email protected]>

* 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] <[email protected]>

* 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](sass/dart-sass@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] <[email protected]>

* 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] <[email protected]>

* 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/[email protected]/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] <[email protected]>

* 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](remy/nodemon@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] <[email protected]>

* 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] <[email protected]>

* 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] <[email protected]>

* 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](eslint/eslint@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] <[email protected]>

* 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] <[email protected]>

* 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] <[email protected]>

* 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] <[email protected]>

* 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/[email protected]...@commercetools/[email protected])

---
updated-dependencies:
- dependency-name: "@commercetools/platform-sdk"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* 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](mswjs/msw@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] <[email protected]>

* 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/[email protected]/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] <[email protected]>

* 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] <[email protected]>

* 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] <[email protected]>

* 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](sinclairzx81/typebox@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] <[email protected]>

* 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] <[email protected]>
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] <[email protected]>
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](motdotla/dotenv@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] <[email protected]>

* 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] <[email protected]>

* 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/[email protected]...@commercetools/[email protected])

---
updated-dependencies:
- dependency-name: "@commercetools/platform-sdk"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* 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] <[email protected]>
Co-authored-by: King-Hin Leung <[email protected]>
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/[email protected]/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] <[email protected]>
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](fastify/fastify@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] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix failing test

* tiny fixes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: King-Hin Leung <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: King-Hin Leung <[email protected]>
Co-authored-by: Juan J. Campos <[email protected]>
Co-authored-by: david sanchez ortiz <[email protected]>
Co-authored-by: dasanor <[email protected]>
  • Loading branch information
7 people committed Mar 14, 2024
1 parent 0b6e7c4 commit 33c0447
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
1 change: 1 addition & 0 deletions processor/src/services/abstract-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
84 changes: 69 additions & 15 deletions processor/src/services/paypal-payment.service.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {
CommercetoolsCartService,
CommercetoolsPaymentService,
ErrorGeneral,
healthCheckCommercetoolsPermissions,
statusHandler,
} from '@commercetools/connect-payments-sdk';
import { ErrorGeneral, healthCheckCommercetoolsPermissions, statusHandler } from '@commercetools/connect-payments-sdk';
import {
CreateOrderRequestDTO,
CreateOrderResponseDTO,
CaptureOrderResponseDTO,
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,
Expand All @@ -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;
Expand All @@ -49,13 +43,29 @@ 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<ConfigResponse> {
return {
clientId: getConfig().paypalClientId,
environment: getConfig().paypalEnvironment,
};
}

/**
* 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<StatusResponse> {
const handler = await statusHandler({
timeout: getConfig().healthCheckTimeout,
Expand Down Expand Up @@ -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<SupportedPaymentComponentsSchemaDTO> {
return {
components: [
Expand All @@ -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<CreateOrderResponseDTO> {
const ctCart = await this.ctCartService.getCart({
id: getCartIdFromContext(),
Expand All @@ -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: {
Expand Down Expand Up @@ -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<PaymentProviderModificationResponse> {
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<PaymentProviderModificationResponse> {
throw new ErrorGeneral('operation not supported', {
fields: {
Expand All @@ -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<PaymentProviderModificationResponse> {
const transaction = request.payment.transactions.find((t) => t.type === 'Charge' && t.state === 'Success');
const captureId = transaction?.interactionId;
Expand Down
6 changes: 6 additions & 0 deletions processor/src/services/types/paypal-payment.type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CommercetoolsCartService, CommercetoolsPaymentService } from '@commercetools/connect-payments-sdk';
import { CaptureOrderRequestDTO } from '../../dtos/paypal-payment.dto';

export type OrderConfirmation = {
Expand All @@ -9,6 +10,11 @@ export enum PaymentOutcome {
REJECTED = 'Rejected',
}

export type PaypalPaymentServiceOptions = {
ctCartService: CommercetoolsCartService;
ctPaymentService: CommercetoolsPaymentService;
};

export enum TransactionStates {
SUCCESS = 'Success',
FAILURE = 'Failure',
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,12 +26,13 @@ function setupMockConfig(keysAndValues: Record<string, string>) {
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({
Expand Down

0 comments on commit 33c0447

Please sign in to comment.