Another attempt to fix reccuring payment migration to match the correct client_id;

This commit is contained in:
johnnyq
2025-09-04 16:29:55 -04:00
parent d37da2e8ff
commit cece9ad46c

View File

@@ -3900,26 +3900,26 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
} }
} }
// Look up the Stripe provider id we just inserted (or most recent one) // Get Stripe provider id
$result = mysqli_query($mysqli, " $res = mysqli_query($mysqli, "
SELECT payment_provider_id SELECT payment_provider_id
FROM payment_providers FROM payment_providers
WHERE payment_provider_name = 'Stripe' WHERE payment_provider_name = 'Stripe'
ORDER BY payment_provider_id DESC ORDER BY payment_provider_id DESC
LIMIT 1 LIMIT 1
"); ");
$stripe = mysqli_fetch_assoc($result); $stripe = mysqli_fetch_assoc($res);
$stripe_provider_id = intval($stripe['payment_provider_id']); $stripe_provider_id = intval($stripe['payment_provider_id']);
// Update all Stripe recurring payments to use the single saved method per client // Correct mapping: RP -> Recurring Invoice -> Client -> Client's Stripe saved method
mysqli_query($mysqli, " mysqli_query($mysqli, "
UPDATE recurring_payments rp UPDATE recurring_payments rp
INNER JOIN invoices i INNER JOIN recurring_invoices ri
ON rp.recurring_payment_recurring_invoice_id = i.invoice_id ON ri.recurring_invoice_id = rp.recurring_payment_recurring_invoice_id
INNER JOIN client_saved_payment_methods spm INNER JOIN client_saved_payment_methods spm
ON spm.saved_payment_client_id = i.invoice_client_id ON spm.saved_payment_client_id = ri.recurring_invoice_client_id
AND spm.saved_payment_provider_id = $stripe_provider_id AND spm.saved_payment_provider_id = $stripe_provider_id
SET SET
rp.recurring_payment_method = 'Credit Card', rp.recurring_payment_method = 'Credit Card',
rp.recurring_payment_saved_payment_id = spm.saved_payment_id rp.recurring_payment_saved_payment_id = spm.saved_payment_id
WHERE rp.recurring_payment_method = 'Stripe' WHERE rp.recurring_payment_method = 'Stripe'