gpt4 book ai didi

php - Stripe::无法向 Laravel 中没有事件卡的客户收费

转载 作者:行者123 更新时间:2023-12-04 17:51:30 26 4
gpt4 key购买 nike

我试图在我的 Laravel 应用程序中实现 strip 我已经通过 Cartlyst docx 并提到了它的设置,但是当我请求测试付款时,我收到此错误 Cannot charge a customer that has no active card我已经研究过谷歌,但到目前为止没有任何效果。

这是代码

public function payment(Request $request)
{
$validator = Validator::make(
array(
'tokenId' => $request->tokenId,
),
array(
'tokenId' => 'required',
)
);
if ($validator->fails()) {
$errors = $validator->errors();
if ($errors->first('tokenId')) {
$message = $errors->first('tokenId');
} else {
$message = __('apiMessages.parametersRequired');
}
$this->setMeta("422", $message);
return response()->json($this->setResponse());
}
try{

$stripe = Stripe::make(env('STRIPE_SECRET'), Constant::STRIPE_VERSION);
$tokenId= $request->tokenId;
$customer = $stripe->customers()->create([
'email' => 'patrick@gmail.com',
]);
/*$customer = $stripe->customers()->find($tokenId);*/
$stripeCustomerId= $customer['id'];
$charge = $stripe->charges()->create([
'customer' => $stripeCustomerId,
'currency' => 'USD',
'amount' => Constant::AMOUNT,
]);
$chargeId=$charge['id'];
$payment= new Payment();
$payment->userId=1;
$payment->amount= Constant::AMOUNT;
$payment->chargeId= $chargeId;
$payment->paymentStatus= 1;
$payment->save();
$this->setMeta("200", __('apiMessages.paymentSuccess'));
return response()->json($this->setResponse());
}
catch (StripeException $stripeException)
{
$this->setMeta("403", $stripeException->getMessage());
return response()->json($this->setResponse());
}
}

请赐教我错在哪里?

最佳答案

是的,感谢 jycr753让我知道我的错误。我没有立即创建任何卡片,这就是为什么会出现此错误

$stripeCustomerId= $customer['id'];
$card = $stripe->cards()->create($stripeCustomerId, $request->tokenId); // add this to add a card.
$charge = $stripe->charges()->create([
'customer' => $stripeCustomerId,
'currency' => 'USD',
'amount' => Constant::AMOUNT,
]);

关于php - Stripe::无法向 Laravel 中没有事件卡的客户收费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44362315/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com