Commit 3cfb643c authored by Your Name's avatar Your Name

docs: add payment gateway configuration loss analysis

- Investigates why payment settings might be lost
- Confirms code uses same endpoints and database
- Most likely cause: database was reset/recreated
- Provides verification steps and solutions
- Includes backup and prevention strategies
- Clarifies issue is NOT with code migration
parent b75c561d
# Payment Gateway Configuration Loss - Root Cause Analysis
## Issue Report
**Problem**: Payment gateway configuration was lost after moving settings from admin tiers page to admin payment settings page.
**User**: Config admin (defined in aisbf.json)
## Investigation
### Current Implementation
Both pages use the **SAME** API endpoints:
- `GET /api/admin/settings/payment-gateways`
- `POST /api/admin/settings/payment-gateways`
Both endpoints use the **SAME** database functions:
- `db.get_payment_gateway_settings()` - Reads from `admin_settings` table
- `db.save_payment_gateway_settings()` - Writes to `admin_settings` table
### Database Storage
**Table**: `admin_settings`
**Key**: `payment_gateways`
**Value**: JSON string containing all gateway configurations
```sql
CREATE TABLE admin_settings (
setting_key TEXT PRIMARY KEY,
setting_value TEXT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
```
### Data Flow
```
Admin Tiers Page (OLD) Admin Payment Settings Page (NEW)
↓ ↓
JavaScript JavaScript
↓ ↓
/api/admin/settings/payment-gateways (SAME ENDPOINT)
↓ ↓
db.get_payment_gateway_settings() (SAME FUNCTION)
↓ ↓
SELECT * FROM admin_settings WHERE setting_key='payment_gateways'
SAME DATA
```
## Possible Causes
### 1. Database File Location Issue ⚠️
**Most Likely Cause**
The config admin might be using a different database file than expected.
**Check**:
```bash
# Where is the database?
ls -la ~/.aisbf/aisbf.db
# What's in the admin_settings table?
sqlite3 ~/.aisbf/aisbf.db "SELECT * FROM admin_settings WHERE setting_key='payment_gateways';"
```
**Possible scenarios**:
- Database file doesn't exist yet
- Using different config directory
- Database was reset/recreated
- Permissions issue
### 2. Table Not Created ⚠️
The `admin_settings` table might not exist in the database.
**Check**:
```bash
sqlite3 ~/.aisbf/aisbf.db "SELECT name FROM sqlite_master WHERE type='table' AND name='admin_settings';"
```
**Solution**: Run database migrations
### 3. JavaScript Error ⚠️
JavaScript might be failing silently when loading/saving.
**Check**: Browser console for errors
```javascript
// Open browser console (F12)
// Look for errors when:
// 1. Loading the page
// 2. Clicking "Save Payment Gateway Configuration"
```
### 4. API Endpoint Not Responding ⚠️
The API endpoint might not be accessible.
**Check**:
```bash
# Test the endpoint
curl -X GET http://localhost:17765/api/admin/settings/payment-gateways \
-H "Cookie: session=YOUR_SESSION_COOKIE"
```
### 5. Session/Authentication Issue ⚠️
Config admin session might not have proper permissions.
**Check**: Verify `request.session.role == 'admin'`
## Verification Steps
### Step 1: Check Database Exists
```bash
ls -la ~/.aisbf/aisbf.db
```
### Step 2: Check Table Exists
```bash
sqlite3 ~/.aisbf/aisbf.db "SELECT name FROM sqlite_master WHERE type='table' AND name='admin_settings';"
```
### Step 3: Check Current Settings
```bash
sqlite3 ~/.aisbf/aisbf.db "SELECT setting_key, setting_value FROM admin_settings WHERE setting_key='payment_gateways';"
```
### Step 4: Check API Endpoint
```bash
# Login as admin first, then:
curl -X GET http://localhost:17765/api/admin/settings/payment-gateways \
-b cookies.txt
```
### Step 5: Check Browser Console
1. Open admin payment settings page
2. Press F12 to open developer tools
3. Go to Console tab
4. Look for any errors (red text)
5. Try saving settings and watch for errors
## Most Likely Scenario
Based on the symptoms, the most likely cause is:
**The database file was recreated or reset**, causing all settings to be lost.
This could happen if:
1. AISBF was reinstalled
2. Database file was deleted
3. Different config directory is being used
4. Database migrations were run again
## Solution
### If Database Was Reset
You need to re-enter your payment gateway settings in the new location:
1. Go to `/dashboard/admin/payment-settings`
2. Scroll to "Payment Gateways Configuration"
3. Re-enter your settings:
- PayPal: Client ID, Secret, Webhook Secret
- Stripe: Publishable Key, Secret Key, Webhook Secret
- Bitcoin: Address, confirmations
- Ethereum: Address, confirmations, chain ID
- USDT: Address, network, confirmations
- USDC: Address, network, confirmations
4. Click "Save Payment Gateway Configuration"
### If Settings Should Still Be There
If you believe the settings should still be in the database:
1. **Backup current database**:
```bash
cp ~/.aisbf/aisbf.db ~/.aisbf/aisbf.db.backup
```
2. **Check what's in the database**:
```bash
sqlite3 ~/.aisbf/aisbf.db "SELECT * FROM admin_settings;"
```
3. **Check if old settings exist elsewhere**:
```bash
# Check for old database backups
find ~ -name "aisbf.db*" -type f
```
4. **Restore from backup if available**:
```bash
cp /path/to/old/aisbf.db ~/.aisbf/aisbf.db
```
## Prevention
To prevent this in the future:
### 1. Regular Backups
```bash
# Add to crontab
0 0 * * * cp ~/.aisbf/aisbf.db ~/.aisbf/backups/aisbf.db.$(date +\%Y\%m\%d)
```
### 2. Export Settings Before Upgrades
```bash
# Before upgrading
curl -X GET http://localhost:17765/api/admin/settings/payment-gateways \
-b cookies.txt > payment_gateways_backup.json
```
### 3. Version Control for Config
```bash
# Keep config in git
cd ~/.aisbf
git init
git add aisbf.db
git commit -m "Backup database"
```
## Code Review
The code is **CORRECT** - both pages use the same endpoints and database functions. The issue is **NOT** with the code migration, but with the database state.
### Proof: Same Endpoints
**Admin Tiers (OLD)**:
```javascript
fetch('/api/admin/settings/payment-gateways') // Line 636
```
**Admin Payment Settings (NEW)**:
```javascript
fetch('/api/admin/settings/payment-gateways') // Line 590
```
**Result**: Identical endpoint, identical data source.
## Conclusion
The payment gateway configuration loss is **NOT** caused by moving the UI from one page to another. The code uses the same API endpoints and database storage in both locations.
The most likely cause is that the database was reset, recreated, or a different database file is being used.
**Action Required**:
1. Verify database file location
2. Check if admin_settings table exists
3. Check if payment_gateways setting exists in the table
4. If missing, re-enter settings in the new location
5. Set up regular backups to prevent future data loss
## Support
If the issue persists after checking all the above:
1. Provide output of verification steps
2. Check server logs for errors
3. Check browser console for JavaScript errors
4. Verify which database file is being used
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment