我想实现Stripe付款表单,但是我收到致命错误类'Stripe \ Charge。该课程在那里(参见我的文件夹树),我试过了:
$charge = \Stripe\Charge::create(array(
$charge = \Charge::create(array(
但两者都没有用。 我的PHP代码:
require_once('Stripe/lib/Stripe.php');
\Stripe\Stripe::setApiKey("my_key"); //Replace with your Secret Key
$charge = \Stripe\Charge::create(array(
"amount" => 1500,
"currency" => "usd",
"card" => $_POST['stripeToken'],
"description" => "Charge for Facebook Login code."
));
答案 0 :(得分:2)
您正在使用Stripe PHP库的旧版(1.x)。在该版本中,所有类都被命名为\Stripe\Class
。
在版本2.0.0中,语法已更改为使用命名空间,现在所有类都命名为readline()
。
如果可能,我建议您升级到最新版本(3.13.0)。你可以在这里找到它:https://github.com/stripe/stripe-php/releases。 Stripe的文档和API参考中的所有示例都使用较新的语法。
答案 1 :(得分:2)
您可以使用
use \Stripe\Stripe;
\Stripe\Stripe::setApiKey("my_key");
public function chargeCard($token)
{
try
{
$charge=\Stripe\Charge::create(array(
"amount" => 200,//Amount in cent.(100 cent equal to $1.00).it is smallest currency unit
"currency" => "usd",//united state dollar .but we can use different countries currency code
"source" => $token, // obtained createtoken function
"description" => "Charge for testing"//desc of payment purpose,Automatic receipt emails will include the description of the charge(s)
)
);
}
catch(\Stripe\Card $e){
echo $e->getMessage();
}
}
答案 2 :(得分:0)
这对我有用:
$customer = Stripe_Customer::create(array(
'email' => 'customer-email',
'source' => 'stripe_token'
));
$charge = Stripe_Charge::create(array(
"amount" => $order_amount, // amount in cents
"customer"=>$customer->id,
"currency" => "usd",
"description" => "payinguser@example.com"
));