Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-mlc
kohinos
Commits
e5c29138
Commit
e5c29138
authored
Sep 09, 2020
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix paiement payzen adhesion
parent
84b2bd30
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
73 deletions
+32
-73
FluxController.php
src/Controller/FluxController.php
+32
-73
No files found.
src/Controller/FluxController.php
View file @
e5c29138
...
@@ -11,6 +11,7 @@ use Symfony\Component\Form\AbstractType;
...
@@ -11,6 +11,7 @@ use Symfony\Component\Form\AbstractType;
use
Symfony\Component\Form\Form
;
use
Symfony\Component\Form\Form
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\HttpFoundation\StreamedResponse
;
use
Symfony\Component\HttpFoundation\StreamedResponse
;
use
Symfony\Component\HttpFoundation\Session\SessionInterface
;
use
Symfony\Component\HttpFoundation\Session\SessionInterface
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Routing\Annotation\Route
;
...
@@ -291,7 +292,7 @@ class FluxController extends AbstractController
...
@@ -291,7 +292,7 @@ class FluxController extends AbstractController
/**
/**
* Fonction de traitement du paiement, à appeler :
* Fonction de traitement du paiement, à appeler :
* - automatiquement lorsqu'un événement se produit sur le site de Paiement
* - automatiquement lorsqu'un événement se produit sur le site de Paiement
(notification)
* - au retour sur le site par l'utilisateur
* - au retour sur le site par l'utilisateur
*
*
* @Route("/payment/done/", name="payment_done")
* @Route("/payment/done/", name="payment_done")
...
@@ -301,18 +302,26 @@ class FluxController extends AbstractController
...
@@ -301,18 +302,26 @@ class FluxController extends AbstractController
try
{
try
{
$token
=
$this
->
payum
->
getHttpRequestVerifier
()
->
verify
(
$request
);
$token
=
$this
->
payum
->
getHttpRequestVerifier
()
->
verify
(
$request
);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
// Token expiré : retour sur site après paiement
// Token expired
// Get last payment
try
{
$payment
=
$this
->
em
->
getRepository
(
Payment
::
class
)
->
getUserLastPayment
(
$this
->
getUser
()
->
getId
());
}
catch
(
\Exception
$e
)
{
return
$this
->
redirectToRoute
(
'index'
);
return
$this
->
redirectToRoute
(
'index'
);
}
}
if
(
!
is_null
(
$payment
))
{
$gateway
=
$this
->
payum
->
getGateway
(
$token
->
getGatewayName
());
// Execute Notify action
$gateway
->
execute
(
new
Notify
(
$token
));
// Execute 'done' action according to payment status
$gateway
->
execute
(
$status
=
new
GetHumanStatus
(
$token
));
// Get payment
$payment
=
$status
->
getFirstModel
();
// Check for actual payment status. If not null or new: payment has already been processed.
if
(
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_CAPTURED
||
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_AUTHORIZED
)
{
if
(
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_CAPTURED
||
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_AUTHORIZED
)
{
// Invalidate token
$this
->
payum
->
getHttpRequestVerifier
()
->
invalidate
(
$token
);
$type
=
$payment
->
getDescription
();
$type
=
$payment
->
getDescription
();
if
(
Payment
::
TYPE_ACHAT_MONNAIE_ADHERENT
==
$type
||
Payment
::
TYPE_ACHAT_MONNAIE_PRESTA
==
$type
)
{
if
(
Payment
::
TYPE_ACHAT_MONNAIE_ADHERENT
==
$type
||
Payment
::
TYPE_ACHAT_MONNAIE_PRESTA
==
$type
)
{
...
@@ -330,40 +339,34 @@ class FluxController extends AbstractController
...
@@ -330,40 +339,34 @@ class FluxController extends AbstractController
'success'
,
'success'
,
$this
->
translator
->
trans
(
'Votre adhésion a bien été prise en compte, bienvenue !'
)
$this
->
translator
->
trans
(
'Votre adhésion a bien été prise en compte, bienvenue !'
)
);
);
// Connect new user
return
$this
->
guardHandler
->
authenticateUserAndHandleSuccess
(
$this
->
em
->
getRepository
(
User
::
class
)
->
findOneBy
(
array
(
'id'
=>
$payment
->
getClientId
())),
$request
,
$this
->
authenticator
,
'main'
);
}
}
// Update payment status
return
$this
->
redirectToRoute
(
'index'
);
$payment
->
setStatus
(
$payment
->
getStatus
()
.
';done'
);
$this
->
em
->
persist
(
$payment
);
$this
->
em
->
flush
();
}
else
if
(
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_CANCELED
||
}
else
if
(
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_CANCELED
||
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_EXPIRED
||
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_EXPIRED
||
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_FAILED
)
{
$payment
->
getStatus
()
==
GetHumanStatus
::
STATUS_FAILED
)
{
// Invalidate token
$this
->
payum
->
getHttpRequestVerifier
()
->
invalidate
(
$token
);
$this
->
addFlash
(
$this
->
addFlash
(
'error'
,
'error'
,
$this
->
translator
->
trans
(
'La transaction a été annulée.'
)
$this
->
translator
->
trans
(
'La transaction a été annulée.'
)
);
);
$payment
->
setStatus
(
$payment
->
getStatus
()
.
';done'
);
$this
->
em
->
persist
(
$payment
);
$this
->
em
->
flush
();
}
}
return
$this
->
redirectToRoute
(
'index'
);
return
$this
->
redirectToRoute
(
'index'
);
}
}
$gateway
=
$this
->
payum
->
getGateway
(
$token
->
getGatewayName
());
// We got here, payment hasn't been processed, we're in the notification process. Update payment status and go on.
// Execute Notify action
$gateway
->
execute
(
new
Notify
(
$token
));
// Execute 'done' action according to payment status
$gateway
->
execute
(
$status
=
new
GetHumanStatus
(
$token
));
// Get payment & update status
$payment
=
$status
->
getFirstModel
();
$payment
->
setStatus
(
$status
->
getValue
());
$payment
->
setStatus
(
$status
->
getValue
());
$this
->
em
->
persist
(
$payment
);
$this
->
em
->
persist
(
$payment
);
$this
->
em
->
flush
();
$this
->
em
->
flush
();
...
@@ -507,53 +510,9 @@ class FluxController extends AbstractController
...
@@ -507,53 +510,9 @@ class FluxController extends AbstractController
MLCEvents
::
FLUX
,
MLCEvents
::
FLUX
,
new
FluxEvent
(
$flux
)
new
FluxEvent
(
$flux
)
);
);
// Add flash message here too in case Gataway doesn't notify
if
(
Payment
::
TYPE_ACHAT_MONNAIE_ADHERENT
==
$type
||
Payment
::
TYPE_ACHAT_MONNAIE_PRESTA
==
$type
)
{
$this
->
addFlash
(
'success'
,
$this
->
translator
->
trans
(
'Achat de monnaie locale bien effectué !'
)
);
}
else
if
(
Payment
::
TYPE_COTISATION_ADHERENT
==
$type
||
Payment
::
TYPE_COTISATION_PRESTA
==
$type
)
{
$this
->
addFlash
(
'success'
,
$this
->
translator
->
trans
(
'Cotisation bien reçue. Merci !'
)
);
}
else
if
(
Payment
::
TYPE_ADHESION
==
$type
)
{
$this
->
addFlash
(
'success'
,
$this
->
translator
->
trans
(
'Votre adhésion a bien été prise en compte, bienvenue !'
)
);
}
// Invalidate token
$this
->
payum
->
getHttpRequestVerifier
()
->
invalidate
(
$token
);
}
else
if
(
$status
->
getValue
()
==
GetHumanStatus
::
STATUS_CANCELED
||
$status
->
getValue
()
==
GetHumanStatus
::
STATUS_EXPIRED
||
$status
->
getValue
()
==
GetHumanStatus
::
STATUS_FAILED
)
{
$this
->
addFlash
(
'error'
,
$this
->
translator
->
trans
(
'La transaction a été annulée.'
)
);
$this
->
payum
->
getHttpRequestVerifier
()
->
invalidate
(
$token
);
}
if
(
Payment
::
TYPE_ADHESION
==
$type
)
{
// Auto login after adhesion
return
$this
->
guardHandler
->
authenticateUserAndHandleSuccess
(
$user
,
$request
,
$this
->
authenticator
,
'main'
);
}
else
{
return
$this
->
redirectToRoute
(
'index'
);
}
}
return
new
Response
(
'ok'
,
Response
::
HTTP_OK
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment