1

Here is what I want to do: integrate Stripe into my site which is hosted on OVH In the local version, everything works perfectly well (success, failure, etc.).

Online, as soon as I click on the button to go to the payment page, I get the following error:
Attempted to load class "Stripe" from namespace "Stripe". Did you forget a "use" statement for another namespace?

Here is my code:

<?php

namespace App\Controller;

use Stripe\Stripe;
use App\Entity\Devis;
use App\Service\GetSociety;
use Stripe\Checkout\Session;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class StripeController extends AbstractController
{
#[Route('/devis/{reference}/payment', name: 'stripe_create_session')]
    public function index($reference): Response
    {
        $YOUR_DOMAIN = 'https://'.$_SERVER['HTTP_HOST'];
        $devis = $this->entityManager->getRepository(Devis::class)->findOneBy( ['reference' => $reference] );
        if (!$devis || $devis->getUser() != $this->getUser()) {
            return $this->redirectToRoute('account-devis');
        }

        $products_for_stripe[] = [
            'price_data' =>[
                'currency' => 'eur',
                'unit_amount' => $devis->getPrice(),
                'product_data' => [
                    'name' => $devis->getReference(),
                    'images' => $YOUR_DOMAIN,
                ],
            ],
            'quantity' => 1,
        ];

        Stripe::setApiKey('sk_test...');
        $checkout_session = Session::create([
            'customer_email' => $this->getUser()->getEmail(),
            'payment_method_types' => ['card'],
            'line_items' => [
                [
                    'price_data' =>[
                        'currency' => 'eur',
                        'unit_amount' => $devis->getPrice(),
                        'product_data' => [
                            'name' => 'Devis n°'.$devis->getReference(),
                        ],
                    ],
                    'quantity' => 1,
                ]
            ],
            'mode' => 'payment',
            'success_url' => $YOUR_DOMAIN . '/devis/'.$reference.'/merci',
            'cancel_url' => $YOUR_DOMAIN . '/devis/'.$reference.'/erreur',
        ]);
        return $this->redirect($checkout_session->url);
    }
}

Thank you for your responses and your help

Fafnir
  • 33
  • 3

0 Answers0