update payment satus and payment mode of booking

master^2
Varun 3 weeks ago
parent d588dee0a2
commit d554f81af0

@ -1887,3 +1887,53 @@ exports.estimationsget = async (req, reply) => {
throw boom.boomify(err);
}
};
exports.updatePaymentForBooking = async (req, reply) => {
try {
const { bookingid } = req.params;
const { payment_mode, payment_reference_number } = req.body;
if (!bookingid) {
return reply.code(400).send({
status_code: 400,
message: 'bookingid (param) is required',
});
}
if (typeof payment_mode === 'undefined' && typeof payment_reference_number === 'undefined') {
return reply.code(400).send({
status_code: 400,
message: 'At least one of payment_mode or payment_reference_number must be provided in body',
});
}
const update = {};
if (typeof payment_mode !== 'undefined') update.payment_mode = payment_mode;
if (typeof payment_reference_number !== 'undefined') update.payment_reference_number = payment_reference_number;
const updated = await Tankerbooking.findOneAndUpdate(
{ bookingid },
{ $set: update },
{ new: true, runValidators: true }
).lean();
if (!updated) {
return reply.code(404).send({
status_code: 404,
message: `No booking found with bookingid ${bookingid}`,
});
}
return reply.code(200).send({
status_code: 200,
message: 'Payment info updated successfully',
data: updated,
});
} catch (err) {
console.error('updatePaymentForBooking error:', err);
// keep using boom as you used earlier
throw boom.boomify(err);
}
};

@ -62,6 +62,7 @@ const tankersbookingSchema = new mongoose.Schema({
distrubance_price: { type: String, default: "none" },
amount_difference: { type: String, default: "none" },
payment_mode: { type: String, default: null },
payment_reference_number:{type: String, default: null},
remarks : { type: String, default: null },
customerPhone : { type: String, default: null },
supplierPhone : { type: String, default: null },

@ -1326,5 +1326,51 @@ fastify.route({
});
fastify.route({
method: 'PUT',
url: '/api/bookings/:bookingid/payment',
schema: {
description: 'Update payment details for a tanker booking',
tags: ['User'],
summary: 'Update payment info',
params: {
type: 'object',
properties: {
bookingid: { type: 'string', description: 'Booking ID' }
},
required: ['bookingid']
},
body: {
type: 'object',
properties: {
payment_mode: { type: 'string', description: 'Payment mode (e.g., UPI, cash, card)' },
payment_reference_number: { type: 'string', description: 'Reference/transaction ID from gateway' }
},
// at least one should be provided — validated in controller
additionalProperties: false
},
response: {
200: {
type: 'object',
properties: {
status_code: { type: 'integer' },
message: { type: 'string' },
data: { type: 'object' }
}
},
400: { type: 'object' },
404: { type: 'object' }
},
security: [
{
basicAuth: []
}
]
},
// preHandler: fastify.auth([fastify.authenticate]), // enable auth if needed
handler: userController.updatePaymentForBooking
});
next();
};

Loading…
Cancel
Save