The goal is to register an idle user on my website and redirect it to a payment platform by sending the user data entered in the form via the POST method.
I have a form in POST that I use to create an inactive user if this form is valid. I would then like to redirect my user to an external URL while sending the data from this form in POST to this URL. This URL accepts only specific variable names (these variables are in the associative array of my RedirectResponse) and only in POST.
The user will make his payment on the external link and if the payment is successful I will activate the user later. I identify with the payment platform by sending her 'ID' and she has authorized my domain name.
I tried to use RedirectResponse with status 307 but I think it is not possible to send it POST data.
* @Route("/{id<\d+>?1}/{slug}", methods={"GET", "POST"}, name="show")
* @Security("is_granted('IS_AUTHENTICATED_ANONYMOUSLY')")
*/
public function show(Offre $offre, $slug, Request $request): Response
{
if ($offre->getSlug() !== $slug) {
return $this->redirectToRoute('site_devenir_vip_show', [
'id' => $offre->getId(),
'slug' => $offre->getSlug(),
], Response::HTTP_MOVED_PERMANENTLY);
}
$utilisateur = new User();
$form = $this->createForm(UserType::class, $utilisateur);
$form->handleRequest($request);
if ($form->isSubmitted() === true) {
if ($form->isValid() === true) {
// TODO: create the inactive User here
// TODO: redirect the user on the payment platform
return new RedirectResponse('https://mywebsite.com', 307, [
'NOM' => $utilisateur->getNom(),
'PRENOM' => $utilisateur->getPrenom(),
'TEL' => $utilisateur->getTel(),
'EMAIL' => $utilisateur->getEmail(),
'PAYS' => $utilisateur->getPays(),
'ID' => 'XXXX',
'ABONNEMENT' => 'XXXX',
]);
}
$this->addFlash('error', 'Le formulaire comporte des erreurs.');
}
return $this->render('site/pages/devenir_vip/show.html.twig', [
'offre' => $offre,
'form' => $form->createView(),
]);
}
I am currently redirected to the external link that is in the RedirectResponse but it does not get the parameters. Do you have an idea ?