Skip to content

Commit

Permalink
Merge pull request #21 from commercetools/ddeliziact/operations
Browse files Browse the repository at this point in the history
fix(api): clean up operations router
  • Loading branch information
dasanorct authored Feb 26, 2024
2 parents f24055f + ca7e1cb commit 1c8be22
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 27 deletions.
1 change: 0 additions & 1 deletion processor/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const config = {
mockEnvironment: process.env.MOCK_ENVIRONMENT,

// Payment Providers config
returnUrl: process.env.RETURN_URL,
adyenEnvironment: process.env.ADYEN_ENVIRONMENT || '',
adyenClientKey: process.env.ADYEN_CLIENT_KEY || '',
adyenApiKey: process.env.ADYEN_API_KEY || '',
Expand Down
6 changes: 5 additions & 1 deletion processor/src/dtos/operations/config.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Static, Type } from '@sinclair/typebox';

export const ConfigResponseSchema = Type.Any();
export const ConfigResponseSchema = Type.Object({
clientKey: Type.String(),
environment: Type.String(),
returnUrl: Type.String(),
});

export type ConfigResponseSchemaDTO = Static<typeof ConfigResponseSchema>;
16 changes: 0 additions & 16 deletions processor/src/server/plugins/mock-payment.plugin.ts

This file was deleted.

4 changes: 2 additions & 2 deletions processor/src/server/plugins/operation.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { FastifyInstance } from 'fastify';
import { paymentSDK } from '../../payment-sdk';
import { operationsRoute } from '../../routes/operation.route';
import { DefaultOperationService } from '../../services/operation.service';
import { MockOperationProcessor } from '../../services/processors/mock-operation.processor';
import { AdyenOperationProcessor } from '../../services/processors/adyen-operation.processor';

export default async function (server: FastifyInstance) {
const paymentProcessor = new MockOperationProcessor();
const paymentProcessor = new AdyenOperationProcessor();

const operationService = new DefaultOperationService({
ctCartService: paymentSDK.ctCartService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AdyenAPI } from '../../clients/adyen/adyen.client';
import { config } from '../../config/config';
import { PaymentModificationStatus } from '../../dtos/operations/payment-intents.dto';
import { paymentSDK } from '../../payment-sdk';
import { OperationProcessor } from './operation.processor';
import {
CancelPaymentRequest,
CapturePaymentRequest,
Expand All @@ -12,14 +11,15 @@ import {
RefundPaymentRequest,
StatusResponse,
} from '../types/operation.type';
const packageJSON = require('../../package.json');
import { OperationProcessor } from './operation.processor';
const packageJSON = require('../../../package.json');

export class AdyenOperationProcessor implements OperationProcessor {
async config(): Promise<ConfigResponse> {
return {
clientKey: config.adyenClientKey,
environment: config.adyenEnvironment,
returnUrl: config.returnUrl,
returnUrl: config.adyenReturnUrl,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class MockOperationProcessor implements OperationProcessor {
return {
clientKey: config.mockClientKey,
environment: config.mockEnvironment,
};
} as unknown as ConfigResponse;
}

async status(): Promise<StatusResponse> {
Expand Down
4 changes: 1 addition & 3 deletions processor/src/services/types/operation.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export type PaymentProviderModificationResponse = {
pspReference: string;
};

export type ConfigResponse = {
[key: string]: any;
};
export type ConfigResponse = ConfigResponseSchemaDTO;

export type StatusResponse = StatusResponseSchemaDTO;

Expand Down

0 comments on commit 1c8be22

Please sign in to comment.