【发布时间】:2014-06-01 20:50:56
【问题描述】:
解决方案:未安装 CURL-PHP5 确保在 PHP 中启用错误
我遵循的指南:https://stripe.com/docs/checkout/guides/php
Stripe PHP 库的路径:/var/www/stripe-php/lib/Stripe.php 或 /stripe-php/lib/Stripe.php
错误消息:致命错误:在第 9 行的 /var/www/charge.php 中找不到类“Stripe_Customer”
index.php:
<?php require_once('config.php'); ?>
<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="2000" data-billing-address data-description="Test"></script>
</form>
config.php:(key 只是 stripe 提供的测试)
<?php
require_once('stripe-php/lib/Stripe.php');
$stripe = array(
"secret_key" => "sk_test_************************",
"publishable_key" => "pk_test_************************"
);
Stripe::setApiKey($stripe['secret_key']);
?>
charge.php:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once(dirname(__FILE__) . '/config.php');
$token = $_POST['stripeToken'];
$customer = Stripe_Customer::create(array(
'email' => 'customer@example.com',
'card' => $token
));
$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => 2000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $20.00!</h1>';
?>
【问题讨论】:
-
在配置中你有
require_once('stripe-php/lib/Stripe/Stripe.php');,但你说路径是/stripe-php/lib/Stripe.php。这对我来说似乎不一致。 -
您能否在
config.php中执行echo 'test';以确保它成功包含在charge.php中?另外,为什么dirname(__FILE__)而不是__DIR__? -
我只是隐藏了你的测试密钥。不过,有些人仍然可以看到修订版,所以我强烈建议您在 Stripe 上更改它们。即使它们只是测试密钥,您也不希望有人通过发布费用来扭曲您的所有测试。
-
最后一个问题,你到
config.php的绝对路径是什么?是/var/www/config.php吗?
标签: php stripe-payments