everyone I'm trying to implement stripe in my laravel application I have gone through Cartlyst docx and setup it was mentioned but there when I am requesting for testing payment I'm getting this error Cannot charge a customer that has no active card I have looked into google but nothing worked for me till now.
here is the code
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());
}
}
Please enlighten me where I am wrong?