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

前端 未结 2 605
无人共我
无人共我 2021-01-12 02:48

I\'ve been following the Stripe documentation and I am unable to create a \"charge\".

Charge.php

require(\'/var/www/stripe-php-2.1.1/lib/Stripe.php\         


        
2条回答
  •  不思量自难忘°
    2021-01-12 03:22

    If you don't use composer to install the Stripe library you will need to manually include all of the Stripe classes.

    Composer is the preferred way as it will handle the autoloading of classes. Here is a sample composer file:

    {
      "require": {
        "stripe/stripe-php": "2.*"
      }
    }
    

    And then from a command line you would need to run composer update while in the directory for your project. Afterwards, just add require 'vendor/autoload.php'; to the top of your php file.

    Otherwise, replace require('/var/www/stripe-php-2.1.1/lib/Stripe.php');with this code to include all of the classes:

    $stripeClassesDir = __DIR__ . '/stripe-php-2.1.1/lib/';
    $stripeUtilDir    = $stripeClassesDir . 'Util/';
    $stripeErrorDir   = $stripeClassesDir . 'Error/';
    
    set_include_path($stripeClassesDir . PATH_SEPARATOR . $stripeUtilDir . PATH_SEPARATOR . $stripeErrorDir);
    
    function __autoload($class)
    {
        $parts = explode('\\', $class);
        require end($parts) . '.php';
    }
    

提交回复
热议问题