条纹付款设置问题

时间:2014-01-04 15:06:16

标签: php stripe-payments

我是一个明确的PHP菜鸟,所以请耐心等待我。我正在尝试为我的筹款网站设置一个简单的捐款支付选项。我有一个paypal选项,但也想添加一个条带选项。

我正在使用简单的Checkout流程收集卡片信息并设置条带令牌。我已经设置了一个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都是直接从条带自己的文档中提取的,但它似乎并不是直接开箱即用的。我尝试解决的是尝试'include Stripe.php',使用外部stripe.php页面,如果您使用javascript / jquery处理付款而不是条带的结帐选项,则会使用该页面。

非常感谢任何帮助 - 请对您的意见保持温和!

4 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,但后来我installed Stripe using Composer。然后在我的PHP文件中我require_once autoload.php文件,这似乎拉入Stripe库

&#13;
&#13;
<?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
};

?>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

require_once('/home2/username/vendor/autoload.php');

而不是autoload.php使用init.php

根据条带文件的位置,您可能需要编辑init.php

每行的路径语句

autoload.php的使用适用于使用Composer安装Stripe的时间。 如果您希望通过手动安装使用Stripe,请使用init.php,其中Stripe开发者提供了上述答案中包含的所有功能。

答案 2 :(得分:0)

我猜您没有包含条带文档中给出的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&gt; = 5.2环境

图书馆下载:https://code.stripe.com/stripe-php-latest.zip

答案 3 :(得分:0)

对于那些仍然收到错误消息的人

  

第8行的/home/munkeychunk/public_html/pay.php中找不到“Stripe”类

我和你在一起。我通过对/ lib /中的所有必需的Stripe文件执行require_once来解决这个问题。订单很重要,这对我有用

require_once ('./stripe-php-2.1.1/lib/Stripe.php') ;
require_once ('./stripe-php-2.1.1/lib/Util/Set.php') ;
require_once ('./stripe-php-2.1.1/lib/Util/RequestOptions.php') ;
require_once ('./stripe-php-2.1.1/lib/Util/Util.php') ;
require_once ('./stripe-php-2.1.1/lib/Error/Base.php') ;
require_once ('./stripe-php-2.1.1/lib/Error/InvalidRequest.php') ;
require_once ('./stripe-php-2.1.1/lib/Object.php') ;
require_once ('./stripe-php-2.1.1/lib/ApiRequestor.php') ;
require_once ('./stripe-php-2.1.1/lib/ApiResource.php') ;
require_once ('./stripe-php-2.1.1/lib/SingletonApiResource.php') ;
require_once ('./stripe-php-2.1.1/lib/Charge.php') ;

$files = glob('./stripe-php-2.1.1/lib/*.php');
foreach ($files as $file) {
    require_once($file);   
}

$files = glob('./stripe-php-2.1.1/lib/Error/*.php');
foreach ($files as $file) {
    require_once($file);   
}

$files = glob('./stripe-php-2.1.1/lib/Util/*.php');
foreach ($files as $file) {
    require_once($file);   
}
相关问题