Assistant Billing

Stripe Setup

Connect your Stripe account so customers pay you directly through your project.

Step 1: Create a Stripe Account

Sign up at stripe.com. Use test mode (sk_test_*, pk_test_*) for development.

Step 2: Add API Keys

Go to Settings > Stripe in the Dashboard and enter your Stripe keys.

FieldValueRequired
Secret Keysk_test_* or rk_live_*Yes
Publishable Keypk_test_* or pk_live_*Optional

Navigate to your project's Settings page and fill in the Stripe section.

All Stripe keys are encrypted with AES-256-GCM before storage.

Step 3: Configure Webhook

Create a webhook endpoint in the Stripe Dashboard (Developers > Webhooks > Add endpoint).

Endpoint URL:

https://stripe.assistant-billing.dev/webhook/customer/<your_project_id>

Replace <your_project_id> with your project ID (found in Dashboard Settings, starts with pj_).

Events to subscribe:

EventAction
checkout.session.completedCredit customer balance after payment
charge.refundedReverse balance on refund
charge.dispute.createdDeduct balance on dispute
charge.dispute.closedReinstate balance if dispute won

Copy the Signing secret (whsec_...) and add it to your project settings:

Enter the webhook secret in Settings > Stripe > Webhook Secret.

Step 4: Set Pricing

Configure your margin on customer top-ups.

SettingDescriptionDefault
MarkupYour margin on each top-up0%
Platform feeGoes to Assistant Billing (minimum 5%)5%

Fee Breakdown

base_amount   = what the customer requested
markup        = base_amount * markup_percentage
platform_fee  = base_amount * platform_fee_percentage
total_charged = base_amount + markup + platform_fee

Example: $10 top-up with 10% markup + 5% platform fee
  Base:         $10.00  (credited to balance)
  Markup:       $1.00   (your margin)
  Platform fee: $0.50   (Assistant Billing)
  Total:        $11.50  (charged to customer)

Step 5: Test the Flow

Create a checkout session and complete payment using Stripe test cards.

import { BillingClient } from "@assistant-billing/sdk"
 
const billing = new BillingClient({
  platformKey: "sk_pj_live_abc123",
  workspaceId: "ws_team_123",
  userId: "user_456",
})
 
// Create checkout
const checkout = await billing.checkout.create({
  amount: 10,
  successUrl: "https://yourapp.com/billing?status=success",
  cancelUrl: "https://yourapp.com/billing?status=cancelled",
})
 
console.log(checkout)
// → {
//     url: "https://checkout.stripe.com/c/pay/...",
//     base_amount: "10.00",
//     platform_fee: "0.50",
//     markup: "1.00",
//     total_amount: "11.50"
//   }
 
// Open checkout.url and pay with test card: 4242 4242 4242 4242
 
// Verify balance was credited
const balance = await billing.wallet.getBalance()
console.log(balance)
// → { currency: "USD", amount: "10.00" }

Troubleshooting

ErrorFix
"Stripe is not configured for this project"Add Stripe keys in Settings
Webhook returns 400 "Invalid signature"Re-copy whsec_... from Stripe Dashboard
Webhook returns 404 "Gateway not found"Check project ID in the webhook URL
Customer paid but balance unchangedCheck Stripe Dashboard > Webhooks > Recent deliveries for errors