@@ -12,8 +12,9 @@ const moment = require('moment')
1212const helper = require ( '../common/helper' )
1313const logger = require ( '../common/logger' )
1414const errors = require ( '../common/errors' )
15+ const constants = require ( '../../app-constants' )
1516const models = require ( '../models' )
16- const { createPayment } = require ( './PaymentService' )
17+ const PaymentService = require ( './PaymentService' )
1718
1819const WorkPeriodPayment = models . WorkPeriodPayment
1920const esClient = helper . getESClient ( )
@@ -89,20 +90,21 @@ getWorkPeriodPayment.schema = Joi.object().keys({
8990 * Create workPeriodPayment
9091 * @param {Object } currentUser the user who perform this operation
9192 * @param {Object } workPeriodPayment the workPeriodPayment to be created
93+ * @param {Object } options the extra options to control the function
9294 * @returns {Object } the created workPeriodPayment
9395 */
94- async function createWorkPeriodPayment ( currentUser , workPeriodPayment ) {
96+ async function createWorkPeriodPayment ( currentUser , workPeriodPayment , options = { paymentProcessingSwitch : 'OFF' } ) {
9597 // check permission
9698 await _checkUserPermissionForCRUWorkPeriodPayment ( currentUser )
9799
98100 const { projectId, userHandle, endDate } = await helper . ensureWorkPeriodById ( workPeriodPayment . workPeriodId ) // ensure work period exists
99- const paymentChallenge = await createPayment ( {
101+ const paymentChallenge = options . paymentProcessingSwitch === constants . PaymentProcessingSwitch . ON ? ( await PaymentService . createPayment ( {
100102 projectId,
101103 userHandle,
102104 amount : workPeriodPayment . amount ,
103105 name : `TaaS Payment - ${ userHandle } - Week Ending ${ moment ( endDate ) . format ( 'D/M/YYYY' ) } ` ,
104106 description : `TaaS Payment - ${ userHandle } - Week Ending ${ moment ( endDate ) . format ( 'D/M/YYYY' ) } `
105- } )
107+ } ) ) : ( { id : '00000000-0000-0000-0000-000000000000' } )
106108 workPeriodPayment . id = uuid . v4 ( )
107109 workPeriodPayment . challengeId = paymentChallenge . id
108110 workPeriodPayment . createdBy = await helper . getUserId ( currentUser . userId )
@@ -128,7 +130,8 @@ createWorkPeriodPayment.schema = Joi.object().keys({
128130 workPeriodId : Joi . string ( ) . uuid ( ) . required ( ) ,
129131 amount : Joi . number ( ) . greater ( 0 ) . allow ( null ) ,
130132 status : Joi . workPeriodPaymentStatus ( ) . default ( 'completed' )
131- } ) . required ( )
133+ } ) . required ( ) ,
134+ options : Joi . object ( )
132135} ) . required ( )
133136
134137/**
0 commit comments