Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 751
bryanx Avatar asked Dec 24 '22 06:12

bryanx


1 Answers

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.

like image 63
Matthew Arkin Avatar answered Jan 05 '23 06:01

Matthew Arkin