Skip to content

Improve logic of paytobuyer, setinvoice, settleorder, - #677

Merged
grunch merged 2 commits into
mainfrom
improve-paytobuyer-settleorder-setinvoice
Jul 9, 2025
Merged

Improve logic of paytobuyer, setinvoice, settleorder,#677
grunch merged 2 commits into
mainfrom
improve-paytobuyer-settleorder-setinvoice

Conversation

@Catrya

@Catrya Catrya commented Jul 7, 2025

Copy link
Copy Markdown
Member
  • Now /paytobuyer can only be used if the order status is FROZEN or PAID_HOLD_INVOICE
  • /settleorder can only be used if the order status is DISPUTE
  • /setinvoice is also allowed if the order status is COMPLETED_BY_ADMIN
  • Added respective error messages

Summary by CodeRabbit

  • New Features

    • Added user-facing messages in multiple languages clarifying when the "paytobuyer" and "settleorder" commands can be used, based on order status.
    • Expanded order status conditions to allow additional valid states for invoice-related commands.
  • Bug Fixes

    • Improved validation for order status when using the "paytobuyer" and "settleorder" commands, ensuring commands are only available for appropriate order states.
  • Localization

    • Expanded translations for new status-related messages in English, German, Spanish, Persian, French, Italian, Korean, Portuguese, Russian, and Ukrainian.

@Catrya
Catrya requested a review from grunch July 7, 2025 21:57
@coderabbitai

coderabbitai Bot commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

