Skip to content

Commit 7b53ffd

Browse files
MOL-357/PICT-241: add endpoint for post-deploy and undeploy
1 parent 35f40a5 commit 7b53ffd

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

processor/src/controllers/processor.controller.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import CustomError from '../errors/custom.error';
88
import SkipError from '../errors/skip.error';
99
import { apiError } from '../api/error.api';
1010
import { formatErrorResponse } from '../errors/mollie.error';
11+
import { createPaymentExtension, deletePaymentExtension } from '../commercetools/extensions.commercetools';
12+
import {
13+
createCustomPaymentInterfaceInteractionType,
14+
createCustomPaymentTransactionCancelReasonType,
15+
createCustomPaymentType,
16+
} from '../commercetools/customFields.commercetools';
1117

1218
/**
1319
* Exposed service endpoint.
@@ -33,24 +39,64 @@ export const post = async (request: Request, response: Response) => {
3339
data = await paymentController(action, resource);
3440
logger.debug('SCTM - Processor - Finish processing payment requests');
3541
} else {
42+
logger.debug(`SCTM - Processor - Internal Server Error - Resource not recognized. Allowed values are 'payment'.`);
3643
throw new CustomError(500, `Internal Server Error - Resource not recognized. Allowed values are 'payment'.`);
3744
}
3845

3946
return apiSuccess(200, response, data?.actions);
4047
} catch (error) {
4148
if (error instanceof SkipError) {
42-
logger.debug('Skip action', error.message);
49+
logger.debug('SCTM - Processor - Skip action', error.message);
4350

4451
return apiSuccess(200, response, []);
4552
}
4653
if (error instanceof CustomError) {
47-
logger.debug('Error occurred when processing request', error);
54+
logger.debug('SCTM - Processor - Error occurred when processing request', error);
4855

4956
return apiError(response, error.errors);
5057
}
5158

52-
logger.debug('Unexpected error occurred when processing request', error);
59+
logger.debug('SCTM - Processor - Unexpected error occurred when processing request', error);
5360

5461
return apiError(response, formatErrorResponse(error).errors);
5562
}
5663
};
64+
65+
/**
66+
* Exposed service endpoint.
67+
* - Creates the Mollie payment extension, CustomPaymentType, CustomPaymentInterfaceInteractionType and CustomPaymentTransactionCancelReasonType.
68+
*
69+
* @param {Request} request The express request
70+
* @param {Response} response The express response
71+
* @returns
72+
*/
73+
export const installation = async (request: Request, response: Response) => {
74+
const { extensionUrl } = request.body;
75+
76+
if (!extensionUrl) {
77+
logger.debug('SCTM - installation - Missing body parameters {extensionUrl}.');
78+
return apiError(response, formatErrorResponse(new CustomError(400, 'Missing body parameters.')).errors);
79+
}
80+
81+
try {
82+
await createPaymentExtension(extensionUrl);
83+
await createCustomPaymentType();
84+
await createCustomPaymentInterfaceInteractionType();
85+
await createCustomPaymentTransactionCancelReasonType();
86+
logger.debug('SCTM - installation - Finish processing installation requests');
87+
return apiSuccess(200, response, []);
88+
} catch (error) {
89+
logger.debug('SCTM - installation - Unexpected error occurred when processing request', error);
90+
return apiError(response, formatErrorResponse(error).errors);
91+
}
92+
};
93+
94+
export const uninstallation = async (request: Request, response: Response) => {
95+
try {
96+
deletePaymentExtension();
97+
return apiSuccess(200, response, []);
98+
} catch (error) {
99+
logger.debug('SCTM - uninstallation - Unexpected error occurred when processing request', error);
100+
return apiError(response, formatErrorResponse(error).errors);
101+
}
102+
};

processor/src/routes/processor.route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Router } from 'express';
2-
import { post } from '../controllers/processor.controller';
2+
import { post, installation, uninstallation } from '../controllers/processor.controller';
33

44
const serviceRouter = Router();
55

@@ -9,4 +9,8 @@ serviceRouter.get('/health-check', async (req, res) => {
99

1010
serviceRouter.post('/', post);
1111

12+
serviceRouter.post('/install', installation);
13+
14+
serviceRouter.post('/uninstall', uninstallation);
15+
1216
export default serviceRouter;

0 commit comments

Comments
 (0)