Skip to content

Fix payment reminder payable total - #501

Merged
BleedingDev merged 3 commits into
masterfrom
codex/fix-payment-reminder-total
Jul 2, 2026
Merged

Fix payment reminder payable total#501
BleedingDev merged 3 commits into
masterfrom
codex/fix-payment-reminder-total

Conversation

@BleedingDev

@BleedingDev BleedingDev commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

Payment reminder emails could show a different total than the attached receipt. The workflow reloaded the order for the PDF, but the email payload still used raw order.total instead of the current payable summary total.

What changed

The reminder notification total is formatted from the freshly fetched order using the same summary-aware total logic.

Evidence

Added workflow coverage where raw order.total is stale and summary.current_order_total is current; notification data uses the current formatted total.

Summary by CodeRabbit

  • New Features

    • Order payment reminder notifications now show the total in a consistent localised currency format, with a fallback to the original input value when needed.
  • Tests

    • Added coverage for reminder total calculation, including different order data shapes and fallback scenarios.
    • Verified the notification payload uses the expected order details when building the reminder.

@semanticdiff-com

semanticdiff-com Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  apps/medusa-be/src/workflows/send-order-payment-reminder.ts  22% smaller
  apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts  0% smaller

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
new-engine-ui-storybook Ready Ready Preview, Comment Jul 2, 2026 10:33am

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@BleedingDev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 43 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 899f9025-7b39-48fa-b80f-96cf0df5e344

📥 Commits

Reviewing files that changed from the base of the PR and between b25ba2b and 74cc4aa.

📒 Files selected for processing (1)
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts

Walkthrough

The send-order-payment-reminder workflow now computes the notification's total via a formatTotal(order) helper, falling back to input.total, and the QueryOrder type is updated to intersect OrderReceiptOrder with PaymentReminderOrder. New unit tests validate total resolution across multiple scenarios.

Changes

Payment reminder total formatting

Layer / File(s) Summary
Workflow total formatting and typing
apps/medusa-be/src/workflows/send-order-payment-reminder.ts
Imports formatTotal and PaymentReminderOrder, updates QueryOrder typing, and computes notification total via formatTotal(order) ?? input.total.
Unit tests for total resolution
apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
Adds mocks for the workflow SDK and dependencies, and tests verifying data.total formatting from order summary values and input fallback across scenarios.

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant WorkflowStep as build-order-payment-reminder-notification
  participant Query as container.query
  participant formatTotal

  Test->>Query: mock order summary/total response
  Test->>WorkflowStep: invoke step with input.total
  WorkflowStep->>Query: fetch order graph data
  WorkflowStep->>formatTotal: compute formatted total from order
  formatTotal-->>WorkflowStep: formatted total or undefined
  WorkflowStep-->>Test: notification payload with data.total
Loading

Possibly related PRs

  • TechsioCZ/new-engine#375: Introduced the send-order-payment-reminder workflow and unit tests that this PR directly updates to use formatTotal instead of raw order.total.
  • TechsioCZ/new-engine#393: Earlier changes to utils/order-payment-reminders.ts defining PaymentReminderOrder and formatTotal, which this PR now consumes in the workflow.

Poem

A rabbit hopped through order fields so wide,
Found formatTotal waiting there inside,
With PaymentReminderOrder types aligned just right,
And tests to check each total, day or night,
A tidy fix: and test: for a currency delight! 🥕

🚥 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 matches the change to use the current payable total for payment reminder emails.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-payment-reminder-total
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/fix-payment-reminder-total

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e09e0f464

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/medusa-be/src/workflows/send-order-payment-reminder.ts Outdated
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a stale-total bug in payment reminder emails: the step previously sent order.total (a raw number from the workflow input) while the PDF receipt used the freshly queried summary total. The notification data now uses formatTotal(order) ?? input.total, mirroring the summary-aware logic already used elsewhere.

  • Core fix (send-order-payment-reminder.ts): replaces total: order.total with total: formatTotal(order) ?? input.total, giving precedence to summary.current_order_totalsummary.original_order_totalorder.total, and falling back to the input string when none are available.
  • Tests (send-order-payment-reminder.unit.spec.ts): new unit spec covers the three fallback levels plus the full-null fallback path; tests live under src/workflows/__tests__/ which is included by the vitest.config.ts unit include glob.

