Skip to content

Conversation

@dalyathan
Copy link
Collaborator

@dalyathan dalyathan commented Jan 23, 2026

Description

  • Store credit in wallets conneted to customers

Checklist

📌 Always:

  • Set a clear title
  • I have checked my own PR

👍 Most of the time:

  • Added or updated test cases
  • Updated the README

📦 For publishable packages:

  • Increased the version number in package.json
  • Added changes to the CHANGELOG.md

@dalyathan dalyathan changed the title Basic Store Credit Plugin Basic Store Credit Plugin Setup Jan 23, 2026
@dalyathan dalyathan marked this pull request as draft January 23, 2026 22:00
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

Walkthrough

Introduces a new Vendure plugin for store credit wallet functionality, including wallet and adjustment entities, GraphQL API extensions for both shop and admin, a wallet service with balance management, resolvers, and supporting configuration files for testing and linting.

Changes

Cohort / File(s) Summary
Plugin Configuration & Setup
packages/vendure-plugin-store-credit/eslint.config.js, packages/vendure-plugin-store-credit/vitest.config.js, packages/vendure-plugin-store-credit/test/dev-server.ts
ESLint and Vitest configurations with SWC plugin support; dev server bootstrapping Vendure test environment with StoreCreditPlugin and dependent plugins
Core Plugin Definition
packages/vendure-plugin-store-credit/src/store-credit.plugin.ts, packages/vendure-plugin-store-credit/src/index.ts
Main plugin class registering entities, services, and API extensions for shop and admin; root export for plugin access
GraphQL API Definitions
packages/vendure-plugin-store-credit/src/api/api-extensions.ts
GraphQL scalar types and schema extensions defining Wallet, WalletAdjustment, and mutation operations for both shop and admin APIs
GraphQL Resolvers
packages/vendure-plugin-store-credit/src/api/wallet.resolver.ts, packages/vendure-plugin-store-credit/src/api/customer-entity.resolver.ts
Resolvers for wallet mutations (create, adjust balance) and customer wallet relation loading
Data Entities
packages/vendure-plugin-store-credit/src/entities/wallet.entity.ts, packages/vendure-plugin-store-credit/src/entities/wallet-adjustment.entity.ts
Wallet entity with channel awareness and customer relation; WalletAdjustment entity for ledger tracking with cascade delete
Business Logic
packages/vendure-plugin-store-credit/src/services/wallet.service.ts
Wallet operations: creation with initial balance and CREDIT/DEBIT balance adjustments with error handling for missing wallets and insufficient funds
Constants
packages/vendure-plugin-store-credit/src/constants.ts
Plugin symbols and logger context exports

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Linked issue #123 concerns Picqer integration changes (API endpoint and channel default language), but this PR implements a Store Credit plugin with no connection to Picqer integration. Either link the correct issues relevant to the Store Credit plugin or remove the unrelated Picqer issue #123 from this PR.
Out of Scope Changes check ⚠️ Warning All changes are in-scope for a Store Credit plugin setup; however, the linked issue #123 about Picqer is completely unrelated to this codebase. Remove issue #123 linking or replace with issues specifically describing Store Credit plugin requirements that match the implementation.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: setting up a new Store Credit plugin with basic scaffolding and entity/service implementations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The description mentions store credit wallets connected to customers, which aligns with the changeset that introduces a StoreCreditPlugin with Wallet and WalletAdjustment entities.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/store-credit

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@packages/vendure-plugin-store-credit/src/api/customer-entity.resolver.ts`:
- Around line 14-23: The wallets resolver returns wallets for the parent
Customer without verifying the requester owns that customer; update the
wallets(`@Ctx`() ctx: RequestContext, `@Parent`() customer: Customer) method to
check that ctx.session?.customer?.id === customer.id (or equivalent current user
id) and throw an authorization error (e.g., ForbiddenError/Unauthorized) if it
does not match, before calling this.connection.getRepository(...).find(...), so
only the owning customer can access their wallets.

In `@packages/vendure-plugin-store-credit/src/api/wallet.resolver.ts`:
- Around line 13-25: The GraphQL mutations createWallet and
adjustBalanceForWallet are using `@Args`() which passes the whole args object ({
input: ... }) to walletService; change the decorators to `@Args`('input') so the
resolver receives the unwrapped input object expected by WalletService (update
the parameters on createWallet and adjustBalanceForWallet to accept the input
type via `@Args`('input') and pass that input directly to
this.walletService.createWallet(...) and
this.walletService.adjustBalanceForWallet(...)).

In `@packages/vendure-plugin-store-credit/src/services/wallet.service.ts`:
- Around line 70-74: The ledger currently always saves a positive amount via
adjustmentRepo.create(... { wallet: { id: input.walletId } as Wallet, amount:
input.amount }), losing debit/credit direction; change this to persist either a
signed amount or the adjustment type: compute a signedAmount (e.g. signedAmount
= input.type === 'DEBIT' ? -Math.abs(input.amount) : Math.abs(input.amount)) and
pass amount: signedAmount into adjustmentRepo.create, or include a type field
(e.g. type: input.type or isDebit: boolean) on the created entity so
adjustmentRepo.save/adjustmentRepo.create records the direction alongside the
magnitude.
- Around line 19-31: The createWallet method is creating a Wallet without
required non-null fields and misassigning balances; before saving the new Wallet
instance (in createWallet) set channel and currencyCode to valid values (e.g.,
derive from ctx or input) and set balance to the numeric input.initialBalance
(use the same source as initialAmount), ensuring initialAmount and amount
reflect intended semantics; update the Wallet construction or assign properties
on the Wallet instance (referencing createWallet, Wallet, input.initialBalance,
initialAmount, amount, balance, channel, currencyCode) so the DB insert includes
channel and currencyCode and balance is initialized correctly.
🧹 Nitpick comments (1)
packages/vendure-plugin-store-credit/test/dev-server.ts (1)

20-21: Inconsistent import style.

testConfig is dynamically required while other exports from @vendure/testing are statically imported at the top. Consider importing testConfig statically with the other imports for consistency.

@dalyathan
Copy link
Collaborator Author

dalyathan commented Jan 29, 2026

It has been a while since I worked on the plugins, sorry I had missed so many minor details

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