More Stripe Troubleshooting

This commit is contained in:
Ruben Ramirez 2025-04-04 03:29:41 -05:00
parent 257ff33d83
commit 9f8108caa0
2 changed files with 32 additions and 32 deletions

View file

@ -315,29 +315,29 @@ add_action( 'rest_api_init', 'quiztech_register_rest_routes' );
* Set the CUSTOM_DEBUG_LOG file in wp-config.php
*
*/
// function log_to_file($message, $data = false){
// // Only proceed if a message is provided
// if ($message) {
// // Check if the custom log file constant is defined
// if (defined('CUSTOM_DEBUG_LOG') && CUSTOM_DEBUG_LOG) {
// $log_File = CUSTOM_DEBUG_LOG;
function log_to_file2($message, $data = false){
// Only proceed if a message is provided
if ($message) {
// Check if the custom log file constant is defined
if (defined('CUSTOM_DEBUG_LOG') && CUSTOM_DEBUG_LOG) {
$log_File = CUSTOM_DEBUG_LOG;
// $date = new DateTime();
// $date = $date->format("Y/m/d h:i:s");
$date = new DateTime();
$date = $date->format("Y/m/d h:i:s");
// // Convert arrays and objects to JSON format
// if (is_array($data) || is_object($data)) {
// $data = json_encode($data, JSON_PRETTY_PRINT);
// $message = $message . "\r\n" . $data;
// } else if ($data) {
// $message = $message . " " . $data;
// }
// Convert arrays and objects to JSON format
if (is_array($data) || is_object($data)) {
$data = json_encode($data, JSON_PRETTY_PRINT);
$message = $message . "\r\n" . $data;
} else if ($data) {
$message = $message . " " . $data;
}
// // Log the message to the specified file
// error_log("[$date] " . $message ."\r\n", 3, $log_File);
// }
// // If CUSTOM_DEBUG_LOG is not defined, do nothing (fail silently)
// // Alternatively, could log to default PHP error log:
// // else { error_log("Quiztech Debug: " . $message); }
// }
// }
// Log the message to the specified file
error_log("[$date] " . $message ."\r\n", 3, $log_File);
}
// If CUSTOM_DEBUG_LOG is not defined, do nothing (fail silently)
// Alternatively, could log to default PHP error log:
// else { error_log("Quiztech Debug: " . $message); }
}
}

View file

@ -15,7 +15,7 @@ use WP_Error;
* Handles Stripe payment gateway interactions.
*/
class StripeGateway {
\log_to_file('StripeGateway::initiatePayment - START');
log_to_file2('StripeGateway::initiatePayment - START');
/**
* Initiate a payment process via Stripe (e.g., create Checkout Session).
@ -29,7 +29,7 @@ class StripeGateway {
* @return WP_Error|void Returns WP_Error on failure. Redirects user on success.
*/
public function initiatePayment( $user_id, $item_id, $quantity, $price_in_cents, $currency, $metadata ) {
\log_to_file('StripeGateway::initiatePayment - Secret key retrieved (empty=' . (empty($secret_key) ? 'yes' : 'no') . ')');
log_to_file2('StripeGateway::initiatePayment - Secret key retrieved (empty=' . (empty($secret_key) ? 'yes' : 'no') . ')');
// Retrieve Stripe Secret Key
$options = get_option('quiztech_settings');
@ -42,19 +42,19 @@ class StripeGateway {
// Ensure Stripe library is loaded (via Composer autoload)
if ( ! class_exists( '\Stripe\Stripe' ) ) { // Check with leading slash here is okay as it's a general check
\log_to_file('StripeGateway::initiatePayment - Stripe class check FAILED.');
log_to_file2('StripeGateway::initiatePayment - Stripe class check FAILED.');
error_log( 'Quiztech Stripe Error: Stripe PHP library not found. Ensure composer install was run.' );
return new WP_Error( 'stripe_lib_error', __( 'Payment processing library is missing. Please contact the site administrator.', 'quiztech' ) );
}
try {
\log_to_file('StripeGateway::initiatePayment - Attempting to set API key.');
log_to_file2('StripeGateway::initiatePayment - Attempting to set API key.');
Stripe::setApiKey( $secret_key );
// Get the URL for the Manage Credits page
\log_to_file('StripeGateway::initiatePayment - Attempting to get manage-credits page.');
log_to_file2('StripeGateway::initiatePayment - Attempting to get manage-credits page.');
$manage_credits_page = get_page_by_path('manage-credits'); // Assumes page slug is 'manage-credits'
if (!$manage_credits_page) {
@ -64,8 +64,8 @@ class StripeGateway {
$success_url = add_query_arg( 'purchase_status', 'success', $base_url );
$cancel_url = add_query_arg( 'purchase_status', 'cancelled', $base_url );
\log_to_file('StripeGateway::initiatePayment - Success URL: ' . $success_url);
\log_to_file('StripeGateway::initiatePayment - Cancel URL: ' . $cancel_url);
log_to_file2('StripeGateway::initiatePayment - Success URL: ' . $success_url);
log_to_file2('StripeGateway::initiatePayment - Cancel URL: ' . $cancel_url);
@ -75,7 +75,7 @@ class StripeGateway {
$credit_amount_display = isset($matches[1]) ? $matches[1] : $item_id;
$item_name = sprintf( __( 'Quiztech Credits - %s Pack', 'quiztech' ), $credit_amount_display );
\log_to_file('StripeGateway::initiatePayment - Attempting Session::create.');
log_to_file2('StripeGateway::initiatePayment - Attempting Session::create.');
$session = Session::create( [
'payment_method_types' => ['card'],
@ -101,7 +101,7 @@ class StripeGateway {
// Redirect to Stripe Checkout
if ( isset( $session->url ) ) {
\log_to_file('StripeGateway::initiatePayment - Session created. Redirecting to: ' . $session->url);
log_to_file2('StripeGateway::initiatePayment - Session created. Redirecting to: ' . $session->url);
error_log("Quiztech StripeGateway: Attempting redirect to Stripe URL: " . $session->url);
wp_safe_redirect( $session->url );
// If execution reaches here, exit() failed or was bypassed.