Confidence Score: 5/5

Safe to merge — the change is a targeted single-line fix in the notification data assembly, backed by a new unit spec that exercises all fallback branches.

The only logic change is replacing order.total with formatTotal(order) ?? input.total. Both the utility function and the fallback chain are straightforward, the ORDER_PAYMENT_REMINDER_RECEIPT_FIELDS list already includes summary.* and currency_code, and the test file is correctly picked up by the vitest config.

No files require special attention.

Important Files Changed

Filename Overview
apps/medusa-be/src/workflows/send-order-payment-reminder.ts Replaces order.total with formatTotal(order) ?? input.total in notification data; also widens QueryOrder to include PaymentReminderOrder fields (summary, currency_code) needed by formatTotal.
apps/medusa-be/src/workflows/tests/send-order-payment-reminder.unit.spec.ts New unit spec verifying the summary-total precedence chain and the input-total fallback; correctly placed in the vitest src/workflows/**/__tests__/**/*.unit.spec.ts include glob.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Trigger as Workflow Trigger
    participant Step as buildOrderPaymentReminderNotificationStep
    participant Query as query.graph (Order)
    participant Receipt as OrderReceiptModuleService
    participant Email as sendNotificationStep

    Trigger->>Step: WorkflowInput (order_id, total: string?)
    Step->>Query: "graph({ entity: "order", fields: [..., "summary.*", "total", "currency_code"] })"
    Query-->>Step: order (with summary.current_order_total, total, currency_code)
    Step->>Receipt: generateOrderReceiptAttachment(order)
    Receipt-->>Step: PDF attachment
    Note over Step: formatTotal(order)<br/>= summary.current_order_total<br/>?? summary.original_order_total<br/>?? order.total<br/>→ formatted string (or undefined)
    Note over Step: total = formatTotal(order) ?? input.total
    Step->>Email: "CreateNotificationDTO { data: { total: formattedTotal }, attachments: [PDF] }"
    Email-->>Trigger: notification sent
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Trigger as Workflow Trigger
    participant Step as buildOrderPaymentReminderNotificationStep
    participant Query as query.graph (Order)
    participant Receipt as OrderReceiptModuleService
    participant Email as sendNotificationStep

    Trigger->>Step: WorkflowInput (order_id, total: string?)
    Step->>Query: "graph({ entity: "order", fields: [..., "summary.*", "total", "currency_code"] })"
    Query-->>Step: order (with summary.current_order_total, total, currency_code)
    Step->>Receipt: generateOrderReceiptAttachment(order)
    Receipt-->>Step: PDF attachment
    Note over Step: formatTotal(order)<br/>= summary.current_order_total<br/>?? summary.original_order_total<br/>?? order.total<br/>→ formatted string (or undefined)
    Note over Step: total = formatTotal(order) ?? input.total
    Step->>Email: "CreateNotificationDTO { data: { total: formattedTotal }, attachments: [PDF] }"
    Email-->>Trigger: notification sent
Loading

Reviews (3): Last reviewed commit: "Refactor payment reminder test mocks" | Re-trigger Greptile

