handling case where payout failed and webhook event not received
This commit is contained in:
@@ -1111,7 +1111,18 @@ router.post("/cost-preview", authenticateToken, async (req, res) => {
|
||||
|
||||
// Get earnings status for owner's rentals
|
||||
router.get("/earnings/status", authenticateToken, async (req, res, next) => {
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
|
||||
try {
|
||||
// Trigger payout reconciliation in background (non-blocking)
|
||||
// This catches any missed payout.paid or payout.failed webhooks
|
||||
StripeWebhookService.reconcilePayoutStatuses(req.user.id).catch((err) => {
|
||||
reqLogger.error("Background payout reconciliation failed", {
|
||||
error: err.message,
|
||||
userId: req.user.id,
|
||||
});
|
||||
});
|
||||
|
||||
const ownerRentals = await Rental.findAll({
|
||||
where: {
|
||||
ownerId: req.user.id,
|
||||
@@ -1125,6 +1136,9 @@ router.get("/earnings/status", authenticateToken, async (req, res, next) => {
|
||||
"payoutStatus",
|
||||
"payoutProcessedAt",
|
||||
"stripeTransferId",
|
||||
"bankDepositStatus",
|
||||
"bankDepositAt",
|
||||
"bankDepositFailureCode",
|
||||
],
|
||||
include: [{ model: Item, as: "item", attributes: ["name"] }],
|
||||
order: [["createdAt", "DESC"]],
|
||||
@@ -1132,7 +1146,6 @@ router.get("/earnings/status", authenticateToken, async (req, res, next) => {
|
||||
|
||||
res.json(ownerRentals);
|
||||
} catch (error) {
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
reqLogger.error("Error getting earnings status", {
|
||||
error: error.message,
|
||||
stack: error.stack,
|
||||
|
||||
Reference in New Issue
Block a user