← Back to demo home

RCJ Stack β€” User Manual

An all-in-one "build site + collect payment + customer support + analytics" system on Cloudflare Pages, ready to use out of the box.

0. What is this

RCJ Stack is an integrated system based on Cloudflare Pages for "site building + payment + customer support + data analytics", ready to use out of the box:

The whole stack runs on Cloudflare β€” no ICP filing, global CDN, generous free quota, no server of your own needed.

1. Deploy

Method A: Direct Upload (recommended, simplest)

Prerequisites: Node.js and wrangler installed.

npm i -g wrangler          # or: npx wrangler
wrangler login             # first time: bind your Cloudflare account (browser auth)
cd project-dir
wrangler pages deploy . --project-name <your-project>

Note: wrangler.toml sets pages_build_output_dir = "." β€” no build step, just upload static files + Functions.

Method B: Git auto-deploy

Cloudflare Console β†’ Workers & Pages β†’ Create β†’ Connect Git repo β†’ pick repo & branch β†’ Save. Every git push then deploys automatically.

Multi-account tip: to deploy to a non-default Cloudflare account, override with env vars: CLOUDFLARE_API_TOKEN=<token> CLOUDFLARE_ACCOUNT_ID=<id> wrangler pages deploy . --project-name <name>

2. Bind a D1 database (data storage)

  1. Create the database:
    wrangler d1 create <db-name>
    # get database_id from the output
  2. Write it into wrangler.toml:
    [[d1_databases]]
    binding = "DB"
    database_name = "<db-name>"
    database_id = "<database_id>"
  3. Table schemas (orders / support_threads / support_messages) are created automatically on first run β€” no manual table creation needed.

3. Configure products & pricing

Edit ITEMS at the top of functions/api/paypal/_lib.js:

export const ITEMS = {
  'consulting': {
    name: 'Consulting', price: 39,
    desc: 'A 1:1 consulting session.',
    i18n: { zh: { name: 'ε’¨θ―’ζœεŠ‘', desc: '一对一咨诒。' },
            ja: { name: 'コンァルティング', desc: '1:1 コンァル。' } },
  },
  // ...
};
FieldMeaning
priceList price (your settlement currency, USD by default)
depositDeposit charged online now; omit to auto-calc by DEPOSIT_RATE
balanceBalance charged on delivery (auto = price βˆ’ deposit)
i18nChinese / Japanese display names & descriptions

Other tunable constants (same file):

After editing, re-run wrangler pages deploy . β€” the storefront and admin read the new list live.

4. Configure secrets

Set via Cloudflare Console (Settings β†’ Environment variables) or command line:

wrangler pages secret put PAYPAL_CLIENT_ID
wrangler pages secret put PAYPAL_CLIENT_SECRET
wrangler pages secret put PAYPAL_MODE        # sandbox or live
wrangler pages secret put TG_BOT_TOKEN        # optional: Telegram notifications
wrangler pages secret put TG_CHAT_ID
wrangler pages secret put ADMIN_PASSWORD      # /admin login password (required)
VariableRequiredDescription
PAYPAL_CLIENT_IDYesPayPal app Client ID
PAYPAL_CLIENT_SECRETYesPayPal app Secret
PAYPAL_SANDBOX_CLIENT_IDNoSandbox-only ID (falls back to above if blank)
PAYPAL_SANDBOX_CLIENT_SECRETNoSandbox-only Secret
PAYPAL_MODEYessandbox (test) / live (production)
PAYPAL_CURRENCYNoForce settlement currency, e.g. CNY
PAYPAL_CNY_ENABLEDNotrue to enable RMB (requires PayPal account supporting RMB)
TG_BOT_TOKENNoTelegram Bot Token β€” new orders / new messages push in real time
TG_CHAT_IDNoTelegram chat ID to receive notifications
ADMIN_PASSWORDYesAdmin dashboard login password
ADMIN_KEYNoBackup API Key
RESEND_API_KEYNoEmail notifications (Resend)
NOTIFY_EMAILNoEmail to receive notifications
EMAIL_FROMNoFrom address
To switch test / production, only change the PAYPAL_MODE variable.

5. PayPal payment config

6. Telegram support notifications

  1. Find @BotFather to create a Bot, get the Token β†’ fill TG_BOT_TOKEN.
  2. Send a message to @userinfobot, get your chat_id β†’ fill TG_CHAT_ID.
  3. After setup: every new order, every new support message is pushed to your Telegram in real time.
Important: use your own Bot, don't mix with the demo Bot; before going live be sure to swap in your own credentials.

7. Admin dashboard /admin

8. Analytics metrics explained

The dashboard (endpoint /api/analytics/data) aggregates from D1:

MetricMeaning
Revenuesum of cny_amount for orders with status = paid or deposit
Ordersall orders (incl. leads, pending)
Pendingcount of orders with status=pending
Leadscount of rows with source='lead'
Open / Closed sessionsopen / closed count of support conversations
14-day trendorders & revenue per day, to see the growth curve
Traffic analytics (PV / UV) is tracked separately by Cloudflare Web Analytics, not in D1.

9. Support system

10. Email notifications (optional)

After setting RESEND_API_KEY + NOTIFY_EMAIL, new orders / leads also send email.

Note: Resend's free quota is limited and easy to land in spam β€” important notifications should rely on Telegram.

11. FAQ

12. Upgrade & maintenance

Demo instance and real customers must each use a separate D1 + separate secrets, to avoid data cross-talk.
RCJ Stack β€” demo instance Β· no real payments Β· template source