![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/private_html/ |
# Automation Setup Guide
## 🚀 Quick Start
### 1. Test the Auto-Fix Script
First, run it in dry-run mode to see what it would fix:
```bash
cd /home/gositeme/domains/soundstudiopro.com/public_html
php auto_fix_missing_purchases.php --dry-run
```
### 2. Test with Stripe Verification
Run with Stripe verification to ensure payments actually succeeded:
```bash
php auto_fix_missing_purchases.php --verify-stripe --dry-run
```
### 3. Run for Real (First Time)
Once you're confident, run it for real:
```bash
php auto_fix_missing_purchases.php --verify-stripe
```
### 4. Set Up Cron Job
Add to your crontab to run every 10 minutes:
```bash
crontab -e
```
Add this line:
```
*/10 * * * * /usr/bin/php /home/gositeme/domains/soundstudiopro.com/public_html/auto_fix_missing_purchases.php --verify-stripe >> /home/gositeme/domains/soundstudiopro.com/public_html/logs/auto_fix_cron.log 2>&1
```
Or run every 5 minutes for faster detection:
```
*/5 * * * * /usr/bin/php /home/gositeme/domains/soundstudiopro.com/public_html/auto_fix_missing_purchases.php --verify-stripe >> /home/gositeme/domains/soundstudiopro.com/public_html/logs/auto_fix_cron.log 2>&1
```
---
## 📊 Monitoring
### Check Logs
View recent auto-fixes:
```bash
tail -f /home/gositeme/domains/soundstudiopro.com/public_html/logs/auto_fix_purchases.log
```
View cron output:
```bash
tail -f /home/gositeme/domains/soundstudiopro.com/public_html/logs/auto_fix_cron.log
```
### Check Manual Fixes Log
All fixes (manual and automatic) are logged here:
```bash
tail -f /home/gositeme/domains/soundstudiopro.com/public_html/logs/manual_purchase_fixes.log
```
---
## ⚙️ Configuration
Edit `auto_fix_missing_purchases.php` to adjust:
- `$MINUTES_TO_WAIT`: How long to wait after payment intent creation before flagging as missing (default: 5 minutes)
- `$STRIPE_SECRET_KEY`: Your Stripe secret key (already set)
---
## 🔔 Optional: Email Notifications
To get notified when fixes are applied, add this to the script after the summary:
```php
// Send email notification if fixes were applied
if ($fixed_count > 0 && !$dry_run) {
$to = 'admin@yourdomain.com';
$subject = "Auto-Fix: {$fixed_count} Missing Purchases Fixed";
$message = "The auto-fix script fixed {$fixed_count} missing purchases.\n\n";
$message .= "Check logs: /home/gositeme/domains/soundstudiopro.com/public_html/logs/auto_fix_purchases.log";
mail($to, $subject, $message);
}
```
---
## 🛡️ Safety Features
The script includes:
1. **Duplicate Prevention**: Checks if purchase already exists before creating
2. **Stripe Verification**: Optional verification that payment actually succeeded
3. **Time Delay**: Waits 5 minutes after payment intent creation (gives webhook time to process)
4. **Transaction Safety**: Uses database transactions to ensure data consistency
5. **Comprehensive Logging**: Logs all actions for audit trail
---
## 📈 Expected Results
After automation is set up:
- **Detection Time**: Missing purchases detected within 5-10 minutes
- **Fix Time**: Automatically fixed within 5-10 minutes of detection
- **Manual Work**: Reduced to near zero
- **Customer Impact**: Customers get their tracks even if webhook fails
---
## 🔍 Troubleshooting
### Script Not Running
Check cron is working:
```bash
grep CRON /var/log/syslog
```
Check PHP path:
```bash
which php
```
### No Fixes Being Applied
1. Check if there are actually missing purchases in `admin_purchase_tracker.php`
2. Verify payment intents are old enough (wait 5+ minutes)
3. Check logs for errors
4. Verify Stripe API key is correct
### Too Many False Positives
Increase `$MINUTES_TO_WAIT` to give webhooks more time to process.
---
## 🎯 Next Steps
1. ✅ Set up cron job
2. ✅ Monitor logs for first few days
3. ✅ Adjust timing if needed
4. ✅ Consider adding email notifications
5. ✅ Review weekly to ensure it's working correctly