clavitor/clavitor.ai/admin/SANDBOX.md

116 lines
2.9 KiB
Markdown

# Clavitor Admin - Local Development (Paddle Sandbox)
## Quick Start
### 1. Get Sandbox API Key
1. Go to https://sandbox-vendors.paddle.com
2. Log in (create account if needed)
3. Go to **Developer Tools > Authentication**
4. Create **API Key** (server-side) - copy this
5. Create **Client Token** (client-side) - copy this too
### 2. Set API Key
Edit `admin/sync.go`:
```go
const DefaultAPIKey = "pdl_sandbox_apikey_..." // Your sandbox API key
```
### 3. Set Client Token
Edit `admin/static/checkout.html`:
```javascript
const PADDLE_CLIENT_TOKEN = 'pdl_sandbox_clienttoken_...'; // Your sandbox client token
```
### 4. Create Products in Sandbox
1. Go to https://sandbox-vendors.paddle.com
2. **Catalog > Products**
3. Create products:
- Clavitor Personal - $12/year
- Clavitor Family - $29/year
- Clavitor Pro - $49/year
4. **Copy the Price IDs** (look like `pri_01xxx`)
### 5. Update Price IDs
Edit `admin/paddle_checkout.go`:
```go
var PriceIDs = map[string]string{
"personal_yearly_usd": "pri_01xxxxxx", // Replace with actual
"family_yearly_usd": "pri_02xxxxxx",
"pro_yearly_usd": "pri_03xxxxxx",
}
```
### 6. Run Admin Locally
```bash
cd /home/johan/dev/clavitor/clavitor.ai/admin
go run main.go
```
Open http://localhost:8080
### 7. Test Checkout
1. Go to http://localhost:8080/static/checkout.html
2. Select a plan
3. Enter email
4. Click "Subscribe Now"
5. Use Paddle's **test card**: `4242 4242 4242 4242`
- Any future expiry date
- Any 3-digit CVC
6. Payment succeeds in sandbox
7. Check webhook delivered to your local endpoint
## Sandbox vs Production
| | Sandbox | Production |
|--|---------|------------|
| URL | sandbox-api.paddle.com | api.paddle.com |
| Money | Fake | Real |
| Cards | Test cards only | Real cards |
| Webhooks | Same format | Same format |
## Webhook Testing
Paddle webhooks need to reach your local machine. Use one of:
1. **ngrok**: `ngrok http 8080` → gives you public URL
2. **localtunnel**: `lt --port 8080`
3. **Set webhook URL** in Paddle to your tunnel URL + `/webhooks/paddle`
## Environment Variables (Alternative)
Instead of editing code, use env vars:
```bash
export PADDLE_API_KEY="pdl_sandbox_apikey_..."
export PADDLE_CLIENT_TOKEN="pdl_sandbox_clienttoken_..."
export PADDLE_SANDBOX="true"
go run main.go
```
## Troubleshooting
**"Invalid API key"**: You're using production key in sandbox (or vice versa)
**"Product not found"**: Price ID is from wrong environment
**"Client token invalid"**: Token expired or wrong environment
**"Checkout doesn't open"**: Check browser console for JavaScript errors
## Switching to Production
When ready for real payments:
1. Get production API key from https://vendors.paddle.com
2. Change `environment: 'sandbox'` to `'production'` in checkout.html
3. Change sandbox URLs to production in sync.go
4. Use real Price IDs from production dashboard
5. Test with small real payment first