From 401f0dfce348179bccc859be4086b8f8cd410217 Mon Sep 17 00:00:00 2001 From: Wrongecho Date: Sun, 30 Aug 2026 14:09:44 +0100 Subject: [PATCH] Stripe ID creation/linking for guest flows --- guest/guest_pay_invoice_stripe.php | 2 +- guest/guest_pay_setup_stripe_customer.php | 2 +- guest/guest_view_invoice.php | 32 ++++++++++++++++++----- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/guest/guest_pay_invoice_stripe.php b/guest/guest_pay_invoice_stripe.php index ff0664724..f0da772c3 100644 --- a/guest/guest_pay_invoice_stripe.php +++ b/guest/guest_pay_invoice_stripe.php @@ -5,7 +5,7 @@ require_once 'includes/inc_all_guest.php'; DEFINE("WORDING_PAYMENT_FAILED", "

There was an error verifying your payment. Please contact us for more information before attempting payment again.

"); // --- Get Stripe config from payment_providers table --- -$stripe_provider = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT payment_provider_account, payment_provider_private_key, payment_provider_public_key FROM payment_providers")); +$stripe_provider = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT payment_provider_account, payment_provider_private_key, payment_provider_public_key FROM payment_providers WHERE payment_provider_name = 'Stripe' LIMIT 1")); $stripe_publishable = escapeHtml($stripe_provider['payment_provider_public_key']); diff --git a/guest/guest_pay_setup_stripe_customer.php b/guest/guest_pay_setup_stripe_customer.php index 8f0681169..84136d8e8 100644 --- a/guest/guest_pay_setup_stripe_customer.php +++ b/guest/guest_pay_setup_stripe_customer.php @@ -3,7 +3,7 @@ require_once 'includes/inc_all_guest.php'; // --- Get Stripe config from payment_providers table --- -$stripe_provider = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT payment_provider_id, payment_provider_account, payment_provider_private_key, payment_provider_public_key FROM payment_providers")); +$stripe_provider = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT payment_provider_id, payment_provider_account, payment_provider_private_key, payment_provider_public_key FROM payment_providers WHERE payment_provider_name = 'Stripe' LIMIT 1")); $stripe_provider_id = intval($stripe_provider['payment_provider_id']); $stripe_publishable = escapeHtml($stripe_provider['payment_provider_public_key']); diff --git a/guest/guest_view_invoice.php b/guest/guest_view_invoice.php index d078e379d..baee7ed22 100644 --- a/guest/guest_view_invoice.php +++ b/guest/guest_view_invoice.php @@ -95,12 +95,22 @@ $company_locale = escapeHtml($row['company_locale']); $config_invoice_footer = escapeHtml($row['config_invoice_footer']); // Get Payment Provide Details -$sql = mysqli_query($mysqli, "SELECT payment_provider_id, payment_provider_name, payment_provider_threshold FROM payment_providers WHERE payment_provider_active = 1 LIMIT 1"); +$sql = mysqli_query($mysqli, "SELECT payment_provider_id, payment_provider_name, payment_provider_threshold FROM payment_providers WHERE payment_provider_active = 1 AND payment_provider_name = 'Stripe' LIMIT 1"); $row = mysqli_fetch_assoc($sql); -$payment_provider_id = intval($row['payment_provider_id']); +$payment_provider_id = $stripe_provider_id = intval($row['payment_provider_id']); $payment_provider_name = escapeHtml($row['payment_provider_name']); $payment_provider_threshold = floatval($row['payment_provider_threshold']); + +// Get client's Stripe customer ID +$stripe_customer_query = mysqli_query($mysqli, " + SELECT payment_provider_client FROM client_payment_provider + WHERE client_id = $client_id AND payment_provider_id = $stripe_provider_id + LIMIT 1 +"); +$stripe_customer = mysqli_fetch_assoc($stripe_customer_query); +$stripe_customer_id = $stripe_customer ? escapeSql($stripe_customer['payment_provider_client']) : null; + //Set Currency Format $currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY); @@ -179,8 +189,8 @@ if ($balance > 0) { Download - 0) { $payment_provider_threshold == 0 || $payment_provider_threshold > $invoice_amount ) - ){ ?> - Pay Now - + ) + { + // Stripe - Online payment (either setup a customer record, or pay directly if customer record already exists) + // Needs adjusting if we do ever add more payment providers but fine for now. + if ($stripe_customer_id) { ?> + Pay Now + + Pay Now +