handling case where payout failed and webhook event not received
This commit is contained in:
@@ -116,6 +116,61 @@ class PaymentEmailService {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send payout failed notification to owner
|
||||
* @param {string} ownerEmail - Owner's email address
|
||||
* @param {Object} params - Email parameters
|
||||
* @param {string} params.ownerName - Owner's name
|
||||
* @param {number} params.payoutAmount - Payout amount in dollars
|
||||
* @param {string} params.failureMessage - User-friendly failure message
|
||||
* @param {string} params.actionRequired - Action the owner needs to take
|
||||
* @param {string} params.failureCode - The Stripe failure code
|
||||
* @param {boolean} params.requiresBankUpdate - Whether bank account update is needed
|
||||
* @param {string} params.payoutSettingsUrl - URL to payout settings
|
||||
* @returns {Promise<{success: boolean, messageId?: string, error?: string}>}
|
||||
*/
|
||||
async sendPayoutFailedNotification(ownerEmail, params) {
|
||||
if (!this.initialized) {
|
||||
await this.initialize();
|
||||
}
|
||||
|
||||
try {
|
||||
const {
|
||||
ownerName,
|
||||
payoutAmount,
|
||||
failureMessage,
|
||||
actionRequired,
|
||||
failureCode,
|
||||
requiresBankUpdate,
|
||||
payoutSettingsUrl,
|
||||
} = params;
|
||||
|
||||
const variables = {
|
||||
ownerName: ownerName || "there",
|
||||
payoutAmount: payoutAmount?.toFixed(2) || "0.00",
|
||||
failureMessage: failureMessage || "There was an issue with your payout.",
|
||||
actionRequired: actionRequired || "Please check your bank account details.",
|
||||
failureCode: failureCode || "unknown",
|
||||
requiresBankUpdate: requiresBankUpdate || false,
|
||||
payoutSettingsUrl: payoutSettingsUrl || process.env.FRONTEND_URL + "/settings/payouts",
|
||||
};
|
||||
|
||||
const htmlContent = await this.templateManager.renderTemplate(
|
||||
"payoutFailedToOwner",
|
||||
variables
|
||||
);
|
||||
|
||||
return await this.emailClient.sendEmail(
|
||||
ownerEmail,
|
||||
"Action Required: Payout Issue - Village Share",
|
||||
htmlContent
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Failed to send payout failed notification:", error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PaymentEmailService;
|
||||
|
||||
Reference in New Issue
Block a user