问题
I'm using this Cakephp StripeComponent plugin : https://github.com/chronon/CakePHP-StripeComponent-Plugin
Everything is working fine but I can't cancel the subscription with this plugin.
I had tried this https://stripe.com/docs/api#cancel_subscription, but no success.
As its saying to retrieve
the subscription and then cancel()
But this plugin doesn't have any retrieve subscription
function.
When I tried this,
$sub = \Stripe\Subscription::retrieve('SUBSCRIPTION_ID');
$sub->cancel();
I'm getting error Fatal error: Call to undefined method Stripe\Subscription::retrieve()
I'm stuck.. Please help me out from this.
回答1:
Call this function as
Stripe_Subscription::retrieve('SUBSCRIPTION_ID')
回答2:
I searched this problem too much on google but I got only some results like
Update Stripe library to 3.13.0.
Add custom functions.... etc.
Finally I solved this problem by myself..
In the StripeComponent.php
, write this function:
public function subscriptionCancel($cust_id) {
Stripe::setApiKey($this->key);
$customer = false;
try {
$customer = Stripe_Customer::retrieve($cust_id);
$customer->cancelSubscription();
} catch (Exception $e) {
return false;
}
return $customer;
}
And call this function subscriptionCancel()
in your Controller as:
$subscription = $this->Stripe->subscriptionCancel($cust_id);
So the subscription related to particular $cust_id
will be canceled.
来源:https://stackoverflow.com/questions/40174904/cant-cancel-the-subscription-on-stripe-in-cakephp