Commit 3e0f6bc5 authored by GiorgosK's avatar GiorgosK

Better workflow for processCallback

parent 30533a51
...@@ -6,7 +6,7 @@ use Drupal\Core\Controller\ControllerBase; ...@@ -6,7 +6,7 @@ use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Drupal\commerce_order\Entity\Order; //use Drupal\commerce_order\Entity\Order;
use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface;
/** /**
* Endpoints for the routes defined. * Endpoints for the routes defined.
...@@ -60,17 +60,27 @@ class CallbackController extends ControllerBase { ...@@ -60,17 +60,27 @@ class CallbackController extends ControllerBase {
if ($action == "cancel") { if ($action == "cancel") {
return "You have cancelled your payment"; return "You have cancelled your payment";
} }
$resultCode = $request->get('ResultCode');
if ($resultCode !== "0") {
$this->logResponse($request, "failure");
return "The payment could not be completed";
}
$hashkey = $request->get('HashKey'); $hashkey = $request->get('HashKey');
$order_id = $request->get('MerchantReference'); $order_id = $request->get('MerchantReference');
$order = Order::load($order_id); $order = $this->entityTypeManager->getStorage('commerce_order')->load($order_id);
$ticket_result = $order->getData("IssueNewTicketResult"); $ticket_result = $order->getData("IssueNewTicketResult");
$hash = $this->calculateHash($request, $order_id, $ticket_result); $hash = $this->calculateHash($request, $order_id, $ticket_result);
if ($hash !== $hashkey) { if ($hash !== $hashkey) {
$this->createPayment($order, $request, $ticket_result, "Unvalidated"); $this->createPayment($order, $request, $ticket_result, "Unvalidated");
$this->logResponse($request, "failure");
return "Sorry we were not able to validate your payment"; return "Sorry we were not able to validate your payment";
} }
$this->createPayment($order, $request, $ticket_result); $this->createPayment($order, $request, $ticket_result);
$this->logResponse($request, "success");
return $this->getDisplayMessage($request); return $this->getDisplayMessage($request);
} }
...@@ -114,7 +124,7 @@ class CallbackController extends ControllerBase { ...@@ -114,7 +124,7 @@ class CallbackController extends ControllerBase {
/** /**
* Create Payment. * Create Payment.
*/ */
public function createPayment(Order $order, $request, $ticket_result, $state = "completed") { public function createPayment($order, $request, $ticket_result, $state = "completed") {
  • Why did you remove the Order type? It would be better if you had it as OrderInterface but it was ok.

  • Because I am using dependency injection and getting the order from EntityTypeManagerInterface if you look at the rest of the code. I might be wrong I stand to be corrected. Perhaps OrderInterface would work also I did not try. It was having problem with Order though.

    Edited by GiorgosK
Please register or sign in to reply
$payment_storage = $this->entityTypeManager->getStorage('commerce_payment'); $payment_storage = $this->entityTypeManager->getStorage('commerce_payment');
$payment = $payment_storage->create([ $payment = $payment_storage->create([
'state' => $state, 'state' => $state,
......
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