#derin_webhooks

1 messages · Page 1 of 1 (latest)

final solsticeBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1297767602050826280

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

sinful valve
coarse mist
#

const createRefund = async (req, res, next) => {
const { paymentIntentId, bookId } = req.body;

try {
const book = await Book.findById(bookId);

if (!book) {
  return res
    .status(404)
    .json({ success: false, message: "Book not found" });
}

const refundAmount = book.price * 100;

const refund = await stripe.refunds.create({
  payment_intent: paymentIntentId,
  amount: refundAmount,
});

res.status(200).json({ success: true, refund });

} catch (error) {
console.error("Error creating refund:", error);
res
.status(500)
.json({ success: false, message: "Failed to create refund" });
}
};

const webhookRefund = (req, res, next) => {
const signature = req.headers["stripe-signature"];

let event;

try {
event = stripe.webhooks.constructEvent(
req.body,
signature,
process.env.STRIPE_REFUND_WEBHOOK_TEST_SECRET
);
} catch (err) {
console.error("Webhook signature verification failed:", err.message);
return res.status(400).send(Webhook Error: ${err.message});
}

if (event.type === "charge.refunded") {
const refund = event.data.object;

if (refund.status === "succeeded") {
  const paymentIntentId = refund.payment_intent;

  const { bookId } = req.body;

  Purchase.findOneAndUpdate(
    { paymentIntentId, book: bookId },
    { refunded: true }
  )
    .then(() => {
      console.log("Purchase marked as refunded");
    })
    .catch((err) => {
      console.error("Error updating refund status:", err);
    });
}

}
{
"error": {
"message": "Refund amount ($9.00) is greater than unrefunded amount on charge ($4.53)",
"param": "amount",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_oPUhwwsLZhnN3M?t=1729481678",
"type": "invalid_request_error"
}
}

sinful valve
#

The charge amount of pi_3QCC1kHloKxPxF5L0QjRjiss was CAD 22.53. There were multiple refunds performed on this Payment Intent:

  1. [2024-10-21 03:11:50 UTC] CAD 9.00 was refunded in https://dashboard.stripe.com/test/logs/req_AOseH5N1U9COP5 - remaining balance for refund was: (22.53-9) = 13.53 CAD
  2. [2024-10-21 03:17:31 UTC] CAD 9.00 was refunded in https://dashboard.stripe.com/test/logs/req_7jD8PsbTdP3AsE - remaining balance was (13.53 - 9) = 4.53 CAD

This pi_3QCC1kHloKxPxF5L0QjRjiss only left with CAD 4.53 to refund, which was fewer than the refunded amount of CAD 9.00 in https://dashboard.stripe.com/test/logs/req_oPUhwwsLZhnN3M that was made on 2024-10-21 03:34:38 UTC

final solsticeBOT
coarse mist
#

Thank you so much River. This explanation is satisfactory. The problem is that I am not seeing the details on the dashboard. I am working on testing mode so i'll need to adjust the frontend codes. Thanks a million once again.

#

The problem I am having is that even though the create is been created an the refund is taking place. The dashboard is still returning an error response. HTTP status code
404 (Not Found)
{
"status": "fail",
"message": "Can't find /api/webhook-refund on this server"
}

mystic rune
#

Hi @coarse mist I'm taking over this thread

#

Can you share with me the request ID?

coarse mist
#

Okay, thank you. The request ID is "evt_3QCDFeHloKxPxF5L1kjLEl8X"

mystic rune
#

This is the webhook event ID. and the event wasn't delievered successfully because your server returned 404

coarse mist
#

Do you mean the webhook ID

mystic rune
coarse mist
#

Thank you so very much. I have identified my error. The endpoint URL is wrong. I will fix that and test again. Thanks a million. I really appreciate your support.