我是一个十足的PHP新手,所以请容忍我。我正在尝试为我的筹款网站设置一个简单的捐款支付选项。我有一个paypal选项,但正在寻找添加条纹选项以及。
我正在使用简单的结帐过程来收集卡信息并设置条形令牌。我已经设置了一个pay.php文件来处理服务器上的卡信息。
<!DOCTYPE html>
<html>
<body>
<?php
// secret key
***Stripe::setApiKey("sk_test_##########");***
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
//Create the charge on Stripe's servers
try {
$charge = Stripe_Charge::create(array(
"amount" => 500, // amount in cents, again
"currency" => "aud",
"card" => $token,
"description" => "payinguser@example.com")
);
} catch(Stripe_CardError $e) {
// card decline
}
?>
</body>
</html>显然,我使用了正确的密钥,我只是在这里阻止了它。表单看起来一切正常,但是当它发布到pay.php上时,它抛出了这个错误。
致命错误:在第8行的/home/munkeychunk/public_html/pay.php中找不到类'Stripe‘
如上所述,第8行是密钥组件/API密钥。正如我所说的,我是一个PHP新手,我不确定如何或什么来设置类的“条纹”!
大多数PHP都是直接从stripe自己的文档中升级过来的,但它似乎不能直接开箱即用。我想解决的办法是尝试使用一个外部stripe.php页面,如果你使用javascript/jquery而不是stripe的结账选项来处理支付,就会用到这个页面。
任何帮助都将不胜感激--请温文尔雅地评论!
发布于 2015-03-21 04:43:58
我也有同样的问题,但后来我installed Stripe using Composer了。然后,在我的PHP文件中,我对autoload.php文件执行require_once操作,这似乎就是在拉入条带库。
<?php
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account
require_once('/home2/username/vendor/autoload.php');
\Stripe\Stripe::setApiKey("sk_test_########");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
"amount" => 1000, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "payinguser@example.com")
);
} catch(\Stripe\Error\Card $e) {
// The card has been declined
};
?>
发布于 2015-05-15 22:31:26
require_once('/home2/username/vendor/autoload.php');使用init.php代替autoload.php
根据条带文件的位置,您可能需要编辑init.php每行上的path语句
autoload.php的使用适用于随Composer一起安装的条带。当你想通过手动安装来使用条纹时,使用init.php,在那里条纹开发者已经提供了上面答案中包含的所有功能。
发布于 2014-01-05 17:02:26
我猜想你还没有像Stripe文档中给出的那样包含Stripe库。所以它应该是这样的
<!DOCTYPE html>
<html>
<body>
<?php
//Include stripe library first before doing anything related to stripe here
require_once('./lib/Stripe.php');
// secret key
***Stripe::setApiKey("sk_test_##########");***
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
//Create the charge on Stripe's servers
try {
$charge = Stripe_Charge::create(array(
"amount" => 500, // amount in cents, again
"currency" => "aud",
"card" => $token,
"description" => "payinguser@example.com")
);
} catch(Stripe_CardError $e) {
// card decline
}
?>
</body>
</html>文档:https://stripe.com/docs/checkout/guides/php
注意:需要PHP >= 5.2环境
https://stackoverflow.com/questions/20922589
复制相似问题