我正在尝试在我的虚拟服务器上测试Stripe Checkout,但是当我尝试返回此错误时:
致命错误:未找到“Stripe \ Customer”类 第8行/home/user/public_html/charge.php
根据建议here我验证了文件./config.php是否存在:
的var_dump(file_exists( “./ config.php中”));
它返回bool(true)
作为PhP初学者我不知道我做错了什么。
charge.php
<?php
require_once('./config.php');
var_dump(file_exists("./config.php"));
$token = $_POST['stripeToken'];
$customer = \Stripe\Customer::create(array(
'email' => 'customer@example.com',
'source' => $token
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 2000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $20.00!</h1>';
?>
的config.php
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => getenv('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => getenv('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
目录:
>public_html >vendor >stripe >lib >Charge.php >Customer.php >Stripe.php
更新
好的,马修建议的更改会出现新的错误。但我不知道我应该在哪里设置API密钥Stripe::setApiKey(<API-KEY>)
?它在config.php
...
致命错误:未捕获异常'Stripe \ Error \ Authentication' 消息'未提供API密钥。 (提示:使用设置API密钥 “条纹:: setApiKey()” 的。 /home/user/public_html/vendor/stripe/lib/ApiRequestor.php:127 Stack 追踪:#0 /home/user/public_html/vendor/stripe/lib/ApiRequestor.php(59): Stripe \ ApiRequestor-&gt; _requestRaw('post','/ v1 / customers',Array, 数组)#1 /home/user/public_html/vendor/stripe/lib/ApiResource.php(115): Stripe \ ApiRequestor-&gt; request('post','/ v1 / customers',Array,Array)#2 /home/user/public_html/vendor/stripe/lib/ApiResource.php(155): Stripe \ ApiResource :: _ staticRequest('post','/ v1 / customers',Array, NULL)#3 /home/user/public_html/vendor/stripe/lib/Customer.php(37): Stripe \ ApiResource :: _ create(Array,NULL)#4 /home/user/public_html/charge.php(9):Stripe \ Customer :: create(Array)
5 {main}在第127行的/home/user/public_html/vendor/stripe/lib/ApiRequestor.php中抛出
答案 0 :(得分:1)
我不确定但是看起来像是作曲家,
如果你还没有检查路径,请先在 composer.json <中查看它们/ p>
{
"autoload": {
"psr-0": {
"Sub-folder/path": "class's parent directory "
}
}
注意:如果由于此问题而发生问题,您应该重新安装websocket
OR 您可以安排此结构的路径
答案 1 :(得分:0)
昨天我通过电子邮件发送了条纹支持。我无法想出答案......!因此,问题在于我在config.php
中设置API密钥的方式。这段代码不符合我们的想法......它正在尝试检索一个环境变量集,其中变量名称为API键,只返回一个空字符串......
<强>的config.php 强>
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => getenv('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => getenv('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
应
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => ('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => ('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
基本上,只需在每个箭头后移除getenv
即可。对我来说它有效!创建客户并收取金额!没有什么花哨。简单的解决方案。