Skip to content
Snippets Groups Projects
Commit 59e18019 authored by BorislavZlatanov's avatar BorislavZlatanov
Browse files

Resolved merge conflicts

parents 59356122 3fee1676
Branches
Tags
No related merge requests found
......@@ -574,8 +574,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
// 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();
$subscriptions = $stripe_customer->offsetGet('subscriptions');
$data = $subscriptions->offsetGet('data');
if(!empty($data)) {
$status = $data[0]->offsetGet('status');
if ($status == 'active') {
$stripe_customer->cancelSubscription();
}
}
// Attach the Subscription to the Stripe Customer.
......
......@@ -251,6 +251,57 @@ class CRM_Stripe_Page_Webhook extends CRM_Core_Page {
// This has failed more than once. Now what?
}
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.
......@@ -264,4 +315,4 @@ class CRM_Stripe_Page_Webhook extends CRM_Core_Page {
parent::run();
}
}
}
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.
......@@ -143,9 +143,11 @@
if ($('#priceset').length) {
additionalParticipants = cj("#additional_participants").val();
// The currentTotal is already being calculated in Form/Contribution/Main.tpl.
if (currentTotal == 0 && !additionalParticipants) {
// This is also hit when "Going back", but we already have stripe_token.
return true;
if(typeof currentTotal !== 'undefined') {
if (currentTotal == 0 && !additionalParticipants) {
// This is also hit when "Going back", but we already have stripe_token.
return true;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment