Skip to content
Snippets Groups Projects
Commit e5b648c4 authored by anemirovsky's avatar anemirovsky
Browse files

Fix Stripe recurring payments remain Pending in CiviCRM.

This happens if a contact already has an active Stripe subscription due to a
previous recurring contribution that is not completed yet and if they create
a new recurring contribution and change only the amount, without changing the
frequency/installments, then Stripe will wait to charge the card until the
next installment is due. CiviCRM, expects the charge to be immediate, so the
first contribution does not get marked as Completed, and more importantly,
never appears in Stripe, since the card didn't actually get charged.

To correct this, we have to first cancel any existing active subscriptions
for that contact. Then, everything works correctly.
parent 7509ced7
No related branches found
No related tags found
No related merge requests found
......@@ -433,6 +433,19 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
VALUES (%1)", $query_params);
}
// If a contact/customer has an existing active recurring
// contribution/subscription, Stripe will update the existing subscription.
// If only the amount has changed not the installments/frequency, Stripe
// will not charge the card again until the next installment is due. This
// does not work well for CiviCRM, since CiviCRM creates a new recurring
// contribution along with a new initial contribution, so it expects the
// card to be charged immediately. So, since Stripe only supports one
// subscription per customer, we have to cancel the existing active
// subscription first.
if (!empty($stripe_customer->subscription) && $stripe_customer->subscription-> status == 'active') {
$stripe_customer->cancelSubscription();
}
// Attach the Subscription to the Stripe Customer.
$stripe_response = $stripe_customer->updateSubscription(array(
'prorate' => FALSE, 'plan' => $plan_id));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment