Search code examples
stripe-paymentsstripe-connectstripe.net

Stripe subscriptions do not work whichever version of the api I use


Hi I am trying to change my payment method to use stripe. I am creating a plan and a customer and subscriptions for the customer using the code,

    \Stripe\Stripe::setApiKey("stripe api key");                                    
    $plan = \Stripe\Plan::create(array(
      "name" => $randomString,
      "id" => $randomString,
      "interval" => "month",
      "currency" => "usd",
      "amount" => $amtincents,
    ));
    \Stripe\Stripe::setApiKey("stripe api key");                                    
    $cust = \Stripe\Customer::create(array(
              "email" => $emailval,
            ));
    $custid = $cust->id;
    \Stripe\Stripe::setApiKey("stripe api key");                                    
    \Stripe\Subscription::create(array(
      "customer" => $custid,
      "plan" => $randomString,
    ));

The plan and customer get created but no matter which version of the stripe api I use I get the error 'Method \Stripe\Subscription not found' when I try to subscribe the customer to the plan. Any help would be appreciated.


Solution

  • You're using an older version of Stripe's PHP bindings. The Subscription methods were added in version 3.13.0.

    You should upgrade to the latest version (currently 4.3.0). You can download it from the repository: https://github.com/stripe/stripe-php/releases, or upgrade using Composer if you used it to install the library.