mcpField
T
tinyship-payment

tinyship-payment

github.com/tinyshipcnDevelopment583 installsUpdated 2w ago
Repository

About tinyship-payment

A payment integration guide for developers building with TinyShip. It covers provider selection, pricing plans, webhooks, local testing, and optional AI credit configuration.

Key features

  1. 01Choose providers by target market
  2. 02Configure static or dynamic pricing plans
  3. 03Set up subscriptions, one-time payments, and credit packs
  4. 04Configure webhooks for local development
  5. 05Set optional AI credit consumption

Use cases

  1. 01Select a provider for a target market
  2. 02Adjust pricing plans through the admin interface
  3. 03Debug payment webhooks and verify test payments locally

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/tinyshipcn/tinyship-skills --skill tinyship-payment

After installing, type/tinyship-paymentin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
alipay-setup.md
paypal-setup.md
stripe-setup.md
wechat-pay-setup.md

Details

From the project README

TinyShip Payment Integration

Guide for setting up payment providers in TinyShip.

Provider Selection

Ask the user about their target market to recommend providers:

MarketRecommendedSubscription Support
ChinaWeChat Pay, AlipayOne-time + credits only
GlobalStripeFull (one-time, recurring, credits)
Global (easy onboard)CreemFull (one-time, recurring, credits)
Global (alt)PayPalFull (one-time, recurring, credits)
Global (MoR/tax-free)Dodo PaymentsFull (Merchant of Record)
Global (MoR/tax-free)Waffo PancakeFull (Merchant of Record; no CNY for subscriptions)

Setup by Provider

Read the relevant reference file for detailed steps:

For Creem, Dodo Payments, and Waffo Pancake, read docs/user-guide/payment/creem.md, docs/user-guide/payment/dodo.md, and docs/user-guide/payment/waffo.md from the TinyShip repo.

Waffo specifics to keep in mind: API keys are bound to Test or Production at creation time (no TEST_MODE switch), webhook verification uses an RSA public key (the SDK has Test/Prod keys built in), and each plan needs a waffoProductId (PROD_xxx).

Configure Pricing Plans

After setting up a provider, you can configure plans in two ways:

Option A: Static Plans (default)

Define plans directly in config/payment.ts:

plans: {
  monthly: {
    provider: 'stripe',           // must match your configured provider
    id: 'monthly',
    amount: 10,
    currency: 'USD',
    duration: { months: 1, type: 'recurring' },
    stripePriceId: 'price_xxx',   // provider-specific ID (required for Stripe)
    i18n: {
      'en': {
        name: 'Monthly Plan',
        description: 'Full access for one month',
        duration: 'month',
        features: ['All features', 'Priority support']
      },
      'zh-CN': {
        name: '月度订阅',
        description: '一个月完整访问',
        duration: '月',
        features: ['所有功能', '优先支持']
      }
    }
  }
}

Plans automatically appear on the /pricing page.

Option B: Dynamic Pricing (admin-managed)

Set PRICING_MODE="dynamic" in .env to enable. Plans are then stored in the database and managed via the admin panel at /admin/pricing — prices can be adjusted anytime without code changes or redeployment.

Fresh projects already include the pricing_plan table in the schema, so a normal database init covers it. Projects upgraded from older versions must add the table first:

pnpm db:push          # PostgreSQL
pnpm db:push:sqlite   # SQLite / D1

Dynamic pricing adds:

  • Creating/editing/reordering plans from the admin UI
  • Markdown-formatted feature lists
  • Strikethrough pricing (original price)
  • Locale-based plan visibility
  • One-click import of existing static plans into the database

To migrate existing static plans: enable dynamic mode, open /admin/pricing, click "Import from Config", verify each plan's provider IDs, then run a test payment. Switch back anytime by setting PRICING_MODE="static" and restarting — dynamic plan data is preserved.

See docs/user-guide/payment/dynamic-pricing.md in the TinyShip repo for full details.

Plan Types
Typeduration.typeProviders
One-timeone_timeAll
SubscriptionrecurringStripe, Creem, PayPal, Dodo, Waffo
Credit packcreditsAll (set duration.credits: 100)

Webhook Setup (Local Development)

Payment providers need to send webhooks to your app. For local development:

  1. Install a tunnel tool:
# Option A: ngrok
ngrok http 7001

# Option B: Cloudflare Tunnel
cloudflared tunnel --url http://localhost:7001
  1. Use the tunnel URL as your webhook endpoint
  2. Configure the webhook URL in the provider's dashboard

Webhook endpoints are at: {BASE_URL}/api/payment/webhook/{provider} (e.g., /api/payment/webhook/stripe)

Credit System (Optional)

To enable AI credit consumption, configure config/credits.ts:

credits: {
  consumptionMode: 'dynamic',          // 'fixed' or 'dynamic'
  fixedChatCost: 10,                   // credits per chat (fixed mode)
  dynamicChatCostPerKiloToken: 1,      // credits per 1K tokens (dynamic mode)
  modelMultipliers: {
    'qwen3.7-flash': 1.0,
    'gpt-5.6-sol': 2.0,
    'default': 1.0
  }
}

Add a credit purchase plan alongside subscription plans:

credits100: {
  provider: 'stripe',
  id: 'credits100',
  amount: 10,
  currency: 'USD',
  duration: { type: 'credits', credits: 100 },
  stripePriceId: 'price_xxx',
  i18n: { /* ... */ }
}

Verify

  1. Start the dev server
  2. Visit /pricing — plans should display
  3. Click a plan and complete a test payment (use sandbox/test mode)
  4. Check /dashboard — order should appear
  5. For subscriptions, verify /api/subscription/status returns active status

Reference Files in TinyShip Repo

  • config/payment.ts — payment provider and plan configuration
  • config/credits.ts — credit system configuration
  • libs/payment/AGENTS.md — payment library architecture
  • libs/credits/AGENTS.md — credit system architecture
  • docs/user-guide/payment/overview.md — payment documentation index
  • docs/user-guide/payment/waffo.md — Waffo Pancake setup (MoR, hosted checkout)
  • docs/user-guide/payment/dynamic-pricing.md — dynamic pricing admin guide
  • docs/user-guide/payment-testing.md — testing and webhook debug guide

Comments

Markdown supported