Skip to content

Repository files navigation

Cloudcore Ecom

CI

E-commerce starter for Cloudcore CMS. Adds products, subscriptions, Stripe, and PayPal to your CMS.

Not a standalone service — copy the source files into your CMS. One Worker, one database, one auth system.

Setup

1. Copy ecom files into your CMS

# Clone this repo
git clone https://github.com/cloudcore-cms/cloudcore-ecom.git
# Copy the source files into your CMS
cp -r cloudcore-ecom/src/* your-cms/src/ecom/
# Copy the migration
cp cloudcore-ecom/migrations/001_ecom.sql your-cms/src/db/migrations/002_ecom.sql

2. Run the migration

npx wrangler d1 migrations apply cloudcore-db --file=src/db/migrations/002_ecom.sql

3. Mount the routes in your CMS

// src/index.tsimport{ecomRoutes,ecomPublicRoutes,ecomWebhookRoutes}from'./ecom';// Admin routes (behind auth)app.route('/api/v1/shop',ecomRoutes);// Public product listing (no auth)app.route('/api/v1/public/shop',ecomPublicRoutes);// Payment webhooks (verified by provider signatures, no auth)app.route('/api/v1/webhooks',ecomWebhookRoutes);

4. Add environment variables

# wrangler.toml [vars] or use wrangler secret putSTRIPE_SECRET_KEY = ""STRIPE_WEBHOOK_SECRET = ""# PayPal (optional)PAYPAL_CLIENT_ID = ""PAYPAL_CLIENT_SECRET = ""PAYPAL_WEBHOOK_ID = ""PAYPAL_MODE = "sandbox"# or "live"

API Endpoints

Admin (requires CMS auth)

MethodEndpointDescription
GET/shop/productsList products
GET/shop/products/:idGet product
POST/shop/productsCreate product
PATCH/shop/products/:idUpdate product
DELETE/shop/products/:idDelete product
POST/shop/checkoutCreate checkout session
GET/shop/subscriptionsList all subscriptions
GET/shop/subscriptions/myList current user's subscriptions
POST/shop/subscriptions/:id/cancelCancel subscription

Public (no auth)

MethodEndpointDescription
GET/public/shop/productsList active products
GET/public/shop/products/:slugGet product by slug

Webhooks (verified by provider)

MethodEndpointDescription
POST/webhooks/stripeStripe webhook
POST/webhooks/paypalPayPal webhook

Product Types

One-time purchase:

{
"name": "Pro Template",
"type": "one_time",
"price": 4900,
"currency": "usd"
}

Subscription:

{
"name": "Pro Plan",
"type": "subscription",
"price": 1900,
"currency": "usd",
"intervalType": "month",
"intervalCount": 1,
"trialDays": 14
}

Prices are in cents (4900 = $49.00).

Database Tables

All tables prefixed with cc_ecom_ to avoid conflicts with CMS tables:

  • cc_ecom_products — products and subscription plans
  • cc_ecom_orders — one-time purchase records
  • cc_ecom_subscriptions — active/canceled subscriptions
  • cc_ecom_webhook_events — idempotency log for payment webhooks

How It Works

  1. Admin creates products in the CMS (or via API)
  2. Frontend lists active products via the public endpoint
  3. User clicks "Buy" — frontend calls /shop/checkout with product ID and payment provider
  4. User is redirected to Stripe/PayPal hosted checkout
  5. On success, webhook creates order/subscription records in D1
  6. Frontend checks subscription status via /shop/subscriptions/my

No PCI compliance needed — all card handling is done by Stripe/PayPal.

License

MIT

About

E-commerce starter for Cloudcore CMS. Adds products, subscriptions, Stripe, and PayPal to your CMS.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages