Skip to content

feat: add instant refunds through a new Ledger service - #1

Open
ivanmilevtues wants to merge 4 commits into
mainfrom
feat/instant-refunds
Open

ivanmilevtues wants to merge 4 commits into
mainfrom
feat/instant-refunds

Conversation

@ivanmilevtues

Copy link
Copy Markdown
Member

This change introduces a Ledger service for instant refunds and shows the available credit on the storefront account page. Payment settlements are also recorded in the ledger. The submitted test suite checks ledger balances, idempotency, currency isolation, and the revised refund flow.

This is a deliberately flawed demonstration PR in a synthetic commerce repository. Review it against the product contract in the README: refunds should return money to the original payment method, and the Storefront should reach money operations through Checkout. No real payments or customer data are involved.

Validation: npm test passes 11 tests. npm run demo executes the same €49 refund scenario as the baseline, making its changed outcome inspectable.

The CodeBoarding Action generates the architecture comparison from this code. Keep this PR open for the product demonstration.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

CodeBoarding review

Status: 4 changed components

See the full change in CodeBoarding.

graph LR
    n_Application_and_Commerce_Core["Application and Commerce Core"]
    n_Payment_Processing["Payment Processing"]
    n_Refund_Management["Refund Management"]
    n_Ledger_and_Store_Credit["Ledger and Store Credit"]
    n_Application_and_Commerce_Core -- "initializes and queries payments" --> n_Payment_Processing
    n_Application_and_Commerce_Core -- "initializes and delegates refund requests" --> n_Refund_Management
    n_Application_and_Commerce_Core -- "queries customer balance and instantiates ledger" --> n_Ledger_and_Store_Credit
    n_Payment_Processing -- "validates transaction amounts" --> n_Application_and_Commerce_Core
    n_Payment_Processing -- "posts settlement entries to" --> n_Ledger_and_Store_Credit
    n_Refund_Management -- "notifies customers and validates order amounts" --> n_Application_and_Commerce_Core
    n_Refund_Management -- "credits refunds into" --> n_Ledger_and_Store_Credit
    n_Ledger_and_Store_Credit -- "validates monetary amounts" --> n_Application_and_Commerce_Core
    n_Refund_Management -- "reverses payment transactions" --> n_Payment_Processing
    classDef added fill:#1f883d,stroke:#0b5d23,color:#ffffff;
    classDef modified fill:#bf8700,stroke:#7d4e00,color:#ffffff;
    classDef deleted fill:#cf222e,stroke:#82071e,color:#ffffff,stroke-dasharray:5 3;
    class n_Ledger_and_Store_Credit added;
    class n_Application_and_Commerce_Core,n_Payment_Processing,n_Refund_Management modified;
    linkStyle 2,4,6,7 stroke:#0b5d23,stroke-width:2px;
    linkStyle 8 stroke:#82071e,stroke-width:2px,stroke-dasharray:5 3;
Loading

download artifacts · run 39789420669

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T13:45:19.037321Z 0a99141 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 0a99141eec

ℹ️ 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 refunds/refund-service.js
Comment on lines +25 to +26
const ledgerEntry = this.ledger.creditRefund(order, amount, requestId);
const refund = { ...ledgerEntry, orderId, customerId: order.customerId, status: 'completed' };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore refunds to the original payment method

Every successful refund now posts store credit instead of calling PaymentService.refundOriginalPayment, violating the README's product contract. Both Storefront and Support mark the refund completed and reduce the remaining refundable amount without returning money to the customer's card. Running npm run demo confirms that the €49 refund produces no card reversals and a 4900-cent discrepancy in FinanceExport.reconcile(). Keep the original-payment reversal as the refund operation rather than replacing it with a ledger credit.

Useful? React with 👍 / 👎.

Comment on lines +17 to +18
const availableCredit = this.ledger.balance(customerId, currency);
return `Store credit: ${formatMoney(availableCredit, currency)}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Read account balances through Checkout

renderBalance now bypasses CheckoutApi.accountSummary and accesses Ledger directly, contrary to the README's explicit requirement that Storefront access money operations through Checkout. This also makes the existing new StorefrontAccount(checkout) construction misleading: it creates a separate, empty ledger, so the displayed balance ignores credits available through the supplied Checkout instance. Expose the currency-aware balance through Checkout and have the view consume that interface instead of owning another money-service dependency.

Useful? React with 👍 / 👎.

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