![]() 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/.cursor-server/data/User/History/364c57f/ |
<?php
// Test script to debug process_credit_payment.php
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo "Testing process_credit_payment.php...\n";
// Test 1: Check if the file exists and is readable
if (!file_exists('process_credit_payment.php')) {
echo "ERROR: process_credit_payment.php not found\n";
exit;
}
echo "✓ File exists\n";
// Test 2: Check if config/database.php exists
if (!file_exists('config/database.php')) {
echo "ERROR: config/database.php not found\n";
exit;
}
echo "✓ Database config exists\n";
// Test 3: Test database connection
try {
require_once 'config/database.php';
echo "✓ Database config loaded\n";
// Test database connection
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
echo "✓ Database connection successful\n";
} catch (Exception $e) {
echo "ERROR: Database connection failed: " . $e->getMessage() . "\n";
exit;
}
// Test 4: Test Stripe key format
$stripe_secret_key = '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';
if (strpos($stripe_secret_key, 'sk_live_') === 0) {
echo "✓ Stripe live key format looks correct\n";
} else {
echo "ERROR: Stripe key format looks wrong\n";
}
// Test 5: Test cURL functionality
if (function_exists('curl_init')) {
echo "✓ cURL is available\n";
} else {
echo "ERROR: cURL is not available\n";
exit;
}
// Test 6: Test JSON functions
if (function_exists('json_encode') && function_exists('json_decode')) {
echo "✓ JSON functions are available\n";
} else {
echo "ERROR: JSON functions are not available\n";
exit;
}
// Test 7: Test session functionality
if (function_exists('session_start')) {
echo "✓ Session functions are available\n";
} else {
echo "ERROR: Session functions are not available\n";
exit;
}
echo "\nAll basic tests passed. The issue might be in the logic.\n";
// Test 8: Simulate the actual request
echo "\nSimulating actual request...\n";
// Mock session
$_SESSION['user_id'] = 1;
// Mock input
$input = [
'action' => 'process_cart_payment',
'cart' => [
[
'package' => 'starter',
'quantity' => 1
]
]
];
echo "Input: " . json_encode($input) . "\n";
// Test the logic step by step
try {
// Test credit packages array
$credit_packages = [
'starter' => [
'name' => 'Starter',
'credits' => 30,
'price' => 1999, // $19.99 in cents
'stripe_price_id' => 'price_starter_credits'
],
'pro' => [
'name' => 'Pro',
'credits' => 200,
'price' => 5900, // $59.00 in cents
'stripe_price_id' => 'price_pro_credits'
],
'premium' => [
'name' => 'Premium',
'credits' => 500,
'price' => 12900, // $129.00 in cents
'stripe_price_id' => 'price_premium_credits'
]
];
echo "✓ Credit packages defined\n";
// Test cart processing logic
$cart_data = $input['cart'] ?? [];
if (empty($cart_data)) {
throw new Exception('Cart is empty');
}
echo "✓ Cart data received\n";
// Handle different cart formats
$credit_items = [];
$track_items = [];
if (isset($cart_data['credits']) && isset($cart_data['tracks'])) {
// New mixed cart format with credits and tracks properties
$credit_items = $cart_data['credits'] ?? [];
$track_items = $cart_data['tracks'] ?? [];
} elseif (is_array($cart_data) && !empty($cart_data) && isset($cart_data[0]['package'])) {
// Frontend is sending credit items array directly
$credit_items = $cart_data;
$track_items = [];
} else {
// Legacy format - assume all items are credits
$credit_items = $cart_data;
$track_items = [];
}
echo "✓ Cart format processed\n";
echo "Credit items: " . json_encode($credit_items) . "\n";
echo "Track items: " . json_encode($track_items) . "\n";
// Calculate total amount and credits
$total_amount = 0;
$total_credits = 0;
$cart_summary = [];
// Process credit items
foreach ($credit_items as $item) {
$package_id = $item['package'];
$quantity = $item['quantity'];
if (!isset($credit_packages[$package_id])) {
throw new Exception('Invalid package in cart: ' . $package_id);
}
$package = $credit_packages[$package_id];
$item_total = $package['price'] * $quantity;
$item_credits = $package['credits'] * $quantity;
$total_amount += $item_total;
$total_credits += $item_credits;
$cart_summary[] = [
'type' => 'credit',
'package' => $package_id,
'name' => $package['name'],
'credits' => $item_credits,
'quantity' => $quantity,
'amount' => $item_total
];
}
echo "✓ Credit items processed\n";
echo "Total amount: $total_amount cents\n";
echo "Total credits: $total_credits\n";
// Test Stripe API call
echo "\nTesting Stripe API call...\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/payment_intents');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $stripe_secret_key,
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'amount' => $total_amount,
'currency' => 'usd',
'metadata' => json_encode([
'user_id' => $_SESSION['user_id'],
'cart_items' => json_encode($cart_summary),
'total_credits' => $total_credits,
'has_tracks' => !empty($track_items),
'subscription_period' => '30_days',
'payment_type' => 'mixed_cart_checkout'
])
]));
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_error) {
throw new Exception('cURL Error: ' . $curl_error);
}
echo "✓ Stripe API call completed\n";
echo "HTTP Code: $http_code\n";
if ($http_code !== 200) {
echo "ERROR: Stripe API returned HTTP $http_code\n";
echo "Response: $response\n";
exit;
}
$payment_intent = json_decode($response, true);
if (!$payment_intent || !isset($payment_intent['client_secret'])) {
echo "ERROR: Invalid response from Stripe\n";
echo "Response: $response\n";
exit;
}
echo "✓ Stripe payment intent created successfully\n";
echo "Payment Intent ID: " . $payment_intent['id'] . "\n";
echo "Client Secret: " . substr($payment_intent['client_secret'], 0, 20) . "...\n";
$response_data = [
'success' => true,
'client_secret' => $payment_intent['client_secret'],
'payment_intent_id' => $payment_intent['id'],
'amount' => $total_amount,
'credits' => $total_credits,
'cart_summary' => $cart_summary
];
echo "\n✓ Final response data:\n";
echo json_encode($response_data, JSON_PRETTY_PRINT) . "\n";
} catch (Exception $e) {
echo "ERROR: " . $e->getMessage() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}
echo "\nTest completed.\n";
?>