phonepe (#43)
All checks were successful
Deploy FitLien services to Dev / Deploy to Dev (push) Successful in 3m35s
All checks were successful
Deploy FitLien services to Dev / Deploy to Dev (push) Successful in 3m35s
Co-authored-by: AllenTJ7 <163137620+AllenTJ7@users.noreply.github.com> Reviewed-on: #43
This commit is contained in:
parent
4b054fac56
commit
d3cc6b3710
@ -65,11 +65,9 @@ export const directGenerateInvoice = onRequest({
|
|||||||
paymentMethod: paymentMethod || 'Online'
|
paymentMethod: paymentMethod || 'Online'
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate the invoice without updating any payment records
|
|
||||||
const invoicePath = await invoiceService.generateInvoice(invoiceData);
|
const invoicePath = await invoiceService.generateInvoice(invoiceData);
|
||||||
const downloadUrl = await invoiceService.getInvoiceDownloadUrl(invoicePath);
|
const downloadUrl = await invoiceService.getInvoiceDownloadUrl(invoicePath);
|
||||||
|
|
||||||
// Send email if requested
|
|
||||||
let emailSent = false;
|
let emailSent = false;
|
||||||
if (sendEmail && email) {
|
if (sendEmail && email) {
|
||||||
emailSent = await invoiceService.sendInvoiceEmail(invoicePath, {
|
emailSent = await invoiceService.sendInvoiceEmail(invoicePath, {
|
||||||
|
|||||||
@ -35,7 +35,6 @@ export const getInvoiceUrl = onRequest({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a download URL for the invoice
|
|
||||||
const downloadUrl = await invoiceService.getInvoiceDownloadUrl(invoicePath as string);
|
const downloadUrl = await invoiceService.getInvoiceDownloadUrl(invoicePath as string);
|
||||||
|
|
||||||
response.json({
|
response.json({
|
||||||
|
|||||||
@ -58,10 +58,32 @@ export class InvoiceService {
|
|||||||
|
|
||||||
doc.setFontSize(12);
|
doc.setFontSize(12);
|
||||||
doc.setFont('helvetica', 'normal');
|
doc.setFont('helvetica', 'normal');
|
||||||
doc.text(data.address, 20, 30);
|
|
||||||
|
const maxWidth = 170;
|
||||||
|
const lineHeight = 5;
|
||||||
|
|
||||||
|
const addressLines = doc.splitTextToSize(data.address, maxWidth);
|
||||||
|
|
||||||
|
if (addressLines.length <= 2) {
|
||||||
|
for (let i = 0; i < addressLines.length; i++) {
|
||||||
|
doc.text(addressLines[i], 20, 30 + (i * lineHeight));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
doc.text(addressLines[0], 20, 30);
|
||||||
|
|
||||||
|
let secondLine = addressLines[1];
|
||||||
|
if (secondLine.length > 3) {
|
||||||
|
secondLine = secondLine.substring(0, secondLine.length - 3) + '...';
|
||||||
|
} else {
|
||||||
|
secondLine += '...';
|
||||||
|
}
|
||||||
|
doc.text(secondLine, 20, 35);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gstYPosition = 40;
|
||||||
|
|
||||||
if (hasGst) {
|
if (hasGst) {
|
||||||
doc.text(`GSTIN: ${data.gstNumber}`, 20, 40);
|
doc.text(`GSTIN: ${data.gstNumber}`, 20, gstYPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.setFontSize(24);
|
doc.setFontSize(24);
|
||||||
@ -75,6 +97,14 @@ export class InvoiceService {
|
|||||||
doc.line(20, 45, 190, 45);
|
doc.line(20, 45, 190, 45);
|
||||||
|
|
||||||
doc.setFontSize(12);
|
doc.setFontSize(12);
|
||||||
|
const receiptToBoxX = 15;
|
||||||
|
const receiptToBoxY = 55;
|
||||||
|
const receiptToBoxWidth = 175;
|
||||||
|
const receiptToBoxHeight = 45;
|
||||||
|
|
||||||
|
doc.setDrawColor(0, 0, 0);
|
||||||
|
doc.setLineWidth(0.5);
|
||||||
|
doc.rect(receiptToBoxX, receiptToBoxY, receiptToBoxWidth, receiptToBoxHeight);
|
||||||
doc.setFont('helvetica', 'bold');
|
doc.setFont('helvetica', 'bold');
|
||||||
doc.text('Receipt To:', 20, 60);
|
doc.text('Receipt To:', 20, 60);
|
||||||
|
|
||||||
@ -83,20 +113,34 @@ export class InvoiceService {
|
|||||||
doc.text(`Phone: ${data.phoneNumber}`, 20, 80);
|
doc.text(`Phone: ${data.phoneNumber}`, 20, 80);
|
||||||
doc.text(`Email: ${data.email}`, 20, 90);
|
doc.text(`Email: ${data.email}`, 20, 90);
|
||||||
|
|
||||||
autoTable(doc,{
|
autoTable(doc, {
|
||||||
startY: 110,
|
startY: 110,
|
||||||
head: [['No.', 'Description', 'HSN/SAC', 'Amount (INR)']],
|
head: [['No.', 'Description', 'HSN/SAC', 'Amount (INR)']],
|
||||||
body: [
|
body: [
|
||||||
['1', `${data.planName} Subscription`, '999723', baseAmount.toFixed(2)]
|
['1', `${data.planName} Subscription`, '999723', baseAmount.toFixed(2)]
|
||||||
],
|
],
|
||||||
headStyles: { fillColor: [220, 220, 220], textColor: [0, 0, 0], fontStyle: 'bold' },
|
headStyles: {
|
||||||
styles: { halign: 'center' },
|
fillColor: [220, 220, 220],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
lineWidth: 0.5,
|
||||||
|
lineColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
styles: {
|
||||||
|
halign: 'center',
|
||||||
|
lineWidth: 0.5,
|
||||||
|
lineColor: [0, 0, 0]
|
||||||
|
},
|
||||||
columnStyles: {
|
columnStyles: {
|
||||||
0: { halign: 'center', cellWidth: 20 },
|
0: { halign: 'center', cellWidth: 20 },
|
||||||
1: { halign: 'left' },
|
1: { halign: 'left' },
|
||||||
2: { halign: 'center', cellWidth: 40 },
|
2: { halign: 'center', cellWidth: 40 },
|
||||||
3: { halign: 'right', cellWidth: 40 }
|
3: { halign: 'right', cellWidth: 40 }
|
||||||
}
|
},
|
||||||
|
theme: 'grid',
|
||||||
|
tableLineWidth: 0.5,
|
||||||
|
tableLineColor: [0, 0, 0],
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const finalY = (doc as any).lastAutoTable.finalY + 20;
|
const finalY = (doc as any).lastAutoTable.finalY + 20;
|
||||||
@ -122,6 +166,17 @@ export class InvoiceService {
|
|||||||
|
|
||||||
const paymentY = hasGst ? finalY + 50 : finalY + 20;
|
const paymentY = hasGst ? finalY + 50 : finalY + 20;
|
||||||
|
|
||||||
|
doc.line(20, 45, 190, 45);
|
||||||
|
|
||||||
|
const boxX = 15;
|
||||||
|
const boxY = paymentY - 5;
|
||||||
|
const boxWidth = 175;
|
||||||
|
const boxHeight = 45;
|
||||||
|
|
||||||
|
doc.setDrawColor(0, 0, 0);
|
||||||
|
doc.setLineWidth(0.5);
|
||||||
|
doc.rect(boxX, boxY, boxWidth, boxHeight);
|
||||||
|
|
||||||
doc.setFont('helvetica', 'bold');
|
doc.setFont('helvetica', 'bold');
|
||||||
doc.text('Payment Information:', 20, paymentY);
|
doc.text('Payment Information:', 20, paymentY);
|
||||||
|
|
||||||
@ -197,7 +252,7 @@ export class InvoiceService {
|
|||||||
let found = false;
|
let found = false;
|
||||||
for (let i = 0; i < paymentsData.length; i++) {
|
for (let i = 0; i < paymentsData.length; i++) {
|
||||||
if (paymentsData[i].referenceNumber === paymentId ||
|
if (paymentsData[i].referenceNumber === paymentId ||
|
||||||
paymentsData[i].transactionId === paymentId) {
|
paymentsData[i].transactionId === paymentId) {
|
||||||
paymentsData[i].invoicePath = invoicePath;
|
paymentsData[i].invoicePath = invoicePath;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { getAdmin, getLogger } from "../../shared/config";
|
|||||||
const admin = getAdmin();
|
const admin = getAdmin();
|
||||||
const logger = getLogger();
|
const logger = getLogger();
|
||||||
|
|
||||||
// Define an interface for the payment data to avoid type errors
|
|
||||||
interface PaymentData {
|
interface PaymentData {
|
||||||
id: string;
|
id: string;
|
||||||
date: string;
|
date: string;
|
||||||
@ -14,7 +13,7 @@ interface PaymentData {
|
|||||||
discount: any;
|
discount: any;
|
||||||
transactionId: string;
|
transactionId: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
invoicePath?: string; // Make this optional
|
invoicePath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updatePaymentDataAfterSuccess(
|
export async function updatePaymentDataAfterSuccess(
|
||||||
@ -24,7 +23,6 @@ export async function updatePaymentDataAfterSuccess(
|
|||||||
invoicePath?: string
|
invoicePath?: string
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
// Get the payment order from Firestore
|
|
||||||
const orderQuery = await admin.firestore()
|
const orderQuery = await admin.firestore()
|
||||||
.collection('payment_orders')
|
.collection('payment_orders')
|
||||||
.where('merchantOrderId', '==', merchantOrderId)
|
.where('merchantOrderId', '==', merchantOrderId)
|
||||||
@ -39,19 +37,17 @@ export async function updatePaymentDataAfterSuccess(
|
|||||||
const orderDoc = orderQuery.docs[0];
|
const orderDoc = orderQuery.docs[0];
|
||||||
const orderData = orderDoc.data();
|
const orderData = orderDoc.data();
|
||||||
|
|
||||||
// Extract membership ID from metaInfo
|
|
||||||
const membershipId = orderData.metaInfo?.membershipId;
|
const membershipId = orderData.metaInfo?.membershipId;
|
||||||
if (!membershipId) {
|
if (!membershipId) {
|
||||||
logger.error(`No membershipId found in metaInfo for order: ${merchantOrderId}`);
|
logger.error(`No membershipId found in metaInfo for order: ${merchantOrderId}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isoDate = new Date().toLocaleDateString('en-GB').split('/').join('-'); // DD-MM-YYYY format
|
const isoDate = new Date().toLocaleDateString('en-GB').split('/').join('-');
|
||||||
const dateTimestamp = admin.firestore.Timestamp.now();
|
const dateTimestamp = admin.firestore.Timestamp.now();
|
||||||
|
|
||||||
// Create payment data object with proper typing
|
|
||||||
const paymentData: PaymentData = {
|
const paymentData: PaymentData = {
|
||||||
id: admin.firestore().collection('_').doc().id, // Generate a UUID
|
id: admin.firestore().collection('_').doc().id,
|
||||||
date: isoDate,
|
date: isoDate,
|
||||||
dateTimestamp: dateTimestamp,
|
dateTimestamp: dateTimestamp,
|
||||||
amount: orderData.amount,
|
amount: orderData.amount,
|
||||||
@ -62,19 +58,16 @@ export async function updatePaymentDataAfterSuccess(
|
|||||||
createdAt: new Date()
|
createdAt: new Date()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add invoice path if provided
|
|
||||||
if (invoicePath) {
|
if (invoicePath) {
|
||||||
paymentData.invoicePath = invoicePath;
|
paymentData.invoicePath = invoicePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get reference to membership payments document
|
|
||||||
const membershipPaymentsRef = admin.firestore()
|
const membershipPaymentsRef = admin.firestore()
|
||||||
.collection('membership_payments')
|
.collection('membership_payments')
|
||||||
.doc(membershipId);
|
.doc(membershipId);
|
||||||
|
|
||||||
const docSnapshot = await membershipPaymentsRef.get();
|
const docSnapshot = await membershipPaymentsRef.get();
|
||||||
|
|
||||||
// Update or create the membership payments document
|
|
||||||
if (docSnapshot.exists) {
|
if (docSnapshot.exists) {
|
||||||
await membershipPaymentsRef.update({
|
await membershipPaymentsRef.update({
|
||||||
'payments': admin.firestore.FieldValue.arrayUnion(paymentData),
|
'payments': admin.firestore.FieldValue.arrayUnion(paymentData),
|
||||||
@ -92,7 +85,6 @@ export async function updatePaymentDataAfterSuccess(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update membership status
|
|
||||||
await updateMembershipStatus(membershipId, orderData.userId);
|
await updateMembershipStatus(membershipId, orderData.userId);
|
||||||
|
|
||||||
logger.info(`Successfully updated payment data for membership: ${membershipId}`);
|
logger.info(`Successfully updated payment data for membership: ${membershipId}`);
|
||||||
@ -118,7 +110,7 @@ async function updateMembershipStatus(membershipId: string, userId: string): Pro
|
|||||||
.collection('memberships')
|
.collection('memberships')
|
||||||
.doc(membershipId)
|
.doc(membershipId)
|
||||||
.update({
|
.update({
|
||||||
'status': 'ACTIVE', // Assuming this matches your InvitationStatus.active
|
'status': 'ACTIVE',
|
||||||
'updatedAt': admin.firestore.FieldValue.serverTimestamp(),
|
'updatedAt': admin.firestore.FieldValue.serverTimestamp(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user