Fix Recurring Payment Migration for stripe
This commit is contained in:
@@ -3900,24 +3900,30 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set Recurring payment method with Stripe to the new saved_payment_id and update the method to Credit Card
|
||||
$sql_recurring_payments = mysqli_query($mysqli, "SELECT * FROM recurring_payments
|
||||
LEFT JOIN invoices ON recurring_payment_recurring_invoice_id = invoice_id
|
||||
LEFT JOIN client_saved_payment_methods ON saved_payment_client_id = invoice_client_id
|
||||
WHERE recurring_payment_method = 'Stripe'"
|
||||
);
|
||||
// Look up the Stripe provider id we just inserted (or most recent one)
|
||||
$result = mysqli_query($mysqli, "
|
||||
SELECT payment_provider_id
|
||||
FROM payment_providers
|
||||
WHERE payment_provider_name = 'Stripe'
|
||||
ORDER BY payment_provider_id DESC
|
||||
LIMIT 1
|
||||
");
|
||||
$stripe = mysqli_fetch_assoc($result);
|
||||
$stripe_provider_id = intval($stripe['payment_provider_id']);
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_recurring_payments)) {
|
||||
$recurring_payment_id = intval($row['recurring_payment_id']);
|
||||
$client_id = intval($row['invoice_client_id']);
|
||||
$saved_payment_id = intval($row['saved_payment_id']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE recurring_payments SET
|
||||
recurring_payment_method = 'Credit Card',
|
||||
recurring_payment_saved_payment_id = $saved_payment_id
|
||||
WHERE recurring_payment_id = $recurring_payment_id"
|
||||
);
|
||||
}
|
||||
// Update all Stripe recurring payments to use the single saved method per client
|
||||
mysqli_query($mysqli, "
|
||||
UPDATE recurring_payments rp
|
||||
INNER JOIN invoices i
|
||||
ON rp.recurring_payment_recurring_invoice_id = i.invoice_id
|
||||
INNER JOIN client_saved_payment_methods spm
|
||||
ON spm.saved_payment_client_id = i.invoice_client_id
|
||||
AND spm.saved_payment_provider_id = $stripe_provider_id
|
||||
SET
|
||||
rp.recurring_payment_method = 'Credit Card',
|
||||
rp.recurring_payment_saved_payment_id = spm.saved_payment_id
|
||||
WHERE rp.recurring_payment_method = 'Stripe'
|
||||
");
|
||||
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '2.3.0'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user