![]() 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/ |
<?php
/**
* Quick Fix: Create Missing Price IDs
* Creates any missing prices and updates config immediately
*/
session_start();
require_once 'config/database.php';
// Check admin access
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
die("Admin access required");
}
$plans_config = require __DIR__ . '/config/subscription_plans.php';
$stripe_secret = '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';
$results = [];
$config_updates = [];
// First, check what prices already exist in Stripe
$existing_prices = [];
$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);
curl_close($ch);
$prices_data = json_decode($response, true);
if (isset($prices_data['data'])) {
foreach ($prices_data['data'] as $price) {
$amount = $price['unit_amount'] / 100;
$existing_prices[(string)$amount] = $price['id'];
}
}
// Check which plans need prices created or fixed
foreach ($plans_config as $plan_key => $plan) {
$current_price_id = $plan['stripe_price_id'] ?? '';
$is_placeholder = (
empty($current_price_id) ||
strpos($current_price_id, 'price_') !== 0 ||
strlen($current_price_id) < 20 ||
strpos($current_price_id, '_monthly') !== false // Placeholder pattern
);
// Check if we already have a price for this amount in Stripe
$expected_amount = (string)$plan['price'];
$existing_price_id = $existing_prices[$expected_amount] ?? null;
if ($existing_price_id && !$is_placeholder && $current_price_id === $existing_price_id) {
// Already correct
$results[$plan_key] = [
'status' => 'already_correct',
'price_id' => $current_price_id
];
} elseif ($existing_price_id) {
// Price exists in Stripe, just need to update config
$results[$plan_key] = [
'status' => 'found_existing',
'price_id' => $existing_price_id
];
$config_updates[$plan_key] = $existing_price_id;
} elseif ($is_placeholder) {
// Need to create new price
try {
// Create Product
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/products');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $stripe_secret]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'name' => $plan['name'] . ' Plan',
'description' => $plan['tracks_per_month'] . ' tracks per month subscription',
'metadata[plan_key]' => $plan_key,
'metadata[tracks_per_month]' => (string)$plan['tracks_per_month']
]));
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code !== 200) {
throw new Exception("Failed to create product: " . $response);
}
$product = json_decode($response, true);
$product_id = $product['id'];
// Create Price
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/prices');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $stripe_secret]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'product' => $product_id,
'unit_amount' => (int)($plan['price'] * 100),
'currency' => 'usd',
'recurring[interval]' => 'month',
'metadata[plan_key]' => $plan_key,
'metadata[plan_name]' => $plan['name']
]));
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code !== 200) {
throw new Exception("Failed to create price: " . $response);
}
$price = json_decode($response, true);
$price_id = $price['id'];
$results[$plan_key] = [
'status' => 'created',
'product_id' => $product_id,
'price_id' => $price_id
];
$config_updates[$plan_key] = $price_id;
} catch (Exception $e) {
$results[$plan_key] = [
'status' => 'error',
'error' => $e->getMessage()
];
}
} else {
// Has a Price ID but it's wrong - need to verify or create correct one
// Try to find correct price by amount
$expected_amount = (string)$plan['price'];
$existing_price_id = $existing_prices[$expected_amount] ?? null;
if ($existing_price_id) {
// Found correct price in Stripe
$results[$plan_key] = [
'status' => 'found_correct',
'old_price_id' => $current_price_id,
'price_id' => $existing_price_id
];
$config_updates[$plan_key] = $existing_price_id;
} else {
// Price ID exists but wrong, and correct one doesn't exist - need to create
$results[$plan_key] = [
'status' => 'wrong_price_id',
'old_price_id' => $current_price_id,
'needs_creation' => true
];
// Will be handled in creation loop below
}
}
}
// Create any missing prices
foreach ($plans_config as $plan_key => $plan) {
if (isset($results[$plan_key]) && ($results[$plan_key]['status'] === 'wrong_price_id' || $results[$plan_key]['status'] === 'error')) {
// Need to create this price
if (!isset($results[$plan_key]['needs_creation']) || $results[$plan_key]['needs_creation']) {
try {
// Update config file
if (!empty($config_updates)) {
$config_file = __DIR__ . '/config/subscription_plans.php';
$config_content = file_get_contents($config_file);
foreach ($config_updates as $plan_key => $price_id) {
// Match the specific plan block and replace stripe_price_id
$pattern = "/(['\"]{$plan_key}['\"]\s*=>\s*\[[^\]]*'stripe_price_id'\s*=>\s*['\"])[^'\"]*(['\"])/s";
if (preg_match($pattern, $config_content)) {
$config_content = preg_replace($pattern, "$1{$price_id}$2", $config_content, 1);
}
}
file_put_contents($config_file, $config_content);
$config_updated = true;
} else {
$config_updated = false;
}
$page_title = 'Fix Missing Price IDs';
include 'includes/header.php';
?>
<main style="max-width: 900px; margin: 40px auto; padding: 20px;">
<div style="background: #2a2a2a; border-radius: 12px; padding: 40px;">
<h1 style="color: white; margin-bottom: 20px;">🔧 Fix Missing Price IDs</h1>
<?php if ($config_updated): ?>
<div style="background: #2d5016; padding: 20px; border-radius: 8px; margin-bottom: 30px;">
<h2 style="color: #48bb78; margin-bottom: 15px;">✅ Success!</h2>
<p style="color: white; margin-bottom: 15px;">
Created <strong><?= count($config_updates) ?></strong> missing prices and updated config file.
</p>
<a href="/verify_stripe_prices.php" style="display: inline-block; padding: 12px 24px; background: #48bb78; color: white; text-decoration: none; border-radius: 8px; margin-top: 10px;">
Verify All Prices
</a>
</div>
<?php endif; ?>
<table style="width: 100%; border-collapse: collapse; color: white;">
<thead>
<tr style="border-bottom: 2px solid #444; background: #1a1a1a;">
<th style="padding: 15px; text-align: left;">Plan</th>
<th style="padding: 15px; text-align: left;">Status</th>
<th style="padding: 15px; text-align: left;">Price ID</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $plan_key => $result):
$plan = $plans_config[$plan_key];
?>
<tr style="border-bottom: 1px solid #333;">
<td style="padding: 15px;">
<strong style="color: <?= $plan['color'] ?>;"><?= htmlspecialchars($plan['name']) ?></strong>
<br><small style="color: #a0aec0;">$<?= number_format($plan['price'], 2) ?>/month</small>
</td>
<td style="padding: 15px;">
<?php if ($result['status'] === 'created'): ?>
<span style="color: #48bb78; font-weight: bold;">✅ Created</span>
<?php elseif ($result['status'] === 'already_configured'): ?>
<span style="color: #ffc107;">⏭️ Already Configured</span>
<?php else: ?>
<span style="color: #e53e3e; font-weight: bold;">❌ Error</span>
<br><small style="color: #e53e3e;"><?= htmlspecialchars($result['error'] ?? 'Unknown') ?></small>
<?php endif; ?>
</td>
<td style="padding: 15px; font-family: monospace; font-size: 0.9rem;">
<?php if ($result['status'] === 'created'): ?>
<span style="color: #48bb78;"><?= htmlspecialchars($result['price_id']) ?></span>
<?php elseif ($result['status'] === 'already_configured'): ?>
<span style="color: #a0aec0;"><?= htmlspecialchars($result['price_id']) ?></span>
<?php else: ?>
<span style="color: #e53e3e;">N/A</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div style="margin-top: 30px; padding: 20px; background: #1a1a1a; border-radius: 8px;">
<h3 style="color: white; margin-bottom: 15px;">📝 What This Does</h3>
<ul style="color: #a0aec0; line-height: 1.8;">
<li>Checks which plans have placeholder Price IDs</li>
<li>Creates missing products and prices in Stripe</li>
<li>Automatically updates <code>config/subscription_plans.php</code></li>
<li>Skips plans that already have valid Price IDs</li>
</ul>
</div>
</div>
</main>
<?php include 'includes/footer.php'; ?>