Files
HotLunches/payp/cleanup.php
T
2026-10-19 15:22:52 -07:00

122 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Cleanup utility to remove incorrect merchant IDs (partner IDs saved as merchant IDs)
* Run this once to clean up the bad data from before the fix
*/
$config = require __DIR__ . '/config.php';
require __DIR__ . '/lib/Storage.php';
header('Content-Type: text/html; charset=utf-8');
$storage = new Storage($config['storage_path']);
$partnerMerchantId = $config['partner_merchant_id'];
$cleaned = [
'merchants' => 0,
'pending' => 0,
];
// Clean merchants.json
$merchants = $storage->get('merchants', []);
$originalMerchantsCount = count($merchants);
foreach ($merchants as $school => $info) {
if (isset($info['merchant_id']) && strcasecmp($info['merchant_id'], $partnerMerchantId) === 0) {
unset($merchants[$school]);
$cleaned['merchants']++;
}
}
if ($cleaned['merchants'] > 0) {
$storage->set('merchants', $merchants);
}
// Clean pending_onboarding.json
$pending = $storage->get('pending_onboarding', []);
foreach ($pending as $trackId => &$entry) {
if (!is_array($entry)) continue;
if (isset($entry['merchant_id']) && strcasecmp($entry['merchant_id'], $partnerMerchantId) === 0) {
// Remove the incorrect merchant_id and mark as incomplete
unset($entry['merchant_id']);
$entry['status'] = 'incomplete_onboarding';
$entry['note'] = 'Removed incorrect partner ID. Merchant needs to complete onboarding.';
$entry['cleaned_at'] = time();
$cleaned['pending']++;
}
}
unset($entry);
if ($cleaned['pending'] > 0) {
$storage->set('pending_onboarding', $pending);
}
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Cleanup Utility - PayPal Integration</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 800px; margin: 2rem auto; padding: 0 1rem; }
.box { border: 1px solid #ddd; padding: 1.5rem; border-radius: .5rem; margin-bottom: 1rem; }
.success { background: #d4edda; border-color: #c3e6cb; color: #155724; }
.warning { background: #fff3cd; border-color: #ffeaa7; color: #856404; }
.info { background: #d1ecf1; border-color: #bee5eb; color: #0c5460; }
code { background: #f4f4f4; padding: .2rem .4rem; border-radius: .25rem; }
a { color: #0070ba; }
</style>
</head>
<body>
<h1>🧹 Data Cleanup Complete</h1>
<?php if ($cleaned['merchants'] > 0 || $cleaned['pending'] > 0): ?>
<div class="box success">
<h2>✅ Cleanup Results</h2>
<p><strong><?= $cleaned['merchants'] + $cleaned['pending'] ?></strong> incorrect entries fixed:</p>
<ul>
<li><strong><?= $cleaned['merchants'] ?></strong> incorrect merchant entries removed from <code>merchants.json</code></li>
<li><strong><?= $cleaned['pending'] ?></strong> pending entries corrected in <code>pending_onboarding.json</code></li>
</ul>
</div>
<?php else: ?>
<div class="box info">
<h2>ℹ️ No Cleanup Needed</h2>
<p>No incorrect merchant IDs found. Your data is clean!</p>
</div>
<?php endif; ?>
<div class="box warning">
<h3>⚠️ About the Cleanup</h3>
<p>This utility removed entries where your <strong>partner merchant ID</strong> (<code><?= htmlspecialchars($partnerMerchantId) ?></code>) was incorrectly saved as a merchant's ID.</p>
<p>These merchants will need to:</p>
<ol>
<li>Click "Connect with PayPal" again</li>
<li><strong>Complete the ENTIRE PayPal business account setup</strong></li>
<li>Return to your application to get properly connected</li>
</ol>
</div>
<div class="box info">
<h3>📊 Current Status</h3>
<p><strong>Total connected merchants:</strong> <?= count($merchants) ?></p>
<p><strong>Total pending entries:</strong> <?= count($pending) ?></p>
<?php if (count($merchants) > 0): ?>
<h4>Connected Merchants:</h4>
<ul>
<?php foreach ($merchants as $school => $info): ?>
<li><strong><?= htmlspecialchars($school) ?></strong> - <code><?= htmlspecialchars($info['merchant_id']) ?></code></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<div class="box">
<h3>🔗 Next Steps</h3>
<ul>
<li><a href="index.php">← Back to Dashboard</a></li>
<li><a href="partner_diag.php" target="_blank">View Partner Diagnostics</a></li>
</ul>
<p><small><strong>Note:</strong> You can safely run this cleanup script multiple times. It only removes entries that match your partner merchant ID.</small></p>
</div>
</body>
</html>