Commit 868352ad authored by GiorgosK's avatar GiorgosK

Add logResponse function in CallbackController

parent dc0c472f
...@@ -74,6 +74,43 @@ class CallbackController extends ControllerBase { ...@@ -74,6 +74,43 @@ class CallbackController extends ControllerBase {
return $this->getDisplayMessage($request); return $this->getDisplayMessage($request);
} }
/**
* Log response data to database log and order object.
*/
public function logResponse($request, $status = "success") {
$order_id = $request->get('MerchantReference');
$data = [
"SupportReferenceID" => $request->get('SupportReferenceID'),
"MerchantReference" => $order_id,
"ResponseCode" => $request->get('ResponseCode'),
"ResponseDescription" => $request->get('ResponseDescription'),
];
if($status === "success"){
$data2 = [
"StatusFlag" => $request->get('StatusFlag'),
"ApprovalCode" => $request->get('ApprovalCode'),
"PackageNo" => $request->get('PackageNo'),
"AuthStatus" => $request->get('AuthStatus'),
];
$data = array_merge($data,$data2);
}
// log for immediate action
if($status === "success"){
$this->logger->info("Payment " . $status . ": " . '<pre><code>' . print_r($data, TRUE) . '</code></pre>');
}else if($status === "failure"){
$this->logger->alert("Payment " . $status . ": " . '<pre><code>' . print_r($data, TRUE) . '</code></pre>');
}
// log in the order data field for future reference
$order = $this->entityTypeManager->getStorage('commerce_order')->load($order_id);
$IssueNewTicketResult = $order->getData("IssueNewTicketResult");
$IssueNewTicketResult = array_merge($IssueNewTicketResult, $data);
$order->setData("IssueNewTicketResult", $IssueNewTicketResult);
$order->save();
}
/** /**
* Create Payment. * Create Payment.
*/ */
......
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