checkout-magento2-plugin
checkout-magento2-plugin copied to clipboard
Last module don't handle Log error
With the last module (5.5)
You upgrade the function getPayload :
From this :
public function getPayload()
{
$this->logger->additional($this->getRequest()->getContent(), 'webhook');
return json_decode($this->getRequest()->getContent());
}
To this :
/**
* Get the request payload
*
* @return mixed
*/
public function getPayload()
{
$this->logger->additional($this->getRequest()->getContent(), 'webhook');
return $this->json->unserialize($this->getRequest()->getContent());
}
As you know json_decode return method object and json->unserialize from magento return array object, you translate many part of your module, but you forget :
public function logError($response, OrderInterface $order): void
{
// Assign the payment instance
$payment = $order->getPayment();
// Prepare the failed transaction info
$suffix = __(
' for an amount of %1. Action ID: %2. Event ID: %3. Payment ID: %4. Error: %5 %6',
$this->prepareAmount($response->data->amount, $order),
!empty($response->data->action_id) ? $response->data->action_id : __('Not specified.'),
!empty($response->id) ? $response->id : __('Not specified.'),
!empty($response->data->id) ? $response->data->id : __('Not specified.'),
!empty($response->data->response_code) ? $response->data->response_code : __('Not specified.'),
!empty($response->data->response_summary) ? $response->data->response_summary : __('Not specified.')
);
// Add the order comment
$previousComment = $this->orderHandler->getStatusHistoryByEntity('3ds Fail', $order);
if ($previousComment && $response->type === 'payment_declined') {
$previousComment->setEntityName('order')->setComment(
__(self::TRANSACTION_ERROR_LABEL[$response->type]) . $suffix
);
$this->orderStatusHistoryRepository->save($previousComment);
} else {
// Add the order comment
$order->addStatusHistoryComment(
__(self::TRANSACTION_ERROR_LABEL[$response->type]) . $suffix
);
}
// Save the data
$this->orderPaymentRepository->save($payment);
$this->orderRepository->save($order);
}
Every callback with an error crash.