feat(payment): add QR code generation#7751
Conversation
Reviewer's GuideAdds QR-code-based ticketing for invoices, including email delivery on successful payment, barcode scanning workflow with real-time updates, and enhanced invoice filtering and payment configuration, while refactoring invoice kind filtering logic and relaxing email delivery user requirements. Sequence diagram for invoice QR email on successful paymentsequenceDiagram
participant Client as ClientPortal
participant InvoicesResolver as invoicesCheck
participant InvoicesModel as models.Invoices
participant PaymentMethodsModel as models.PaymentMethods
participant QRMailer as sendInvoiceBarcodeEmail
participant Notifications as sendTRPCMessage
participant QRCode as QRCode
Client->>InvoicesResolver: invoicesCheck(_id)
InvoicesResolver->>InvoicesModel: getInvoice({ _id }, true)
InvoicesModel-->>InvoicesResolver: invoice
InvoicesResolver->>PaymentMethodsModel: findOne({ _id: paymentId }).lean()
PaymentMethodsModel-->>InvoicesResolver: payment
InvoicesResolver->>InvoicesResolver: updateOne({ _id }, { sendEmailOnPayment: true })
InvoicesResolver->>QRMailer: sendInvoiceBarcodeEmail(subdomain, invoice)
QRMailer->>QRCode: create(ticketCode, { errorCorrectionLevel: 'M' })
QRMailer->>Notifications: sendTRPCMessage({ pluginName: core, module: notifications, action: sendEmail })
Sequence diagram for invoice barcode scanning and real-time updatessequenceDiagram
actor Scanner as ScannerClient
participant GQLAPI as invoiceScanBarcode
participant InvoicesModel as models.Invoices
participant PubSub as graphqlPubsub
participant UI as useInvoices.subscribeToMore
Scanner->>GQLAPI: invoiceScanBarcode(code)
GQLAPI->>InvoicesModel: findOne({ invoiceNumber: code }).lean()
InvoicesModel-->>GQLAPI: invoice
GQLAPI->>InvoicesModel: scanBarcode(code)
InvoicesModel-->>GQLAPI: scanned
GQLAPI->>PubSub: publish(invoiceUpdated:scanned._id, { invoiceUpdated: scanned })
GQLAPI->>PubSub: publish(invoiceScanned, { invoiceScanned: scanned })
PubSub-->>Scanner: invoiceScanBarcode response (scanned)
UI->>UI: useInvoices()
UI->>UI: subscribeToMore({ document: INVOICE_SCANNED_SUBSCRIPTION })
PubSub-->>UI: INVOICE_SCANNED_SUBSCRIPTION
UI->>UI: updateQuery(prev, subscriptionData)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR adds invoice barcode scanning with real-time subscription updates, introduces configurable email sending on payments, improves invoice filtering, and includes minor schema updates for email delivery and contact handling across backend and frontend. ChangesInvoice Barcode Scanning Feature
Payment Method Email Configuration
Supporting Updates
🎯 4 (Complex) | ⏱️ ~60 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
🌗 Pull Request OverviewThis PR adds QR code generation functionality for payment invoices, including barcode scanning capabilities, email notifications with QR codes upon successful payment, and filtering enhancements for invoice management. It introduces a new Reviewed Changes Show a summary per file
📋 Review Findings📄
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
sendInvoiceBarcodeEmailhelper ininvoices.tsmixes QR generation logic and a large inline HTML template inside the resolver; consider extracting the email template and QR table rendering into a separate utility/module and guard against missinginvoice.emailbefore callingsendTRPCMessage. generateFilterQuery/buildKindQuerynow run multipledistinctqueries per request and again insideinvoicesTotalCountfor each kind, which can become N+1 style DB calls; consider caching thebuildKindQueryresult per request or restructuring the aggregation to avoid repeatedTransactions/PaymentMethodslookups for each kind.- In
InvoiceStatusFilterandInvoiceKindFilter,setQueries({ status: ... })/setQueries({ kind: ... })may overwrite other query params (e.g.searchValueor the other filter); ifuseMultiQueryStatedoes not merge by default, switch to an updater function that preserves existing keys when applying a single filter.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `sendInvoiceBarcodeEmail` helper in `invoices.ts` mixes QR generation logic and a large inline HTML template inside the resolver; consider extracting the email template and QR table rendering into a separate utility/module and guard against missing `invoice.email` before calling `sendTRPCMessage`.
- `generateFilterQuery`/`buildKindQuery` now run multiple `distinct` queries per request and again inside `invoicesTotalCount` for each kind, which can become N+1 style DB calls; consider caching the `buildKindQuery` result per request or restructuring the aggregation to avoid repeated `Transactions`/`PaymentMethods` lookups for each kind.
- In `InvoiceStatusFilter` and `InvoiceKindFilter`, `setQueries({ status: ... })` / `setQueries({ kind: ... })` may overwrite other query params (e.g. `searchValue` or the other filter); if `useMultiQueryState` does not merge by default, switch to an updater function that preserves existing keys when applying a single filter.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| } from 'erxes-api-shared/utils'; | ||
| import { IContext } from '~/connectionResolvers'; | ||
| import { IInvoice } from '~/modules/payment/@types/invoices'; | ||
| import { IInvoice, IInvoiceDocument } from '~/modules/payment/@types/invoices'; |
| import { | ||
| IconProgressCheck, | ||
| IconSearch, | ||
| IconWallet, | ||
| } from '@tabler/icons-react'; |
|



Summary by Sourcery
Add QR-code based invoice ticketing, email delivery, and scanning support across payment APIs and UI.
New Features:
Enhancements:
Summary by CodeRabbit