I created a symfony project but when I click on the buy button I get this as an error: The Stripe Checkout Link
I set the right API Key and I created the form but everytime I got “Something went wrong
The page you were looking for could not be found. Please check the URL or contact the merchant.”
#[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() * 100;
error_log('Total Amount: ' . $totalAmount);
// Debugging URLs
error_log('Success URL: ' . $this->generateUrl('subject_success'));
error_log('Cancel URL: ' . $this->generateUrl('subject_cancel'));
$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', [], UrlGeneratorInterface::ABSOLUTE_URL),
'cancel_url' => $this->generateUrl('subject_cancel', [], UrlGeneratorInterface::ABSOLUTE_URL),
]);
return $this->redirect($checkoutSession->url, 303);
}
Soltani Ahmed Soltani Ahmed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.