Skip to content

feat: add support for failed withdrawal payment notifications with retry options and localization Summary#793

Open
Matobi98 wants to merge 1 commit intolnp2pBot:mainfrom
Matobi98:issue768
Open

feat: add support for failed withdrawal payment notifications with retry options and localization Summary#793
Matobi98 wants to merge 1 commit intolnp2pBot:mainfrom
Matobi98:issue768

Conversation

@Matobi98
Copy link
Copy Markdown
Contributor

@Matobi98 Matobi98 commented Apr 27, 2026

Summary

When a community earnings withdrawal fails (expired invoice or repeated payment failure), the bot now:
- Sends a dedicated notification instead of the generic order payment failure message

  • Includes a "Withdraw earnings" inline button so the admin can immediately retry without having to navigate the bot manually
  • Adds a filter to skip already-expired invoices in the community earnings payment query, avoiding unnecessary retries

Changes

  • jobs/pending_payments.ts: separate notification path for community earnings failures with inline retry button
  • bot/modules/community/scenes.ts: filter out is_invoice_expired: true invoices from the pending payments query
  • locales/*.yaml (10 languages): new pending_payment_failed_earnings and withdraw_earnings keys

Test plan

  • Simulate an expired community earnings invoice and verify the bot sends the new notification with the "Withdraw earnings" button
  • Confirm the button triggers the correct withdrawEarnings_<community_id> callback
  • Verify the generic pending_payment_failed message still works for regular order payments

Summary by CodeRabbit

  • Bug Fixes

    • Improved duplicate payment detection to exclude expired invoices from active payment checks.
  • New Features

    • Added "withdraw earnings" action button in payment failure notifications, enabling users to quickly initiate new withdrawal attempts when invoices expire or payments fail.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

Walkthrough

This PR refines pending payment handling for earnings and withdrawals by filtering expired invoices from duplication checks, adding inline "withdraw earnings" action buttons to failure and expiration notifications, and introducing a specialized pending_payment_failed_earnings message key across all supported locales.

Changes

Cohort / File(s) Summary
Core Logic
bot/modules/community/scenes.ts, jobs/pending_payments.ts
Modified pending payment invoice lookup to exclude expired records from duplication detection; added "withdraw earnings" inline action buttons to failure and expiration notifications; updated failure message key to pending_payment_failed_earnings.
Localization
locales/{de,en,es,fa,fr,it,ko,pt,ru,uk}.yaml
Added new translation entry pending_payment_failed_earnings across all 10 language files to provide locale-specific messaging for earnings/withdrawal payment failures with retry guidance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • grunch
  • Luquitasjeffrey

Poem

🐰 A withdrawal's quest, now clearer and bright,
With expired invoices filtered from sight,
Fresh "earn" buttons bloom in messages true,
Across every tongue—Persian, Korean, and blue!
Our earnings grow wings when we get it just right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding support for failed withdrawal payment notifications with retry options and localization across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
jobs/pending_payments.ts (1)

198-216: ⚠️ Potential issue | 🟠 Major

Missing return after the expired-invoice notification — fall-through causes duplicate user message and a misleading error log.

Unlike the analogous expired-invoice branch in attemptPendingPayments (lines 61–70), this block doesn't return after sending the message. Execution continues into the community fetch and the else branch (because payment.confirmed_at is falsy on an expired-invoice object):

  • pending.last_error is set to 'PAYMENT_FAILED' and a Withdraw failed after N attempts error is logged, even though the real cause is expiration.
  • If this happens on the attempt where pending.attempts >= PAYMENT_ATTEMPTS, the user receives two Telegram messages (invoice_expired_earnings followed by pending_payment_failed_earnings), both carrying the same withdraw_earnings inline button — a confusing UX that this PR amplifies by adding the second button.
🛠️ Proposed fix
       if (!!payment && payment.is_expired) {
         pending.is_invoice_expired = true;
-        await bot.telegram.sendMessage(
+        await bot.telegram.sendMessage(
           user.tg_id,
           i18nCtx.t('invoice_expired_earnings'),
           {
             reply_markup: {
               inline_keyboard: [
                 [
                   {
                     text: i18nCtx.t('withdraw_earnings'),
                     callback_data: `withdrawEarnings_${pending.community_id}`,
                   },
                 ],
               ],
             },
           },
         );
+        return;
       }

Note that pending.save() will still run in finally, so is_invoice_expired = true is persisted as intended.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@jobs/pending_payments.ts` around lines 198 - 216, The expired-invoice branch
is missing a return, so after setting pending.is_invoice_expired and calling
bot.telegram.sendMessage it falls through and executes the failure/else logic;
fix by adding an early return immediately after the bot.telegram.sendMessage
call in the block that sets pending.is_invoice_expired so execution exits the
surrounding function (ensuring pending.save() in the finally still runs) to
prevent setting pending.last_error, logging a PAYMENT_FAILED, and sending the
duplicate pending_payment_failed_earnings message.
🧹 Nitpick comments (1)
jobs/pending_payments.ts (1)

200-214: Extract the duplicated "withdraw earnings" inline keyboard.

The same reply_markup object is constructed in both notification paths. A small helper keeps the two flows in sync if the button text/callback shape ever changes.

♻️ Suggested helper
const withdrawEarningsKeyboard = (i18nCtx: I18nContext, communityId: unknown) => ({
  reply_markup: {
    inline_keyboard: [[
      {
        text: i18nCtx.t('withdraw_earnings'),
        callback_data: `withdrawEarnings_${communityId}`,
      },
    ]],
  },
});

Then use it at both call sites:

await bot.telegram.sendMessage(
  user.tg_id,
  i18nCtx.t('invoice_expired_earnings'),
  withdrawEarningsKeyboard(i18nCtx, pending.community_id),
);

Also applies to: 257-274

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@jobs/pending_payments.ts` around lines 200 - 214, Extract the duplicated
reply_markup into a small helper (e.g., withdrawEarningsKeyboard) that accepts
(i18nCtx, communityId) and returns the inline keyboard object; replace the
inline reply_markup passed to bot.telegram.sendMessage in the
invoice_expired_earnings path (the sendMessage call using user.tg_id and
i18nCtx.t('invoice_expired_earnings')) and the other sendMessage call at the
other location (lines ~257-274) to use withdrawEarningsKeyboard(i18nCtx,
pending.community_id) so both flows share the same button text and callback_data
construction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@jobs/pending_payments.ts`:
- Around line 198-216: The expired-invoice branch is missing a return, so after
setting pending.is_invoice_expired and calling bot.telegram.sendMessage it falls
through and executes the failure/else logic; fix by adding an early return
immediately after the bot.telegram.sendMessage call in the block that sets
pending.is_invoice_expired so execution exits the surrounding function (ensuring
pending.save() in the finally still runs) to prevent setting pending.last_error,
logging a PAYMENT_FAILED, and sending the duplicate
pending_payment_failed_earnings message.

---

Nitpick comments:
In `@jobs/pending_payments.ts`:
- Around line 200-214: Extract the duplicated reply_markup into a small helper
(e.g., withdrawEarningsKeyboard) that accepts (i18nCtx, communityId) and returns
the inline keyboard object; replace the inline reply_markup passed to
bot.telegram.sendMessage in the invoice_expired_earnings path (the sendMessage
call using user.tg_id and i18nCtx.t('invoice_expired_earnings')) and the other
sendMessage call at the other location (lines ~257-274) to use
withdrawEarningsKeyboard(i18nCtx, pending.community_id) so both flows share the
same button text and callback_data construction.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c79f792a-69ac-4b64-afe7-fa1a8076e002

📥 Commits

Reviewing files that changed from the base of the PR and between 064ded1 and 9f0c783.

📒 Files selected for processing (12)
  • bot/modules/community/scenes.ts
  • jobs/pending_payments.ts
  • locales/de.yaml
  • locales/en.yaml
  • locales/es.yaml
  • locales/fa.yaml
  • locales/fr.yaml
  • locales/it.yaml
  • locales/ko.yaml
  • locales/pt.yaml
  • locales/ru.yaml
  • locales/uk.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant