# Pi API Key - Quick Reference Card

**Print this page or bookmark it!**

---

## ⚡ 10-Minute Quick Start

### 1. Create Account (2 min)
```
1. Go to: https://www.pi.network
2. Click: "Sign Up"
3. Choose: Email or Phone
4. Verify: Check your email/SMS
✅ Account created
```

### 2. Register App (3 min)
```
1. Go to: https://develop.pi
2. Click: "Create New App"
3. Enter Name: "Nexera Africa"
4. Select Type: "Web App"
5. Click: "Next"
✅ App created
```

### 3. Configure URLs (2 min)
```
Callback URL:
https://nexeraafrica.com/api/pi_payment.php

Redirect URL:
https://nexeraafrica.com/checkout.html

Permissions:
✓ username
✓ payments
```

### 4. Get API Key (2 min)
```
1. Go to: Credentials tab
2. Find: API Key (Sandbox section)
3. Click: Copy
4. Save: Securely!
✅ Key obtained
```

### 5. Configure Code (1 min)
```php
// In api/pi_payment.php, line ~10:
define('PI_API_KEY', 'sk_live_xxx...');
```

---

## 📍 Key URLs

| Purpose | URL |
|---------|-----|
| Create Account | https://www.pi.network/register |
| Developer Portal | https://develop.pi |
| Create App | https://develop.pi/create-app |
| My Apps | https://develop.pi/my-apps |
| API Docs | https://docs.pi.network |

---

## 🔑 API Key Examples

**Sandbox (Testing):**
```
sk_live_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p
     ↑
  Starts with: sk_live_
```

**Production (Live):**
```
sk_prod_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p
     ↑
  Starts with: sk_prod_
```

---

## 🧪 Test Your API Key

```bash
# In terminal, SSH to your VPS:
ssh root@nexeraafrica.com

# Test if API key is set:
echo $PI_API_KEY

# Test the API endpoint:
curl -X POST https://nexeraafrica.com/api/pi_payment.php?action=create \
  -H "Content-Type: application/json" \
  -d '{"amount": 0.00314, "memo": "test"}'

# Expected response (success):
# {"status":"success","orderId":"NEXERA-xxx"}
```

---

## ✅ Verification Checklist

- [ ] Account created
- [ ] App registered as "Nexera Africa"
- [ ] App type: Web App
- [ ] Callback URL: `nexeraafrica.com/api/pi_payment.php`
- [ ] Redirect URL: `nexeraafrica.com/checkout.html`
- [ ] Permissions: username + payments selected
- [ ] API Key copied and secured
- [ ] Code updated with API Key
- [ ] Tested with `curl` command
- [ ] Ready for testing in Pi Browser

---

## 🚨 Security Rules

| DO | DON'T |
|----|-------|
| Store in environment variable | Hardcode in files |
| Use .env or secrets manager | Commit to GitHub |
| Rotate every 90 days | Share publicly |
| Use sandbox for testing | Test in production |
| Regenerate if compromised | Reuse across projects |

---

## 🔄 Environment Variables Setup

### Linux/Mac VPS
```bash
# SSH into VPS
ssh root@nexeraafrica.com

# Edit bash profile
nano ~/.bashrc

# Add this line:
export PI_API_KEY="sk_live_xxx..."

# Save and reload
source ~/.bashrc

# Verify
echo $PI_API_KEY
```

### Windows (If Self-Hosted)
```powershell
# PowerShell (Run as Administrator):
[System.Environment]::SetEnvironmentVariable("PI_API_KEY","sk_live_xxx...")

# Verify:
$env:PI_API_KEY
```

---

## 📞 Common Issues & Fixes

| Issue | Fix |
|-------|-----|
| "API key not working" | Verify key format: `sk_live_` or `sk_prod_` |
| "Unauthorized error" | Check sandbox vs production mode |
| "Key not found" | Reload environment: `source ~/.bashrc` |
| "Key lost" | Regenerate in Developer Portal |
| "Can't see credentials" | Log out and log back in |

---

## 🎯 File Locations

### API Key Configuration
```
File: api/pi_payment.php
Line: ~10-15
Look for: define('PI_API_KEY', ...)
```

### Code Files Using API Key
```
1. api/pi_payment.php          ← Main backend
2. checkout.html               ← Standalone checkout
3. payment.php                 ← Listing checkout
```

### Environment Variable File (VPS)
```
File: ~/.bashrc (Linux)
File: ~/.zshrc  (Mac)
Command: export PI_API_KEY="..."
```

---

## 📊 Testing Flow

```
┌─────────────────────────────────────┐
│ 1. Create Account                   │
│    https://www.pi.network/register  │
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ 2. Developer Portal                 │
│    https://develop.pi               │
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ 3. Create App (Nexera Africa)       │
│    Type: Web App                    │
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ 4. Configure URLs & Permissions     │
│    - Callback: api/pi_payment.php   │
│    - Permissions: username, payments│
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ 5. Get API Key (Sandbox)            │
│    Format: sk_live_...              │
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ 6. Configure Code                   │
│    api/pi_payment.php: define(...)  │
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ 7. Test with cURL                   │
│    curl -X POST ...                 │
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ 8. Test in Pi Browser               │
│    https://nexeraafrica.com/...     │
└──────────────┬──────────────────────┘
               ↓
┌─────────────────────────────────────┐
│ ✅ READY FOR PRODUCTION             │
│    Switch to prod_key, sandbox:false│
└─────────────────────────────────────┘
```

---

## 💡 Pro Tips

### Tip 1: Store Key Safely
```bash
# Create encrypted file
gpg -c ~/.pi_api_key.txt

# Or use password manager:
# - 1Password
# - LastPass  
# - Bitwarden
# - KeePass
```

### Tip 2: Multiple Environments
```bash
# Different keys per environment:
export PI_API_KEY_DEV="sk_live_..."   # Sandbox
export PI_API_KEY_PROD="sk_prod_..."  # Live

# In code:
$env = getenv('APP_ENV') ?: 'dev';
$key = getenv('PI_API_KEY_' . strtoupper($env));
```

### Tip 3: Monitor Usage
```bash
# Check API quota/usage in Developer Portal:
https://develop.pi/app/[APP_ID]/analytics
```

### Tip 4: Rotate Keys
```
Every 90 days:
1. Generate new API key
2. Update code
3. Verify working
4. Delete old key
```

---

## 🆘 Need Help?

| Question | Answer |
|----------|--------|
| Where's my API key? | Developer Portal → App → Credentials |
| Can I use same key for sandbox & prod? | No, they're separate |
| What if I lose it? | Regenerate in Developer Portal |
| Is it safe to hardcode? | NO! Use environment variables |
| How long is the key? | ~50-60 characters |
| Can I share it? | NO! Keep it secret |

---

## 📋 Configuration Checklist - One Page

```
ACCOUNT SETUP
☐ Signed up at pi.network
☐ Verified email/phone
☐ Can access Developer Portal

APP REGISTRATION
☐ Created app "Nexera Africa"
☐ Selected type: Web App
☐ Added sandbox callback URL
☐ Added redirect URLs
☐ Selected permissions (username, payments)

API KEY
☐ Copied sandbox API key
☐ Verified format (sk_live_...)
☐ Stored securely
☐ Set environment variable
☐ Updated api/pi_payment.php

TESTING
☐ API responds to curl test
☐ Tested in Pi Browser
☐ Database table created
☐ Orders saving correctly

PRODUCTION READY
☐ Got production API key (sk_prod_...)
☐ Updated code
☐ Changed sandbox: false
☐ All tests pass
☐ Ready to deploy
```

---

## 🚀 Quick Deploy Commands

```bash
# SSH to VPS
ssh root@nexeraafrica.com

# Set API key
export PI_API_KEY="sk_live_xxx..."

# Test endpoint
curl -X POST https://nexeraafrica.com/api/pi_payment.php?action=create \
  -H "Content-Type: application/json" \
  -d '{"amount":0.00314,"memo":"test"}'

# Check database
mysql -u root -p -e "SELECT COUNT(*) FROM nexora_db.pi_payments;"

# Done!
```

---

**Bookmark this page!** ⭐  
Last updated: June 13, 2026