"""

Walkthrough

Order status validation logic has been updated in bot command handlers to refine when certain actions can occur. New localized user messages were added in multiple languages to clarify command usage restrictions based on order status. No exported function signatures or public interfaces were changed.

Changes

Files / Areas Change Summary
bot/commands.ts Expanded allowed statuses in addInvoicePHI to include 'COMPLETED_BY_ADMIN' alongside 'PAID_HOLD_INVOICE'.
bot/start.ts Updated status checks for /setinvoice, /settleorder, and /paytobuyer commands; enforced stricter validation and status transitions.
locales/de.yaml, en.yaml, es.yaml, fa.yaml, fr.yaml, it.yaml, ko.yaml, pt.yaml, ru.yaml, uk.yaml Added new localized strings specifying command usage restrictions based on order statuses.

Possibly related PRs

  • Fix frozen #676: Adjusts order status checks in addInvoicePHI and /setinvoice command handling, focusing on inclusion/exclusion of specific statuses—closely related to the status validation logic updated in this PR.

Suggested reviewers

  • grunch

Poem

A hop, a skip, a status check,
Commands now know just what to expect.
Translations bloom in every tongue,
Ensuring users aren’t left unsung.
Orders march through states so neat—
This bunny’s code is quite the treat! 🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-08T14_09_56_956Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ec31b7 and 4db35e2.

📒 Files selected for processing (1)
  • bot/start.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bot/start.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: ci_to_main
  • GitHub Check: Analyze (javascript)
  • GitHub Check: ci_to_main
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch improve-paytobuyer-settleorder-setinvoice

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
locales/ru.yaml (1)

640-641: Translation consistent; minor stylistic tweak optional.

The statuses (FROZEN, PAID_HOLD_INVOICE, DISPUTE) are intentionally left untranslated for technical accuracy.
If you prefer full Russian localisation, consider wrapping the English status names in back-quotes to visually distinguish them (e.g. «статус FROZEN»). No functional impact—optional.

locales/it.yaml (1)

637-638: Italian copy OK; watch plural agreement.

“ordini con stato …” is plural, which matches the message, but the command acts on a single order.
Consider singular form for consistency with other locale strings:

-Il comando paytobuyer può essere utilizzato solo su ordini con stato …
+Il comando paytobuyer può essere utilizzato solo su un ordine con stato …

Same for settleorder_only_dispute_orders.

locales/fr.yaml (1)

639-640: Minor wording nitpick – prefix commands with “/” for consistency

Everywhere else in the file, commands are shown with the leading slash (e.g. /release).
Consider:

-paytobuyer_only_frozen_orders: La commande paytobuyer ne peut être utilisée ...
-settleorder_only_dispute_orders: La commande settleorder ne peut être utilisée ...
+paytobuyer_only_frozen_orders: La commande /paytobuyer ne peut être utilisée ...
+settleorder_only_dispute_orders: La commande /settleorder ne peut être utilisée ...

Purely cosmetic, up to you.

bot/start.ts (1)

894-897: Consider error handling for status update

The status update from FROZEN to PAID_HOLD_INVOICE before calling payToBuyer is logical, but there's a potential issue: if payToBuyer fails after the status update, the order will remain in PAID_HOLD_INVOICE status without successful payment completion.

Consider wrapping the status update and payment in a transaction or adding error handling to revert the status if payment fails:

 // Set status to PAID_HOLD_INVOICE before paying (only if not already PAID_HOLD_INVOICE)
 if (order.status === 'FROZEN') {
   order.status = 'PAID_HOLD_INVOICE';
   await order.save();
 }

-await payToBuyer(bot, order);
+try {
+  await payToBuyer(bot, order);
+} catch (error) {
+  // Revert status if payment fails and order was originally FROZEN
+  if (order.status === 'PAID_HOLD_INVOICE') {
+    order.status = 'FROZEN';
+    await order.save();
+  }
+  throw error;
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe4fe6e and 4ec31b7.

📒 Files selected for processing (12)
  • bot/commands.ts (1 hunks)
  • bot/start.ts (4 hunks)
  • locales/de.yaml (1 hunks)
  • locales/en.yaml (1 hunks)
  • locales/es.yaml (1 hunks)
  • locales/fa.yaml (1 hunks)
  • locales/fr.yaml (1 hunks)
  • locales/it.yaml (1 hunks)
  • locales/ko.yaml (1 hunks)
  • locales/pt.yaml (1 hunks)
  • locales/ru.yaml (1 hunks)
  • locales/uk.yaml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.{ts,tsx}`: Use custom context types that extend Telegraf's base context, such as MainContext and CommunityContext, for context enhancement.

**/*.{ts,tsx}: Use custom context types that extend Telegraf's base context, such as MainContext and CommunityContext, for context enhancement.

📄 Source: CodeRabbit Inference Engine (CLAUDE.md)

List of files the instruction was applied to:

  • bot/commands.ts
  • bot/start.ts
`bot/start.ts`: Bot initialization, command registration, and scheduled jobs should be handled in bot/start.ts.

bot/start.ts: Bot initialization, command registration, and scheduled jobs should be handled in bot/start.ts.

📄 Source: CodeRabbit Inference Engine (CLAUDE.md)

List of files the instruction was applied to:

  • bot/start.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: webwarrior-ws
PR: lnp2pBot/bot#665
File: bot/commands.ts:801-803
Timestamp: 2025-06-23T08:18:45.934Z
Learning: In the IOrder interface from bot/commands.ts, the secret property is typed such that it cannot be undefined, only null or string. Therefore, checking only for null is sufficient and checking for undefined is unnecessary.
bot/commands.ts (3)
Learnt from: webwarrior-ws
PR: lnp2pBot/bot#665
File: bot/commands.ts:801-803
Timestamp: 2025-06-23T08:18:45.934Z
Learning: In the IOrder interface from bot/commands.ts, the secret property is typed such that it cannot be undefined, only null or string. Therefore, checking only for null is sufficient and checking for undefined is unnecessary.
Learnt from: webwarrior-ws
PR: lnp2pBot/bot#665
File: bot/commands.ts:801-803
Timestamp: 2025-06-23T08:18:45.934Z
Learning: In the IOrder interface from models/order.ts, the secret property is typed as `string | null`, which means it can never be undefined in TypeScript strict mode. Therefore, checking only for null is sufficient and checking for undefined is unnecessary.
Learnt from: webwarrior-ws
PR: lnp2pBot/bot#665
File: bot/commands.ts:267-270
Timestamp: 2025-06-23T08:19:23.336Z
Learning: In the IOrder interface, the hash property is typed as `string | null` (not including undefined), so checking specifically for null with `if (order.hash === null)` is the correct and most precise approach rather than using a falsy check like `if (!order.hash)`.
bot/start.ts (3)
Learnt from: CR
PR: lnp2pBot/bot#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T20:32:02.450Z
Learning: Applies to bot/start.ts : Bot initialization, command registration, and scheduled jobs should be handled in bot/start.ts.
Learnt from: webwarrior-ws
PR: lnp2pBot/bot#665
File: bot/commands.ts:801-803
Timestamp: 2025-06-23T08:18:45.934Z
Learning: In the IOrder interface from bot/commands.ts, the secret property is typed such that it cannot be undefined, only null or string. Therefore, checking only for null is sufficient and checking for undefined is unnecessary.
Learnt from: webwarrior-ws
PR: lnp2pBot/bot#665
File: bot/commands.ts:267-270
Timestamp: 2025-06-23T08:19:23.336Z
Learning: In the IOrder interface, the hash property is typed as `string | null` (not including undefined), so checking specifically for null with `if (order.hash === null)` is the correct and most precise approach rather than using a falsy check like `if (!order.hash)`.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: ci_to_main
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (11)
locales/en.yaml (1)

646-647: New keys look good; verify they’re actually referenced in handlers.

Strings are clear, placeholders are not needed, and naming follows existing pattern.
Just double-check that paytobuyer_only_frozen_orders / settleorder_only_dispute_orders have been wired into the corresponding ctx.i18n.t() calls in the command handlers; otherwise the user will still get the fallback English text.

locales/es.yaml (1)

642-643: LGTM! Clear user guidance for command restrictions.

The Spanish localization strings properly communicate the new order status restrictions for the /paytobuyer and /settleorder commands. The messages are clear and user-friendly.

bot/commands.ts (1)

585-586: LGTM! Properly expands allowed order statuses.

The expansion to include 'COMPLETED_BY_ADMIN' status correctly implements the PR requirement to allow the /setinvoice command for admin-completed orders. The comment accurately reflects the updated logic.

locales/uk.yaml (1)

636-637: LGTM! Consistent Ukrainian localization for command restrictions.

The Ukrainian localization strings correctly translate the command restriction messages, maintaining consistency with other language files. The translations are clear and properly formatted.

locales/de.yaml (1)

640-641: New keys added correctly & translation looks good

Keys match the handler names (paytobuyer_only_frozen_orders, settleorder_only_dispute_orders) and the German wording is clear while keeping status constants untranslated.
No YAML-syntax or interpolation issues detected. 👍

locales/ko.yaml (1)

636-638: LGTM – keys & translations provided

All three new keys are present, Hangul text is concise, and status constants are left in English as expected. YAML syntax valid.

locales/fa.yaml (1)

639-640: LGTM: Proper localization support for command restrictions

The new Persian translations correctly communicate the usage restrictions for the /paytobuyer and /settleorder commands, providing clear user feedback when commands are used inappropriately.

locales/pt.yaml (1)

639-640: LGTM: Consistent multilingual support

The Portuguese translations properly implement the command restriction messages, maintaining consistency with other locale files and providing appropriate user feedback.

bot/start.ts (3)

135-135: LGTM: Logical expansion of setinvoice query condition

Adding COMPLETED_BY_ADMIN status to the /setinvoice command query makes sense, allowing buyers to update their invoice even after admin completion. This aligns with the PR objectives and maintains consistency with the addInvoicePHI function expansion mentioned in the AI summary.


499-502: LGTM: Proper status validation for settleorder command

The restriction to only allow /settleorder on orders with DISPUTE status is logical and provides appropriate user feedback. This ensures the command is used only in the correct context and prevents misuse.


869-872: LGTM: Appropriate status validation for paytobuyer command

The validation correctly restricts /paytobuyer to orders with FROZEN or PAID_HOLD_INVOICE statuses, which aligns with the expected workflow. The error message provides clear feedback to users about the command's usage requirements.

Comment thread bot/start.ts Outdated
Comment thread bot/start.ts

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@grunch
grunch merged commit 7480697 into main Jul 9, 2025
7 checks passed
@grunch
grunch deleted the improve-paytobuyer-settleorder-setinvoice branch July 9, 2025 17:36
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.

3 participants