Commit 84b2bd30 by Damien Moulard

fix adhesion cb

parent b932702c
...@@ -218,7 +218,7 @@ class FluxController extends AbstractController ...@@ -218,7 +218,7 @@ class FluxController extends AbstractController
/** /**
* Crée une instance de Payment et redirige vers la page de paiement * Crée une instance de Payment et redirige vers la page de paiement
*/ */
public function preparePaymentAction(Form $form, $type) public function preparePaymentAction(Form $form, $type, $extra_data = null)
{ {
// Enregistre les données du Flux en json, pour l'enregistrer une fois le paiement validé // Enregistre les données du Flux en json, pour l'enregistrer une fois le paiement validé
$serializer = $this->container->get('serializer'); $serializer = $this->container->get('serializer');
...@@ -253,6 +253,11 @@ class FluxController extends AbstractController ...@@ -253,6 +253,11 @@ class FluxController extends AbstractController
$payment->setDescription($type); $payment->setDescription($type);
$payment->setFluxData($jsondata); $payment->setFluxData($jsondata);
// Data to persist when payment is valid (other than Flux data)
if ($extra_data != null) {
$payment->setExtraData($extra_data);
}
if ($type == Payment::TYPE_ADHESION) { if ($type == Payment::TYPE_ADHESION) {
$payment->setTotalAmount($form->get('cotisation')->get('montant')->getData()*100); // 1.23 EUR $payment->setTotalAmount($form->get('cotisation')->get('montant')->getData()*100); // 1.23 EUR
$payment->setClientId('Nouvel adhérent'); $payment->setClientId('Nouvel adhérent');
...@@ -299,7 +304,12 @@ class FluxController extends AbstractController ...@@ -299,7 +304,12 @@ class FluxController extends AbstractController
// Token expiré : retour sur site après paiement // Token expiré : retour sur site après paiement
// Get last payment // Get last payment
$payment = $this->em->getRepository(Payment::class)->getUserLastPayment($this->getUser()->getId()); try {
$payment = $this->em->getRepository(Payment::class)->getUserLastPayment($this->getUser()->getId());
} catch (\Exception $e) {
return $this->redirectToRoute('index');
}
if (!is_null($payment)) { if (!is_null($payment)) {
if ($payment->getStatus() == GetHumanStatus::STATUS_CAPTURED || $payment->getStatus() == GetHumanStatus::STATUS_AUTHORIZED) { if ($payment->getStatus() == GetHumanStatus::STATUS_CAPTURED || $payment->getStatus() == GetHumanStatus::STATUS_AUTHORIZED) {
...@@ -358,6 +368,8 @@ class FluxController extends AbstractController ...@@ -358,6 +368,8 @@ class FluxController extends AbstractController
$this->em->persist($payment); $this->em->persist($payment);
$this->em->flush(); $this->em->flush();
$type = '';
// If payment succesful, persist serialized 'Flux' stored in payment // If payment succesful, persist serialized 'Flux' stored in payment
if ($status->getValue() == GetHumanStatus::STATUS_CAPTURED || $status->getValue() == GetHumanStatus::STATUS_AUTHORIZED) { if ($status->getValue() == GetHumanStatus::STATUS_CAPTURED || $status->getValue() == GetHumanStatus::STATUS_AUTHORIZED) {
...@@ -434,7 +446,7 @@ class FluxController extends AbstractController ...@@ -434,7 +446,7 @@ class FluxController extends AbstractController
$flux->setRecu(true); $flux->setRecu(true);
} else if (Payment::TYPE_ADHESION == $type) { } else if (Payment::TYPE_ADHESION == $type) {
$new_adherent_data = json_decode($this->session->get('new_adherent')); $new_adherent_data = json_decode($payment->getExtraData());
$adherent = new Adherent(); $adherent = new Adherent();
$user = $this->userManager->createUser(); $user = $this->userManager->createUser();
...@@ -456,19 +468,16 @@ class FluxController extends AbstractController ...@@ -456,19 +468,16 @@ class FluxController extends AbstractController
$adherent->setGroupe($group); $adherent->setGroupe($group);
if ($adherent->getGeoloc() == null) { if ($adherent->getGeoloc() == null) {
$geoloc = new Geoloc(); $geoloc = new Geoloc();
$geoloc->setAdresse($new_adherent_data->geoloc->adresse); $geoloc->setAdresse($new_adherent_data->geoloc->adresse);
$geoloc->setCpostal($new_adherent_data->geoloc->cpostal); $geoloc->setCpostal($new_adherent_data->geoloc->cpostal);
$geoloc->setVille($new_adherent_data->geoloc->ville); $geoloc->setVille($new_adherent_data->geoloc->ville);
$adherent->setGeoloc($geoloc); $adherent->setGeoloc($geoloc);
} }
$this->em->persist($adherent); $this->em->persist($adherent);
$this->em->flush(); $this->em->flush();
// Remove new user data from session
$this->session->remove('new_adherent');
// Create first cotisation // Create first cotisation
$flux = $serializer->deserialize( $flux = $serializer->deserialize(
$payment->getFluxData(), $payment->getFluxData(),
...@@ -483,8 +492,9 @@ class FluxController extends AbstractController ...@@ -483,8 +492,9 @@ class FluxController extends AbstractController
$flux->setRole('Adherent'); $flux->setRole('Adherent');
$flux->setRecu(true); $flux->setRecu(true);
// Update payment with new user id // Update payment with new user id, remove user data
$payment->setClientId($user->getId()); $payment->setClientId($user->getId());
$payment->setExtraData('');
$this->em->persist($payment); $this->em->persist($payment);
} else { } else {
return new Response('', Response::HTTP_BAD_REQUEST); return new Response('', Response::HTTP_BAD_REQUEST);
......
...@@ -213,20 +213,19 @@ class IndexController extends AbstractController ...@@ -213,20 +213,19 @@ class IndexController extends AbstractController
if ($form->isValid()) { if ($form->isValid()) {
$adherentNew = $form->getData(); $adherentNew = $form->getData();
// Store form data in session to deal with it at payment callback // Serialize form data in json to store with payment object and persist when payment is valid
$serializer = $this->container->get('serializer'); $serializer = $this->container->get('serializer');
$data = $serializer->normalize($adherentNew, null, $data = $serializer->normalize($adherentNew, null,
[AbstractNormalizer::ATTRIBUTES => ['user' => ['username', 'email', 'firstname', 'lastname', 'plainPassword'], [AbstractNormalizer::ATTRIBUTES => ['user' => ['username', 'email', 'firstname', 'lastname', 'plainPassword'],
'groupe' => ['id'], 'groupe' => ['id'],
'geoloc' => ['adresse', 'cpostal', 'ville']]]); 'geoloc' => ['adresse', 'cpostal', 'ville']]]);
$jsondata = $serializer->serialize($data, 'json'); $jsondata = $serializer->serialize($data, 'json');
$this->session->set('new_adherent', $jsondata);
// Redirect to payment page // Redirect to payment page
return $this->forward('App\Controller\FluxController::preparePaymentAction', [ return $this->forward('App\Controller\FluxController::preparePaymentAction', [
'form' => $form, 'form' => $form,
'type' => Payment::TYPE_ADHESION 'type' => Payment::TYPE_ADHESION,
'extra_data' => $jsondata
]); ]);
} else { } else {
$this->addFlash( $this->addFlash(
......
...@@ -41,6 +41,14 @@ class Payment extends BasePayment ...@@ -41,6 +41,14 @@ class Payment extends BasePayment
*/ */
protected $flux_data; protected $flux_data;
/**
* @var string|null
* Extra data to persist if payment valid
*
* @ORM\Column(type="text", nullable=true)
*/
protected $extra_data;
/** /**
* @return string * @return string
*/ */
...@@ -76,4 +84,22 @@ class Payment extends BasePayment ...@@ -76,4 +84,22 @@ class Payment extends BasePayment
$this->flux_data = $flux_data; $this->flux_data = $flux_data;
return $this; return $this;
} }
/**
* @return string
*/
public function getExtraData(): ?string
{
return $this->extra_data;
}
/**
* @param string $extra_data
* @return Payment
*/
public function setExtraData(string $extra_data): self
{
$this->extra_data = $extra_data;
return $this;
}
} }
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200909121737 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE payment ADD extra_data LONGTEXT DEFAULT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE payment DROP extra_data');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment