Stripe - PHP致命错误:未找到类'Stripe\Charge' [英] Stripe - PHP Fatal error: Class 'Stripe\Charge' not found

查看:1195
本文介绍了Stripe - PHP致命错误:未找到类'Stripe\Charge'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注Stripe文档,我无法创建费用。

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

Charge.php


Charge.php

require('/var/www/stripe-php-2.1.1/lib/Stripe.php');
\Stripe\Stripe::setApiKey("KEY_HERE");

\Stripe\Charge::create(array(
  "amount" => 400,
  "currency" => "usd",
  "source" => "TOKEN_HERE", // obtained with Stripe.js
  "description" => "Charge for test@example.com"
));
?>



我可以处理第一个命令\Stripe\Stripe :: setApiKey KEY_HERE);但在处理下一个错误时收到错误,并收到以下错误:
类别'Stripe \Charge'在/var/www/charge.php中找不到

I'm able to process the first command "\Stripe\Stripe::setApiKey("KEY_HERE");" but receive an error when processing the next and receive the following error: "Class 'Stripe\Charge' not found in /var/www/charge.php"

推荐答案

如果您不使用作曲家安装条纹库,你需要手动包括所有的Stripe类。

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

Composer是处理类自动加载的首选方法。这是一个示例的作曲家文件:

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

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

在您的项目的目录中,您需要运行 composer update 命令行。然后,只需添加 require'vendor / autoload.php'; 到您的php文件的顶部。

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.

,用此代码替换 require('/ var / www / stripe-php-2.1.1 / lib / Stripe.php'); ,以包含所有类: / p>

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';
}

这篇关于Stripe - PHP致命错误:未找到类'Stripe\Charge'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