Skip to content

StockerMC/Copped-Backend

Repository files navigation

ClipStakes Backend

Cloudflare Workers backend for clip attribution with persistent wallet identity + reward ledger balances.

Quick Start

bun install
bun run dev
bun run deploy

Run tests:

bun run test

Environment

Copy .env.example values into your deployed worker secrets.

Required:

  • DATABASE_URL
  • SHOPIFY_WEBHOOK_SECRET

Wallet pass provider (optional, server-side only):

  • WALLETWALLET_API_KEY
  • WALLETWALLET_BASE_URL (defaults to https://api.walletwallet.dev)
  • PUBLIC_API_BASE_URL (recommended, e.g. https://api.clipstakes.app)
  • PUBLIC_VIDEO_BASE_URL (optional, e.g. https://cdn.clipstakes.app/clips)

wallet.pass_url is always generated by the backend and points to GET /wallet/:wallet_code/pass. When WalletWallet is unavailable, local pass signing requires:

  • WALLET_PASS_TYPE_ID
  • WALLET_TEAM_ID
  • WALLET_CERT (base64 PKCS#12)
  • WALLET_CERT_PASSWORD
  • WALLET_WWDR_CERT (PEM or base64 PEM intermediate cert)

Optional pass branding:

  • WALLET_ORGANIZATION_NAME
  • WALLET_PASS_DESCRIPTION
  • WALLET_PASS_LOGO_TEXT

Database Migration

Apply migrations in order, including:

sql/migrations/20260307_coupon_wallet.sql
sql/migrations/20260307_wallet_ledger.sql

The wallet-ledger migration adds:

  • creator_wallets (one wallet identity per user)
  • conversions (provider order dedupe)
  • reward_transactions (credits + debits ledger with idempotency key)

API Notes

Device identity is anonymous via request header:

X-Device-ID: <stable-device-id>

Primary reward flow:

  • POST /clips creates the clip and credits clip_published (+500 cents).
  • POST /conversions and POST /conversions/dev credit every unique conversion (+500 cents) even after 8 hours.
  • 8-hour window controls push urgency only (push.within_window), not reward eligibility.
  • GET /rewards/me returns wallet identity, balances, and recent ledger transactions.
  • POST /wallet/redeem debits balance for cashier/POS redemption.
  • GET /wallet/:wallet_code/balance supports scanner-side balance lookup.

Compatibility:

  • POST /upload and POST /upload-url are both supported.
  • upload_url and video_url are absolute HTTPS URLs generated by the backend.
  • Legacy coupon route /coupons/redeem remains available for previously issued coupons.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors