每个人我都试图在我的laravel应用程序中实现条带我已经通过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());
}
}
请赐教我错在哪里?
答案 0 :(得分:1)
是的,感谢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,
]);