diff --git a/Controller/PaymentController.php b/Controller/PaymentController.php index 0d3b18c..ba46fcb 100644 --- a/Controller/PaymentController.php +++ b/Controller/PaymentController.php @@ -52,10 +52,10 @@ public function newAction(Request $request, $order) return $this->render( 'AppVentusMangopayBundle::cardPayment.html.twig', - array( - 'form' => $form->createView(), + [ + 'form' => $form->createView(), 'order' => $order, - ) + ] ); } @@ -87,13 +87,13 @@ public function paymentFinalizeAction(Request $request, $orderId, $cardId) // Handle error if ((property_exists($updatedCardRegister, 'ResultCode') && $updatedCardRegister->ResultCode !== '000000') - || $updatedCardRegister->Status == 'ERROR') { + || $updatedCardRegister->Status == 'ERROR') { $errorMessage = $this->get('translator')->trans('mangopay.error.'.$updatedCardRegister->ResultCode); - return new JsonResponse(array( + return new JsonResponse([ 'success' => false, 'message' => $errorMessage, - )); + ]); } // Create a PayIn @@ -103,17 +103,17 @@ public function paymentFinalizeAction(Request $request, $orderId, $cardId) if ((property_exists($preAuth, 'Code') && $preAuth->Code !== 200) || $preAuth->Status == 'FAILED') { $errorMessage = $this->get('translator')->trans('mangopay.error.'.$preAuth->ResultCode); - return new JsonResponse(array( + return new JsonResponse([ 'success' => false, 'message' => $errorMessage, - )); + ]); } // Handle secure mode if (property_exists($preAuth, 'SecureModeNeeded') && $preAuth->SecureModeNeeded == 1) { - return new JsonResponse(array( - 'success' => true, + return new JsonResponse([ + 'success' => true, 'redirect' => $preAuth->SecureModeRedirectURL, - )); + ]); } // store payin transaction @@ -134,9 +134,9 @@ public function paymentFinalizeAction(Request $request, $orderId, $cardId) $this->get('translator')->trans('appventus_mangopay.alert.pre_authorisation.success') ); - return new JsonResponse(array( + return new JsonResponse([ 'success' => true, - )); + ]); } /** @@ -193,22 +193,24 @@ public function paymentFinalizeSecureAction(Request $request, $orderId) $this->get('translator')->trans('appventus_mangopay.alert.pre_authorisation.success') ); - return $this->redirect($this->get('appventus_mangopay.payment_helper')->generateSuccessUrl()); + return $this->redirect($this->get('appventus_mangopay.payment_helper')->generateSuccessUrl($orderId)); } /** * @param Request $request The request + * @param int $orderId * * This method shows the congratulations * - * @Route("/success", name="appventus_mangopaybundle_payment_success") + * @Route("/success/{orderId}", name="appventus_mangopaybundle_payment_success") * * @return Response */ - public function successAction(Request $request) + public function successAction(Request $request, $orderId) { return $this->render( - 'AppVentusMangopayBundle::success.html.twig' + 'AppVentusMangopayBundle::success.html.twig', + ['orderId' => $orderId] ); } } diff --git a/Helper/PaymentHelper.php b/Helper/PaymentHelper.php index b5d0d36..ad811f1 100644 --- a/Helper/PaymentHelper.php +++ b/Helper/PaymentHelper.php @@ -53,15 +53,15 @@ public function prepareCardRegistrationCallback(User $user, Order $order) $redirect = $this->router->generate( 'appventus_mangopaybundle_payment_finalize', - array( + [ 'orderId' => $order->getId(), - 'cardId' => $mangoCardRegistration->Id, - ) + 'cardId' => $mangoCardRegistration->Id, + ] ); - $successRedirect = $this->generateSuccessUrl(); + $successRedirect = $this->generateSuccessUrl($order->getId()); - return array( + return [ 'callback' => 'payAjaxOrRedirect("' .$redirect.'", "' .$redirect.'", "' @@ -69,7 +69,7 @@ public function prepareCardRegistrationCallback(User $user, Order $order) .$preregistrationData.'", "' .$accessKey.'", "' .$successRedirect.'")', - ); + ]; } /** @@ -110,9 +110,9 @@ public function createPreAuthorisation(CardRegistration $updatedCardRegister, Us $cardPreAuthorisation->SecureMode = 'DEFAULT'; $cardPreAuthorisation->SecureModeReturnURL = $this->router->generate( 'appventus_mangopaybundle_payment_finalize_secure', - array( + [ 'orderId' => $order->getId(), - ), + ], true ); @@ -125,6 +125,7 @@ public function createPreAuthorisation(CardRegistration $updatedCardRegister, Us return $preAuth; } + /** * execute a pre authorisation. * @@ -195,8 +196,8 @@ public function cancelPreAuthForOrder(Order $order, CardPreAuthorisation $preAut } } - public function generateSuccessUrl() + public function generateSuccessUrl($orderId) { - return $this->router->generate('appventus_mangopaybundle_payment_success'); + return $this->router->generate('appventus_mangopaybundle_payment_success', ['orderId' => $orderId]); } }