npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

medusa-wallet

v0.0.7

Published

Production wallet/store-credit ledger for Medusa v2 with cart reserves, gift cards, claim codes, and refunds.

Readme

medusa-wallet

Production-oriented customer wallet / store-credit ledger for Medusa v2: integer minor-unit ledger, cart credit-line reserves, gift cards, claim codes, refunds, reconcile, and Razorpay top-up.

Features

  • Integer minor units (BIGINT) only — never float/DECIMAL for money
  • Immutable ledger + compensating reverse(); idempotent mutations return the original result
  • Atomic conditional balance updates (WHERE available >= amount)
  • Cart wallet credits: reserve → commit / release with hold TTL + multi-pod FOR UPDATE SKIP LOCKED job
  • Gift cards backed by anonymous wallets (create, cart apply, purchase on order.placed, expiry)
  • Credit lots with credit_source + optional expiry (FIFO spend)
  • Claimable anonymous wallet / gift-card codes (one-shot, Redis/DB rate-limited; requires has_account)
  • Refunds via negative order credit lines + wallet-first PSP saga (wallet_refund_intent)
  • Admin create / credit / debit / reverse (reason + audit) + reconcile + refund-intent retry + customer widget
  • Full-pay checkout via wallet payment provider (pp_wallet_*) still supported
  • Razorpay top-up (initiate, complete, webhook)

Installation

npm install medusa-wallet
import { defineConfig, Modules } from "@medusajs/framework/utils"

export default defineConfig({
  plugins: [
    {
      resolve: "medusa-wallet",
      options: {
        enabled: true,
        ledgerWrites: true,
        checkoutEnabled: true,
        topUpEnabled: true,
        cartCreditsEnabled: true,
        giftCardsEnabled: true,
        defaultCurrency: "INR",
        holdTtlMinutes: 90,
        // redisUrl: process.env.REDIS_URL,
        razorpay: {
          keyId: process.env.RAZORPAY_KEY_ID,
          keySecret: process.env.RAZORPAY_KEY_SECRET,
          webhookSecret:
            process.env.RAZORPAY_WEBHOOK_SECRET ||
            process.env.WALLET_RAZORPAY_WEBHOOK_SECRET,
        },
      },
    },
  ],
  modules: {
    [Modules.PAYMENT]: {
      resolve: "@medusajs/medusa/payment",
      options: {
        providers: [
          {
            resolve: "medusa-wallet/providers/wallet",
            id: "wallet",
            options: {},
          },
        ],
      },
    },
  },
})
npx medusa db:migrate

Checkout paths

  1. Wallet partial: POST /store/carts/:id/wallet-credits → credit line reference=wallet
  2. Gift card: POST /store/carts/:id/gift-cards { code } → credit line reference=gift-card
  3. Full-pay: wallet payment provider only

On complete-cart, reserves for wallet and gift-card lines are committed before payment auth.

Store APIs

| Method | Path | Description | |---|---|---| | GET | /store/wallet | Alias of balance | | GET | /store/wallet/balance | available / reserved / total + expiry hints | | GET | /store/wallet/transactions | History | | GET | /store/wallet/gift-cards | List gift cards assigned to the customer (claimable + claimed) | | POST | /store/wallet/claim | Claim code (wallet or gift-card backed) | | POST/DELETE | /store/carts/:id/wallet-credits | Apply / remove wallet credit | | POST/DELETE | /store/carts/:id/gift-cards | Apply / remove gift card | | GET | /store/gift-cards/:code | Lookup gift card + balance | | GET/POST | /store/wallet/top-up/* | Razorpay top-up |

Admin APIs

| Method | Path | Description | |---|---|---| | GET/POST | /admin/wallets | List / create accounts | | POST | /admin/wallets/credit | debit | Requires reason | | POST | /admin/wallets/reverse | Compensating reverse of a ledger entry | | GET/POST | /admin/wallets/refund-intents | List stuck intents / retry PSP | | GET|POST | /admin/wallets/:id/reconcile | MATCH / MISMATCH | | GET/POST | /admin/gift-cards | List / create gift cards | | GET/POST | /admin/gift-cards/:id | Retrieve / update |

Admin UI: Wallets, Gift cards, customer wallet widget. Transaction reverse action on wallet detail.

Refunds (wallet-first saga)

  1. Negative order credit line → create wallet_refund_intent (split via suggestWalletRefundAmount)
  2. Credit wallet portion (idempotent per OCL id)
  3. If psp_amount > 0 → refundPaymentWorkflow for remainder → mark complete
  4. On PSP failure → stay wallet_credited; resume job retries; admin can reverse (clawback) or retry

Jobs

| Job | Role | |---|---| | release-expired-wallet-holds | TTL expire with SKIP LOCKED | | resume-stuck-wallet-refund-intents | Retry PSP remainder |

Tests

npm test

Includes crash/retry / dual-expire / gift-card dual-reserve / refund idempotency suites.