Can't cancel the subscription on stripe in cakephp
Asked Answered
S

2

0

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.

Slotter answered 21/10, 2016 at 10:59 Comment(0)
S
0

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.

Slotter answered 21/10, 2016 at 11:58 Comment(0)
O
0

Call this function as

    Stripe_Subscription::retrieve('SUBSCRIPTION_ID')
Ostracon answered 21/10, 2016 at 11:56 Comment(1)
I tried but got this error Fatal error: Call to undefined method Stripe\Subscription::retrieve()Slotter
S
0

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.

Slotter answered 21/10, 2016 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.