Skip to content
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

Add cancelSubscription method #251

Open
wants to merge 1 commit into
base: 4.7-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CRM/Core/Payment/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,10 @@ public function doRecurPayment(&$params, $amount, $stripe_customer) {
(subscription_id, customer_id, contribution_recur_id, processor_id, end_time, is_live)
VALUES (%1, %2, %3, %4, %5, '{$this->_islive}')", $query_params);
}
// update recur processor_id with subscriptionId
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionRecur', $params['contributionRecurID'],
'processor_id', $subscription_id
);

// Don't return a $params['trxn_id'] here or else recurring membership contribs will be set
// "Completed" prematurely. Webhook.php does that.
Expand All @@ -828,6 +832,26 @@ public function doRecurPayment(&$params, $amount, $stripe_customer) {

}

/**
* @param string $message
* @param array $params
*
* @return array|bool|object
*/
public function cancelSubscription(&$message = '', $params = array()) {
// Include Stripe library then set plugin info and API credentials.
require_once('stripe-php/init.php');
\Stripe\Stripe::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL());
\Stripe\Stripe::setApiKey($this->_paymentProcessor['user_name']);

if (!empty($params['subscriptionId'])) {
$subscription = \Stripe\Subscription::retrieve($params['subscriptionId']);
$subscription->cancel();
return TRUE;
}
return FALSE;
}

/**
* Transfer method not in use.
*
Expand Down