📦 Complete Package
ITS PayPal Payment System
A complete, standalone PayPal payment system with server-side OAuth2 verification, multi-plan support, affiliate tracking, and drop-in simplicity. 685 lines of code. PHP 5.6+ compatible.
📦 Package Contents
| File | Lines | Purpose |
| pricing.php | 250 | Main pricing page with plans + payment popup |
| checkout.php | 180 | Server-side PayPal verification + sale recording |
| db_config.php | 55 | Database connection + PayPal credentials |
| schema.sql | 80 | All required database tables + seed data |
| README.md | 120 | Full setup instructions + documentation |
✅ Features
✓ Multi-Plan Support — Add unlimited products via a simple PHP array
✓ PayPal Smart Buttons — Gold, pill-shaped, fully responsive
✓ Server-Side OAuth2 Verification — Confirms every order
✓ Duplicate Prevention — UNIQUE index on payment_id
✓ Affiliate Tracking — Pass ?id=TOKENKEY for commissions
✓ Download Token — 64-char hex for digital delivery
✓ Isolated CSS — Drop into any page without conflicts
✓ Single Currency (GBP) — No conversion complexity
✓ PHP 5.6+ Compatible — Works on virtually any server
✓ Sandbox & Live Modes — One toggle to switch
✓ Dual Database — mysqli + PDO fallback
✓ FormData POST — Reliable on all servers
🔄 How It Works
1
Customer visits pricing page, sees your plans
2
Clicks "View Plans & Pay" — popup opens
3
Selects a plan — PayPal button renders
4
Clicks PayPal — logs in and approves
5
onApprove fires — POST to checkout.php
6
checkout.php verifies via OAuth2 API
7
Sale recorded in database
8
Customer redirected to success
🏗️ Payment Flow Architecture
┌──────────────────────────────────────────────────────────┐
│ PAYMENT FLOW ARCHITECTURE │
├──────────────────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ Customer │ │ PayPal JS │ │ PayPal Orders │ │
│ │ clicks │───▶│ SDK Button │───▶│ API v2 │ │
│ │ "Pay" │ │ (Client) │ │ (OAuth2 Verify)│ │
│ └──────────┘ └──────────────┘ └────────┬────────┘ │
│ ▼ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ checkout.php │ │
│ │ • Receives orderID via FormData POST │ │
│ │ • Server-to-server verification via OAuth2 │ │
│ │ • Saves to its_product_sales table │ │
│ │ • Generates download_token (64-char hex) │ │
│ │ • Duplicate prevention (UNIQUE on payment_id) │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────┘
🔒 Security Layers
🔐
Client — PayPal handles card data
🔒
Transport — HTTPS + encryption
✅
Verification — Server OAuth2
🛡️
Duplicate — UNIQUE index
🚀 Quick Start Guide
1
Run schema.sql in your MySQL database
2
Edit db_config.php with credentials
3
Customise $customPlans array
4
Upload all files to your server
5
Test with PayPal Sandbox
6
Set SANDBOX to false — go live!
➕ Adding New Products
Edit the $customPlans array in pricing.php. The PayPal button automatically works with whatever you add. No JavaScript changes needed.
array(
'id' => 'my-product',
'name' => 'My Product',
'price' => '99.00',
'period' => '/one-time',
'features' => 'Feature 1 · Feature 2 · Feature 3',
'badge' => '',
'commission' => '19.80'
),
🔗 Affiliate Tracking
Add ?id=PARTNER_TOKEN to any link. Query sales by tokenkey to calculate commissions.
pricing.php?id=abc123
SELECT tokenkey, SUM(amount) AS total
FROM its_product_sales
WHERE tokenkey = 'abc123'
GROUP BY tokenkey;
⚙️ Requirements
🐘 PHP 5.6 or higher
🗄️ MySQL 5.7 or higher
🔌 curl, mysqli (or PDO), openssl
💳 PayPal Business Account