Repository navigation
feat: add instant refunds through a new Ledger service - #1
ivanmilevtues wants to merge 4 commits into
Conversation
CodeBoarding reviewStatus: 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;
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| const ledgerEntry = this.ledger.creditRefund(order, amount, requestId); | ||
| const refund = { ...ledgerEntry, orderId, customerId: order.customerId, status: 'completed' }; |
There was a problem hiding this comment.
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 👍 / 👎.
| const availableCredit = this.ledger.balance(customerId, currency); | ||
| return `Store credit: ${formatMoney(availableCredit, currency)}`; |
There was a problem hiding this comment.
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 👍 / 👎.
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 testpasses 11 tests.npm run demoexecutes 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.