Credit System

PayPal-integrated billing system with transaction tracking

The credit system allows users to top up their balance via PayPal and use credits to purchase groups and services.

Overview

Credit Balance

Track user credits in EUR

PayPal Integration

Secure payments via PayPal REST API

Transaction History

Complete audit trail

Top-Up Flow

User Journey
  1. User navigates to /credits
  2. Views current balance and transaction history
  3. Clicks "Top Up Credits"
  4. Selects amount (€5-€1000) or enters custom amount
  5. Clicks "Continue to PayPal"
  6. Redirected to PayPal for payment
  7. Completes payment on PayPal
  8. Redirected back to success page
  9. Credits automatically added to balance
  10. Transaction logged in history

Top-Up Amounts

Amount Quick Select Use Case
€5 Basic group purchase
€10 Small top-up
€20 Pro group purchase
€50 Enterprise group
€100 Bulk purchase
Custom Any amount €5-€1000

PayPal Configuration

Sandbox (Testing)
PAYPAL_MODE=sandbox
PAYPAL_CLIENT_ID=your-sandbox-client-id
PAYPAL_CLIENT_SECRET=your-sandbox-client-secret
Get Sandbox Credentials:
  1. Go to PayPal Developer Dashboard
  2. Create a sandbox app
  3. Copy Client ID and Secret
Production
PAYPAL_MODE=live
PAYPAL_CLIENT_ID=your-live-client-id
PAYPAL_CLIENT_SECRET=your-live-client-secret
Before Going Live:
  • Test thoroughly in sandbox
  • Create production app in PayPal
  • Enable SSL/HTTPS
  • Set up webhook verification
  • Review PayPal's policies

Transaction Types

Credit Transactions
  • PayPal Top-Up: User adds credits via PayPal
  • Admin Credit: Manual credit by admin
  • Refund: Credits returned
Debit Transactions
  • Group Purchase: User buys a group
  • Service Purchase: Other services
  • Admin Debit: Manual deduction

Database Schema

Tables
credits

User credit balances

id, user_id, balance, updated_at
transactions

Credit/debit transaction history

id, user_id, type, amount, description, reference_id, created_at
paypal_payments

PayPal payment tracking

id, user_id, payment_id, payer_id, amount, status, created_at

API Routes

GET  /credits                    - View balance & history
GET  /credits/topup              - Top-up form
POST /credits/payment/create    - Create PayPal payment
GET  /credits/payment/success   - Payment success callback
GET  /credits/payment/cancel    - Payment cancelled callback

Security Features

Atomic Transactions

Database transactions ensure consistency

PayPal Verification

Signature verification in production

Audit Trail

Complete transaction logging