![]() 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/public_html/ |
<?php
/**
* List All Stripe Prices
* Shows all subscription prices in Stripe so we can match them to plans
*/
session_start();
require_once 'config/database.php';
// Check admin access
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
die("Admin access required");
}
$stripe_secret = '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';
$plans_config = require __DIR__ . '/config/subscription_plans.php';
// Fetch all prices from Stripe
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/prices?limit=100&type=recurring');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $stripe_secret]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$all_prices = [];
$suggested_matches = [];
if ($http_code === 200) {
$data = json_decode($response, true);
$prices = $data['data'] ?? [];
foreach ($prices as $price) {
$amount = $price['unit_amount'] / 100;
$interval = $price['recurring']['interval'] ?? 'N/A';
$product_id = $price['product'];
// Get product name
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.stripe.com/v1/products/{$product_id}");
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $stripe_secret]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$product_response = curl_exec($ch);
curl_close($ch);
$product_data = json_decode($product_response, true);
$product_name = $product_data['name'] ?? 'Unknown';
$all_prices[] = [
'price_id' => $price['id'],
'amount' => $amount,
'interval' => $interval,
'product_name' => $product_name,
'product_id' => $product_id,
'active' => $price['active'] ?? true
];
// Try to match to a plan
foreach ($plans_config as $plan_key => $plan) {
if (abs($plan['price'] - $amount) < 0.01 && $interval === 'month') {
$suggested_matches[$plan_key] = $price['id'];
}
}
}
}
$page_title = 'List Stripe Prices';
include 'includes/header.php';
?>
<main style="max-width: 1200px; margin: 40px auto; padding: 20px;">
<div style="background: #2a2a2a; border-radius: 12px; padding: 40px;">
<h1 style="color: white; margin-bottom: 20px;">📋 All Stripe Subscription Prices</h1>
<p style="color: #a0aec0; margin-bottom: 30px;">
Here are all recurring prices in your Stripe account. Match them to your plans below.
</p>
<?php if (!empty($suggested_matches)): ?>
<div style="background: #2d5016; padding: 20px; border-radius: 8px; margin-bottom: 30px;">
<h2 style="color: #48bb78; margin-bottom: 15px;">✅ Suggested Matches</h2>
<p style="color: white; margin-bottom: 15px;">Based on price amounts, these Price IDs likely match your plans:</p>
<div style="background: #1a1a1a; padding: 15px; border-radius: 8px; font-family: monospace;">
<?php foreach ($suggested_matches as $plan_key => $price_id):
$plan = $plans_config[$plan_key];
?>
<div style="color: white; margin-bottom: 10px; padding: 10px; background: #2a2a2a; border-radius: 5px;">
<strong style="color: <?= $plan['color'] ?>;"><?= htmlspecialchars($plan['name']) ?></strong> ($<?= number_format($plan['price'], 2) ?>/month) →
<span style="color: #48bb78;"><?= htmlspecialchars($price_id) ?></span>
</div>
<?php endforeach; ?>
</div>
<form method="POST" style="margin-top: 20px;">
<button type="submit" name="apply_matches" value="1" style="padding: 12px 24px; background: #48bb78; color: white; border: none; border-radius: 8px; cursor: pointer; font-size: 1.1rem;">
✅ Apply These Matches to Config
</button>
</form>
</div>
<?php endif; ?>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['apply_matches'])) {
$config_file = __DIR__ . '/config/subscription_plans.php';
$config_content = file_get_contents($config_file);
foreach ($suggested_matches as $plan_key => $price_id) {
// More precise pattern: match the specific plan's stripe_price_id line
$plan_pattern = "/(['\"]{$plan_key}['\"]\s*=>\s*\[[^\]]*'stripe_price_id'\s*=>\s*['\"])[^'\"]*(['\"])/s";
if (preg_match($plan_pattern, $config_content)) {
$config_content = preg_replace($plan_pattern, "$1{$price_id}$2", $config_content, 1);
} else {
// Fallback: replace any stripe_price_id (less precise but should work)
$pattern = "/(['\"]stripe_price_id['\"]\s*=>\s*['\"])[^'\"]*(['\"])/";
$replacement = "$1{$price_id}$2";
$config_content = preg_replace($pattern, $replacement, $config_content, 1);
}
}
file_put_contents($config_file, $config_content);
echo '<div style="background: #2d5016; padding: 20px; border-radius: 8px; margin-bottom: 30px;">';
echo '<p style="color: #48bb78; font-size: 1.2rem;"><strong>✅ Config Updated!</strong> The Price IDs have been applied to config/subscription_plans.php</p>';
echo '<p style="color: white; margin-top: 10px;">Updated plans: ' . implode(', ', array_keys($suggested_matches)) . '</p>';
echo '</div>';
// Reload config
$plans_config = require __DIR__ . '/config/subscription_plans.php';
}
?>
<table style="width: 100%; border-collapse: collapse; color: white; margin-bottom: 30px;">
<thead>
<tr style="border-bottom: 2px solid #444; background: #1a1a1a;">
<th style="padding: 15px; text-align: left;">Price ID</th>
<th style="padding: 15px; text-align: left;">Product Name</th>
<th style="padding: 15px; text-align: left;">Amount</th>
<th style="padding: 15px; text-align: left;">Interval</th>
<th style="padding: 15px; text-align: left;">Status</th>
<th style="padding: 15px; text-align: left;">Matches Plan</th>
</tr>
</thead>
<tbody>
<?php if (empty($all_prices)): ?>
<tr>
<td colspan="6" style="padding: 20px; text-align: center; color: #a0aec0;">
No recurring prices found in Stripe. Run the setup script to create them.
</td>
</tr>
<?php else: ?>
<?php foreach ($all_prices as $price): ?>
<tr style="border-bottom: 1px solid #333;">
<td style="padding: 15px; font-family: monospace; font-size: 0.9rem;">
<?= htmlspecialchars($price['price_id']) ?>
</td>
<td style="padding: 15px;">
<?= htmlspecialchars($price['product_name']) ?>
</td>
<td style="padding: 15px;">
<strong>$<?= number_format($price['amount'], 2) ?></strong>
</td>
<td style="padding: 15px;">
<?= htmlspecialchars($price['interval']) ?>
</td>
<td style="padding: 15px;">
<?php if ($price['active']): ?>
<span style="color: #48bb78;">✅ Active</span>
<?php else: ?>
<span style="color: #e53e3e;">❌ Inactive</span>
<?php endif; ?>
</td>
<td style="padding: 15px;">
<?php
$matched_plan = null;
foreach ($plans_config as $plan_key => $plan) {
if (abs($plan['price'] - $price['amount']) < 0.01 && $price['interval'] === 'month') {
$matched_plan = $plan_key;
break;
}
}
if ($matched_plan):
$plan = $plans_config[$matched_plan];
?>
<span style="color: <?= $plan['color'] ?>; font-weight: bold;">
<?= htmlspecialchars($plan['name']) ?>
</span>
<?php else: ?>
<span style="color: #a0aec0;">No match</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<div style="margin-top: 30px; padding: 20px; background: #1a1a1a; border-radius: 8px;">
<h3 style="color: white; margin-bottom: 15px;">💡 Instructions</h3>
<ol style="color: #a0aec0; line-height: 1.8;">
<li>Review the "Suggested Matches" above</li>
<li>If they look correct, click "Apply These Matches to Config"</li>
<li>If not, manually update <code>config/subscription_plans.php</code> with the correct Price IDs</li>
<li>After updating, run <code>/verify_stripe_prices.php</code> to confirm</li>
</ol>
</div>
</div>
</main>
<?php include 'includes/footer.php'; ?>