From 0ff6764b329278c57626322d856773d305648372 Mon Sep 17 00:00:00 2001 From: Giorgos Kontopoulos Date: Thu, 11 Apr 2019 17:32:48 +0300 Subject: [PATCH] Modify controller to display regular page with message from bank --- commerce_winbank.routing.yml | 2 +- src/Controller/CallbackController.php | 42 +++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/commerce_winbank.routing.yml b/commerce_winbank.routing.yml index 74bb979..5b4dece 100644 --- a/commerce_winbank.routing.yml +++ b/commerce_winbank.routing.yml @@ -3,6 +3,6 @@ commerce_winbank.payment_callback: path: '/commerce_winbank/callback' defaults: _controller: '\Drupal\commerce_winbank\Controller\CallbackController::callback' - _title: 'Winbank Payment Controller' + _title: 'Winbank Payment' requirements: _permission: 'access content' diff --git a/src/Controller/CallbackController.php b/src/Controller/CallbackController.php index 3de44b0..a825576 100644 --- a/src/Controller/CallbackController.php +++ b/src/Controller/CallbackController.php @@ -41,8 +41,11 @@ class CallbackController extends ControllerBase { * @return Response */ public function callback(Request $request) { - $this->processCallback($request); - return new Response(); + $message = $this->processCallback($request); + return [ + '#type' => 'markup', + '#markup' => $message, + ]; } @@ -58,9 +61,10 @@ class CallbackController extends ControllerBase { $hash = $this->calculateHash($request, $order_id, $ticket_result); if( $hash !== $hashkey) { $this->createPayment($order, $request, $ticket_result, "Unvalidated"); - return; + return "Sorry we were not able to validate your payment"; } $this->createPayment($order, $request, $ticket_result); + return $this->getDisplayMessage($request); } /** @@ -114,4 +118,36 @@ class CallbackController extends ControllerBase { ); return hash_hmac('sha256', $concatValues, $ticket_result['TranTicket'], false); } + + /** + * Get message . + * + * @param $request + * + * @param $IssueNewTicketResult + * + * @return string + */ + public function getDisplayMessage($request) { + $message = $request->get('ResultDescription'); + if (empty($message)) { + $messages = [ + '00' => 'Completed successfully', + '08' => 'Completed successfully', + '10' => 'Completed successfully', + '16' => 'Completed successfully', + '11' => 'Transaction already processed', + '05' => 'Declined', + '12' => 'Declined', + '51' => 'Declined', + '34' => 'Lost card / Stolen card / Pick up', + '43' => 'Lost card / Stolen card / Pick up', + '54' => 'Expired card', + '62' => 'Restricted Card', + '92' => 'Declined', + ]; + $message = $messages[$request->get('ResponseCode')]; + } + return $message; + } } -- GitLab