Can't cancel the subscription on stripe in cakephp

删除回忆录丶 提交于 2019-12-14 03:25:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!