-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow to cancel subscription through CiviCRM #241
base: 4.7-dev
Are you sure you want to change the base?
Conversation
Interesting! So does this get called when the cancel button is clicked on a Recurring Contribution? |
yes, on clicking on 'cancel' link , pop will open , it has options (e.g notify user) like other payment processor have. |
I haven't tested this, but I feel like we'd be causing an error once the webhook receives the 'customer.subscription.deleted' event because that code currently cancels the recurring contribution. In this case the recurring contribution would already be canceled. Have you tested this and/or are you seeing such an error? Thanks |
https://github.com/drastik/com.drastikbydesign.stripe/blob/4.7-dev/CRM/Stripe/Page/Webhook.php#L335 https://github.com/civicrm/civicrm-core/blob/master/CRM/Contribute/BAO/ContributionRecur.php#L253 recurring cancel api check status is not cancelled before going further. so there would not be any issue. |
Hi, what's your opinion on my last comment.? |
Is this something that currently does not work with the current codebase? |
@sunilpawar I was having difficulty understanding your sentence. But I think I have it now.
With the API explorer, I just tried canceling an already-canceled recurring contribution with seemingly no ill effects. @sunilpawar Have you have a chance to test your code? @drastik currently the way we're doing it is cancel in the Stripe UI and the event triggers the Recurring Contribution cancelation in Civi. |
@h-c-c , yes i have tested this on live and test mode. |
CRM/Core/Payment/Stripe.php
Outdated
\Stripe\Stripe::setApiKey($this->_paymentProcessor['user_name']); | ||
$subscription = \Stripe\Subscription::retrieve($params['subscriptionId']); | ||
$subscription->cancel(); | ||
return TRUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct.
CRM/Core/Payment/Stripe.php
Outdated
@@ -817,6 +817,10 @@ public function doRecurPayment(&$params, $amount, $stripe_customer) { | |||
VALUES (%1, %2, %3, %4, %5, '{$this->_islive}')", $query_params); | |||
} | |||
|
|||
// update recur processor_id with subscriptionId | |||
if ($subscription_id && $recuring_contribution_id) { | |||
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionRecur', $recuring_contribution_id, 'processor_id', $subscription_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the Contributionrecur.create API here instead of accessing the DAO object directly? It's less likely to break in the future if we use the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire , used api instead of DAO function
@sunilpawar I just gave this a spin. When I attempt to cancel a subscription that is already canceled through the Stripe UI, it throughly locks up my civi session. Maybe we should check to see if the subscription is active before canceling it, and maybe give feedback that it doesn't exist if that's the case, and just cancel the recurring contribution. If we proceed like this, then there's probably no need for the "Send cancellation request to Stripe?" option. What do you think? Thanks! |
@h-c-c is there way to check subscription is active, because retrieve cancelled subscription using api throwing error message 'No such subscription: sub_xxxxxxx' |
We should init Stripe once in a constructor, that way we don't call these |
@sunilpawar I'm against this radio button choice for "Send cancellation request to Stripe?". I'm trying to think of a valid use case for letting the user get their systems out of sync and I really can't think of good reason. Am I missing something? Seems like we should always cancel the subscription in Stripe and simply delete the recurring contribution if it's somehow already gone. What do you think? Thanks! |
The "send cancellation request" is part of core CiviCRM. The use case is that you can cancel recurring payments on the payment processor side, which doesn't update CiviCRM. It's not uncommon for folks to do so, not realizing there's a more correct way. I see this a lot when people switch from having a PayPal "Donate" button to using Civi - their staff are used to cancelling recurring contributions from within PayPal itself. I don't think this should block a merge. |
Thanks @MegaphoneJon, good to know! I understand the scenario, but not the use case. I think a better approach would be to always try to cancel on the payprocessor side and catch silently, with the assumption that we never want an active subscription without a a matching active recurring contribution. My feeling is, if we don't have to give users a way to shoot themselves in the foot, then let's not. I guess I was more specifically asking, is there a valid use case for having a canceled recurring contribution and active subscription. I see none at this time. Leaving the radio buttons seems like a potential pitfall, much less so if "yes" was set as the default option. It's a little detail, but ultimately a kindness I feel. @sunilpawar what if we take this approach? -break up the initialization and cancel in to two different try statements. That should hand the already-canceled situation I think. |
Hi @h-c-c - the use cases I've encountered are:
There's also "testing", but I think that can be handled more elegantly in other ways. |
@h-c-c This is back-end option for Admin/Support team who perform these operation and its safe (not every have access to payment processor site to cancel recurring payment if requested by end user). That's why these feature available through API. CiviCRM have similar feature for other Payment processor (AuthorizeNet, PayPal Pro) |
ha! I'm pretty sure that means it's not safe. That is after all, the point of @MegaphoneJon 's use case....that admin people make errors. What do think about the proposed solution to your question?
|
I think this is an important feature and I would really like to see it added. It seems like the only outstanding issue is h-c-c's suggestion about how to handle the already canceled subscription. I would only add one more thing... the civicrm_contribution_recur table does not have the subscription id (aka processor_id) in it. That means any attempt to cancel a recurring contribution that was made before this patch will fail. I would suggest two steps:
|
I'd only add that the extension should gracefully handle the situation where a subscription is already canceled from within Stripe. With the PayPal processor, pressing the "Cancel Recurring Contribution" button hangs CiviCRM, and leaves a message in the CiviCRM log. |
@sunilpawar To deal with the already canceled situation, apparently we can see if $subscription->ended_at is set. Found here: Probably a good idea to keep the try/catches in there anyway. |
I will add this, Thank @h-c-c for link. |
Is this PR still moving forward?The feature would be highly appreciated. 👍 |
#240 allow to cancel subscription through CiviCRM