I created this code in symfony:
#[Route(‘/buy/{subjectId}’, name: ‘buy_subject’, methods: [‘POST’])]
public function buySubject(Request $request, $subjectId, ManagerRegistry $managerRegistry, $stripeSK): Response
{
$entityManager = $managerRegistry->getManager();
$subject = $entityManager->getRepository(Subject::class)->find($subjectId);
error_log('Subject ID: ' . $subjectId);
if (!$subject) {
throw $this->createNotFoundException('Subject not found');
}
dump($subject);
Stripe::setApiKey($stripeSK);
error_log('Stripe API Key: ' . $stripeSK);
$totalAmount = $subject->getSubjectPrice() ;
error_log('Total Amount: ' . $totalAmount);
$checkoutSession = Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => $subject->getSubjectName(),
],
'unit_amount' => $totalAmount,
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => $this->generateUrl('subject_success'),
'cancel_url' => $this->generateUrl('subject_cancel'),
]);
return $this->redirect($checkoutSession->url, 303);
}
Only to get this error: [Application] Apr 30 23:52:43 |CRITICA| REQUES Uncaught PHP Exception StripeExceptionInvalidRequestException: “Not a valid URL” at C:UsersuserDownloadsTW2.0-Starter-Project-mainvendorstripestripe-phplibExceptionApiErrorException.php line 38
I expected the click on the Buy button to take me to the stripe checkout page
New contributor