【发布时间】:2016-11-05 15:37:23
【问题描述】:
我正在尝试在我的虚拟服务器上测试 Stripe Checkout,但是当我尝试返回此错误时:
致命错误:在 'Stripe\Customer' 类中找不到 /home/user/public_html/charge.php 在第 8 行
按照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”与 message '未提供 API 密钥。 (提示:使用设置您的 API 密钥 "Stripe::setApiKey()".in /home/user/public_html/vendor/stripe/lib/ApiRequestor.php:127 堆栈 跟踪:#0 /home/user/public_html/vendor/stripe/lib/ApiRequestor.php(59): Stripe\ApiRequestor->_requestRaw('post', '/v1/customers', 数组, 阵列)#1 /home/user/public_html/vendor/stripe/lib/ApiResource.php(115): Stripe\ApiRequestor->request('post', '/v1/customers', Array, Array) #2 /home/user/public_html/vendor/stripe/lib/ApiResource.php(155): Stripe\ApiResource::_staticRequest('post', '/v1/customers', 数组, 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 中抛出
【问题讨论】:
-
如果你只做 \Stripe\Customer::create(... 吗?
-
我希望这些不是您的实时 Stripe 凭据...
-
@Machavity:当然不是懒惰!你饿了吧?
-
@MatthewArkin:感谢您的尝试!仍然返回相同的错误...
Fatal error: Class 'Stripe\Customer' not found -
\vendor\stripe\lib\Customer::create不是您访问命名空间类的方式 - 它应该是 Matthew 在上面发布的内容。
标签: php stripe-payments