bryanx
bryanx

Reputation: 169

Call to undefined method Stripe\Subscription::retrieve()

I'm using Stripe within CodeIgniter and here is how I have it set up:

Within my Stripe controller, I am calling the library by the following:

require_once(APPPATH.'libraries/stripe/init.php');

This is per Stripe - PHP Fatal error: Class 'Stripe\Charge' not found

The function that is failing is:

function cancelSubscription($stripeaccount){

    $customer = \Stripe\Customer::retrieve($stripeaccount);
    $sub_id = $customer->subscriptions->data[0]->id;    
    echo $sub_id;
    $subscription = \Stripe\Subscription::retrieve($sub_id);
    $subscription->cancel();

}

I've confirmed through the echo that the \Stripe\Customer call on the first line is in fact working and pulling back the subscription ID. However, it's failing when I try to retrieve the subscription on the 4th line with:

Fatal error: Call to undefined method Stripe\Subscription::retrieve()

Stripe's documentation gives the following example:

$sub = \Stripe\Subscription::retrieve("sub_8PVEGdSaepQU26");
$sub->cancel();

And as you can see, with exception to my variable names, it's the same. I'm coming up blank on this one, any help would be appreciated.

Results of:

print_r(get_class_methods('\Stripe\Subscription'));

[0] => instanceUrl [1] => cancel [2] => save [3] => deleteDiscount [4] => baseUrl [5] => refresh [6] => className [7] => classUrl [8] => init [9] => __construct [10] => __set [11] => __isset [12] => __unset [13] => __get [14] => offsetSet [15] => offsetExists [16] => offsetUnset [17] => offsetGet [18] => keys [19] => constructFrom [20] => refreshFrom [21] => serializeParameters [22] => __toJSON [23] => __toString [24] => __toArray

Upvotes: 5

Views: 7684

Answers (2)

Poonam
Poonam

Reputation: 549

If don't wanna update stripe then simply use this function to cancel the subscription:

function cancelSubscription($stripeaccount){
      //$stripeaccount will be customer_id
    $customer = \Stripe\Customer::retrieve($stripeaccount);
    $sub_id->cancelSubscription(); 
      // cancelSubscription() is a function in Stripe_Customer Class,
      // So without getting subscription detail direct cancel the subscription 

 }

For more explanation, Please have a look here: Can't cancel the subscription on stripe in cakephp

Upvotes: 1

Matthew Arkin
Matthew Arkin

Reputation: 4648

The \Stripe\Subscription::retrieve api is very new and requires the latest version of the stripe-php library (3.13.0), you should try updating your Stripe library.

Upvotes: 9

Related Questions