Skip to content
Snippets Groups Projects
Commit f9b41896 authored by Joshua Walker's avatar Joshua Walker
Browse files

Merge pull request #111 from BorislavZlatanov/4.6-dev-cancelling-contribs

Support for cancelling recurring contributions.
parents 985c0c5d 90b1ea4c
No related branches found
No related tags found
No related merge requests found
......@@ -266,6 +266,59 @@ class CRM_Stripe_Page_Webhook extends CRM_Core_Page {
break;
//Subscription is cancelled
case 'customer.subscription.deleted':
// Find the recurring contribution in CiviCRM by mapping it from Stripe.
$query_params = array(
1 => array($customer_id, 'String'),
);
$rel_info_query = CRM_Core_DAO::executeQuery("SELECT invoice_id
FROM civicrm_stripe_subscriptions
WHERE customer_id = %1",
$query_params);
if (!empty($rel_info_query)) {
$rel_info_query->fetch();
if (!empty($rel_info_query->invoice_id)) {
$invoice_id = $rel_info_query->invoice_id;
} else {
CRM_Core_Error::Fatal("Error relating this customer ($customer_id) to the one in civicrm_stripe_subscriptions");
exit();
}
}
// Fetch Civi's info about this recurring contribution
$recur_contribution = civicrm_api3('ContributionRecur', 'get', array(
'sequential' => 1,
'return' => "id",
'invoice_id' => $invoice_id
));
if (!$recur_contribution['id']) {
CRM_Core_Error::Fatal("ERROR: Stripe triggered a Webhook on an invoice not found in civicrm_contribution_recur: "
. $stripe_event_data);
exit();
}
//Cancel the recurring contribution
$result = civicrm_api3('ContributionRecur', 'cancel', array(
'sequential' => 1,
'id' => $recur_contribution['id']
));
//Delete the record from Stripe's subscriptions table
$query_params = array(
1 => array($invoice_id, 'String'),
);
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_stripe_subscriptions
WHERE invoice_id = %1", $query_params);
break;
// One-time donation and per invoice payment.
case 'charge.succeeded':
// Not implemented.
......
CiviCRM Stripe Payment Processor
--------------------------------
Version 1.8+ of this extension *must* use Stripe's latest API version (at least 2013-12-03).
Go to _Account Settings_ -> _API Keys_ tab -> click _Upgrade available_ button.
More info on how to change: https://stripe.com/docs/upgrades#how-can-i-upgrade-my-api
CONFIGURATION
-------------
All configuration is in the standard Payment Processors settings area in CiviCRM admin.
WEBHOOK & RECURRING PAYMENTS
---------
The Webhook.php file is registered to the path of civicrm/stripe/webhook
You will have to make a Webhook rule in your Stripe.com account and enter this path for recurring charges to end!
For Drupal: https://example.com/civicrm/stripe/webhook
For Joomla: https://example.com/index.php/component/civicrm/?task=civicrm/stripe/webhook
For Wordpress: https://example.com/?page=CiviCRM&q=civicrm/stripe/webhook
INSTALLATION
------------
For CiviCRM 4.4 & up:
1) Your CiviCRM 'Resource URLs' must be set to the extensions directory
relative to Drupal/CRM base. Example: /sites/all/civicrm_extensions/
*NOT the full server path like /var/www/sites/all/civicrm_extensions/*
The admin page for Resource URLs is: /civicrm/admin/setting/url
2) Install extension via CiviCRM's "Manage Extensions" page.
GOOD TO KNOW
------------
* The stripe-php package has been added to this project & no longer needs to be
downloaded separately.
* You do not need the separate civicrm_stripe CMS module for 4.2 & up
* There will no longer be branches for each version. The branches will be:
* Civi's major.minor-dev, and we will create releases (tags) for each new release version.
* Example: 4.6-dev.
AUTHOR INFO
-----------
Joshua Walker
http://drastikbydesign.com
https://drupal.org/user/433663
OTHER CREDITS
-------------
Big thanks to rgburton & Swingline0 for adding wonderful new features to the project.
CiviCRM Stripe Payment Processor
--------------------------------
Version 1.8+ of this extension *must* use Stripe's latest API version (at least 2013-12-03).
Go to _Account Settings_ -> _API Keys_ tab -> click _Upgrade available_ button.
More info on how to change: https://stripe.com/docs/upgrades#how-can-i-upgrade-my-api
CONFIGURATION
-------------
All configuration is in the standard Payment Processors settings area in CiviCRM admin.
WEBHOOK & RECURRING PAYMENTS
---------
The Webhook.php file is registered to the path of civicrm/stripe/webhook
You will have to make a Webhook rule in your Stripe.com account and enter this path for recurring charges to end!
For Drupal: https://example.com/civicrm/stripe/webhook
For Joomla: https://example.com/index.php/component/civicrm/?task=civicrm/stripe/webhook
For Wordpress: https://example.com/?page=CiviCRM&q=civicrm/stripe/webhook
INSTALLATION
------------
For CiviCRM 4.4 & up:
1) Your CiviCRM 'Resource URLs' must be set to the extensions directory
relative to Drupal/CRM base. Example: /sites/all/civicrm_extensions/
*NOT the full server path like /var/www/sites/all/civicrm_extensions/*
The admin page for Resource URLs is: /civicrm/admin/setting/url
2) Install extension via CiviCRM's "Manage Extensions" page.
CANCELLING RECURRING CONTRIBUTIONS
------------
You can cancel a recurring contribution from the Stripe.com dashboard. Go to Customers and then to the specific customer.
Inside the customer you will see a Subscriptions section. Click Cancel on the subscription you want to cancel.
Stripe.com will cancel the subscription and will send a webhook to your site (if you have set the webhook options correctly).
Then the stripe_civicrm extension will process the webhook and cancel the Civi recurring contribution.
GOOD TO KNOW
------------
* The stripe-php package has been added to this project & no longer needs to be
downloaded separately.
* You do not need the separate civicrm_stripe CMS module for 4.2 & up
* There will no longer be branches for each version. The branches will be:
* Civi's major.minor-dev, and we will create releases (tags) for each new release version.
* Example: 4.6-dev.
AUTHOR INFO
-----------
Joshua Walker
http://drastikbydesign.com
https://drupal.org/user/433663
OTHER CREDITS
-------------
Big thanks to rgburton & Swingline0 for adding wonderful new features to the project.
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