phonepe #50
@ -65,11 +65,9 @@ export const directGenerateInvoice = onRequest({
|
||||
paymentMethod: paymentMethod || 'Online'
|
||||
};
|
||||
|
||||
// Generate the invoice without updating any payment records
|
||||
const invoicePath = await invoiceService.generateInvoice(invoiceData);
|
||||
const downloadUrl = await invoiceService.getInvoiceDownloadUrl(invoicePath);
|
||||
|
||||
// Send email if requested
|
||||
let emailSent = false;
|
||||
if (sendEmail && email) {
|
||||
emailSent = await invoiceService.sendInvoiceEmail(invoicePath, {
|
||||
|
||||
@ -35,7 +35,6 @@ export const getInvoiceUrl = onRequest({
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a download URL for the invoice
|
||||
const downloadUrl = await invoiceService.getInvoiceDownloadUrl(invoicePath as string);
|
||||
|
||||
response.json({
|
||||
|
||||
@ -3,7 +3,6 @@ import { getAdmin, getLogger } from "../../shared/config";
|
||||
const admin = getAdmin();
|
||||
const logger = getLogger();
|
||||
|
||||
// Define an interface for the payment data to avoid type errors
|
||||
interface PaymentData {
|
||||
id: string;
|
||||
date: string;
|
||||
@ -14,7 +13,7 @@ interface PaymentData {
|
||||
discount: any;
|
||||
transactionId: string;
|
||||
createdAt: Date;
|
||||
invoicePath?: string; // Make this optional
|
||||
invoicePath?: string;
|
||||
}
|
||||
|
||||
export async function updatePaymentDataAfterSuccess(
|
||||
@ -24,7 +23,6 @@ export async function updatePaymentDataAfterSuccess(
|
||||
invoicePath?: string
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
// Get the payment order from Firestore
|
||||
const orderQuery = await admin.firestore()
|
||||
.collection('payment_orders')
|
||||
.where('merchantOrderId', '==', merchantOrderId)
|
||||
@ -39,19 +37,17 @@ export async function updatePaymentDataAfterSuccess(
|
||||
const orderDoc = orderQuery.docs[0];
|
||||
const orderData = orderDoc.data();
|
||||
|
||||
// Extract membership ID from metaInfo
|
||||
const membershipId = orderData.metaInfo?.membershipId;
|
||||
if (!membershipId) {
|
||||
logger.error(`No membershipId found in metaInfo for order: ${merchantOrderId}`);
|
||||
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();
|
||||
|
||||
// Create payment data object with proper typing
|
||||
const paymentData: PaymentData = {
|
||||
id: admin.firestore().collection('_').doc().id, // Generate a UUID
|
||||
id: admin.firestore().collection('_').doc().id,
|
||||
date: isoDate,
|
||||
dateTimestamp: dateTimestamp,
|
||||
amount: orderData.amount,
|
||||
@ -62,19 +58,16 @@ export async function updatePaymentDataAfterSuccess(
|
||||
createdAt: new Date()
|
||||
};
|
||||
|
||||
// Add invoice path if provided
|
||||
if (invoicePath) {
|
||||
paymentData.invoicePath = invoicePath;
|
||||
}
|
||||
|
||||
// Get reference to membership payments document
|
||||
const membershipPaymentsRef = admin.firestore()
|
||||
.collection('membership_payments')
|
||||
.doc(membershipId);
|
||||
|
||||
const docSnapshot = await membershipPaymentsRef.get();
|
||||
|
||||
// Update or create the membership payments document
|
||||
if (docSnapshot.exists) {
|
||||
await membershipPaymentsRef.update({
|
||||
'payments': admin.firestore.FieldValue.arrayUnion(paymentData),
|
||||
@ -92,7 +85,6 @@ export async function updatePaymentDataAfterSuccess(
|
||||
});
|
||||
}
|
||||
|
||||
// Update membership status
|
||||
await updateMembershipStatus(membershipId, orderData.userId);
|
||||
|
||||
logger.info(`Successfully updated payment data for membership: ${membershipId}`);
|
||||
@ -118,7 +110,7 @@ async function updateMembershipStatus(membershipId: string, userId: string): Pro
|
||||
.collection('memberships')
|
||||
.doc(membershipId)
|
||||
.update({
|
||||
'status': 'ACTIVE', // Assuming this matches your InvitationStatus.active
|
||||
'status': 'ACTIVE',
|
||||
'updatedAt': admin.firestore.FieldValue.serverTimestamp(),
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user