Comment thread apps/medusa-be/src/workflows/send-order-payment-reminder.ts Outdated

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts`:
- Around line 84-120: The mock setup for graph, generateOrderReceiptAttachment,
and the container.resolve stub is duplicated between the single test and the
it.each cases, so extract a shared helper to centralize it. Add a small
createStepContainer(orderOverrides) helper (or equivalent) near
send-order-payment-reminder.unit.spec.ts and reuse it in both places, keeping
the existing dependency keys like "query", "logger", and "order_receipt" intact
while allowing per-scenario overrides.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0529f94d-d403-4a1b-a704-43815b1e24fb

📥 Commits

Reviewing files that changed from the base of the PR and between f6fac4e and b25ba2b.

📒 Files selected for processing (2)
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Greptile Review
  • GitHub Check: main
⚠️ CI failures not shown inline (1)

GitHub Check: Kilo Code Review: Kilo Code Review failed

Conclusion: failure

View job details

Review failed: The message could not be delivered
🧰 Additional context used
📓 Path-based instructions (9)
apps/medusa-be/src/workflows/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Place business logic workflows under apps/medusa-be/src/workflows

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
apps/medusa-be/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/medusa-be/CLAUDE.md)

apps/medusa-be/**/*.{ts,tsx}: Use TypeScript for type checking - run npx tsc --noEmit for validation
Forbidden: Non-null assertions (!) - always use type guards and validation instead
Annotate generic field access with explicit unknown type before type guards - const v: unknown = result[field]
Don't use as Type without validation - always validate before casting
Use Modules.* and ContainerRegistrationKeys.* constants instead of hardcoding strings
Batch operations with CHUNK_SIZE to avoid unbounded operations
Extract pure functions to separate files for testability without runtime dependencies

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
apps/medusa-be/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/medusa-be/CLAUDE.md)

apps/medusa-be/**/*.{ts,tsx,js,jsx}: Use Biome linter with ultracite preset - run bunx biome check --write . and always use braces in conditionals
Comments should explain 'why', never 'what' - use self-documenting code via clear naming
Always use const per declaration - const a = 1; const b = 2 is correct, one variable per line
Use nullish coalescing (??) operator instead of logical OR (||) for default values

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
apps/medusa-be/src/workflows/*.ts

📄 CodeRabbit inference engine (apps/medusa-be/CLAUDE.md)

apps/medusa-be/src/workflows/*.ts: Workflows: Use createWorkflow() and createStep() for multi-step business logic - cannot reassign/iterate variables in workflow body
Use transform() for data manipulation in workflows - limit to data transformations, not external side effects
Use when().then() for conditionals in workflows instead of imperative logic
Use useQueryGraphStep() for Query operations within workflows
Workflows using locks: Use acquireLockStep() and releaseLockStep() - auto-releases on error

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
apps/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Import UI components using the @techsio/ui-kit namespace, not @libs/ui, for runtime apps

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Run Biome linting and formatting only on changed files using 'bunx biome check --write path/to/file'

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
apps/medusa-be/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Medusa backend custom logic should be organized in api/, modules/, workflows/, admin/, subscribers/, and jobs/ directories under apps/medusa-be/src/

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
apps/**/!(medusa-be)/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use modern React patterns and React 19 for frontend applications in the monorepo

Files:

  • apps/medusa-be/src/workflows/send-order-payment-reminder.ts
  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
**/*.{test,spec}.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use Vitest for running tests in backend and UI library projects

Files:

  • apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts
🔇 Additional comments (3)
apps/medusa-be/src/workflows/send-order-payment-reminder.ts (2)

19-22: LGTM!

Also applies to: 156-156


35-35: 🎯 Functional Correctness

Double-check QueryOrder validation isQueryOrder only checks id, total, and customer_id, but QueryOrder also includes display_id and other receipt fields from the query.

apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts (1)

1-250: LGTM!

Coverage nicely exercises the current_order_totaloriginal_order_totaltotalinput.total precedence chain.

Comment thread apps/medusa-be/src/workflows/__tests__/send-order-payment-reminder.unit.spec.ts Outdated
@BleedingDev
BleedingDev merged commit a8f6395 into master Jul 2, 2026
6 of 7 checks passed
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 0.21.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant