We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 0514b25f authored by Raul Quinto Sakai's avatar Raul Quinto Sakai Committed by cyattilakiss

trating notification issue (#499)

parent b58e4057
...@@ -332,111 +332,118 @@ class Cron ...@@ -332,111 +332,118 @@ class Cron
// loop over the notifications // loop over the notifications
$count = 0; $count = 0;
foreach ($notifications as $notification) { foreach ($notifications as $notification) {
$this->_adyenLogger->addAdyenNotificationCronjob( try {
sprintf("Processing notification %s", $notification->getEntityId())
);
// ignore duplicate notification
if ($this->_isDuplicate($notification)) {
$this->_adyenLogger->addAdyenNotificationCronjob( $this->_adyenLogger->addAdyenNotificationCronjob(
"This is a duplicate notification and will be ignored" sprintf("Processing notification %s", $notification->getEntityId())
); );
$this->_updateNotification($notification, false, true);
++$count;
continue;
}
// log the executed notification // ignore duplicate notification
$this->_adyenLogger->addAdyenNotificationCronjob(print_r($notification->debug(), 1)); if ($this->_isDuplicate($notification)) {
$this->_adyenLogger->addAdyenNotificationCronjob(
"This is a duplicate notification and will be ignored"
);
$this->_updateNotification($notification, false, true);
++$count;
continue;
}
// log the executed notification
$this->_adyenLogger->addAdyenNotificationCronjob(print_r($notification->debug(), 1));
// get order // get order
$incrementId = $notification->getMerchantReference(); $incrementId = $notification->getMerchantReference();
$searchCriteria = $this->searchCriteriaBuilder $searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', $incrementId, 'eq') ->addFilter('increment_id', $incrementId, 'eq')
->create(); ->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems(); $orderList = $this->orderRepository->getList($searchCriteria)->getItems();
/** @var \Magento\Sales\Model\Order $order */ /** @var \Magento\Sales\Model\Order $order */
$order = reset($orderList); $order = reset($orderList);
$this->_order = $order; $this->_order = $order;
if (!$this->_order) { if (!$this->_order) {
// order does not exists remove from queue // order does not exists remove from queue
$notification->delete(); $notification->delete();
continue; continue;
} }
// declare all variables that are needed // declare all variables that are needed
$this->_declareVariables($notification); $this->_declareVariables($notification);
// add notification to comment history status is current status // add notification to comment history status is current status
$this->_addStatusHistoryComment(); $this->_addStatusHistoryComment();
$previousAdyenEventCode = $this->_order->getData('adyen_notification_event_code'); $previousAdyenEventCode = $this->_order->getData('adyen_notification_event_code');
// update order details // update order details
$this->_updateAdyenAttributes($notification); $this->_updateAdyenAttributes($notification);
// check if success is true of false // check if success is true of false
if (strcmp($this->_success, 'false') == 0 || strcmp($this->_success, '0') == 0) { if (strcmp($this->_success, 'false') == 0 || strcmp($this->_success, '0') == 0) {
/* /*
* Only cancel the order when it is in state pending, payment review or * Only cancel the order when it is in state pending, payment review or
* if the ORDER_CLOSED is failed (means split payment has not be successful) * if the ORDER_CLOSED is failed (means split payment has not be successful)
*/ */
if ($this->_order->getState() === \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT || if ($this->_order->getState() === \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT ||
$this->_order->getState() === \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW || $this->_order->getState() === \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW ||
$this->_eventCode == Notification::ORDER_CLOSED $this->_eventCode == Notification::ORDER_CLOSED
) { ) {
$this->_adyenLogger->addAdyenNotificationCronjob('Going to cancel the order'); $this->_adyenLogger->addAdyenNotificationCronjob('Going to cancel the order');
// if payment is API check, check if API result pspreference is the same as reference // if payment is API check, check if API result pspreference is the same as reference
if ($this->_eventCode == NOTIFICATION::AUTHORISATION && $this->_getPaymentMethodType() == 'api') { if ($this->_eventCode == NOTIFICATION::AUTHORISATION && $this->_getPaymentMethodType() == 'api') {
// don't cancel the order becasue order was successfull through api // don't cancel the order becasue order was successfull through api
$this->_adyenLogger->addAdyenNotificationCronjob(
'order is not cancelled because api result was succesfull'
);
} else {
/*
* don't cancel the order if previous state is authorisation with success=true
* Split payments can fail if the second payment has failed the first payment is
* refund/cancelled as well so if it is a split payment that failed cancel the order as well
*/
if ($previousAdyenEventCode != "AUTHORISATION : TRUE" ||
$this->_eventCode == Notification::ORDER_CLOSED
) {
$this->_holdCancelOrder(false);
} else {
$this->_order->setData('adyen_notification_event_code', $previousAdyenEventCode);
$this->_adyenLogger->addAdyenNotificationCronjob( $this->_adyenLogger->addAdyenNotificationCronjob(
'order is not cancelled because previous notification 'order is not cancelled because api result was succesfull'
was an authorisation that succeeded'
); );
} else {
/*
* don't cancel the order if previous state is authorisation with success=true
* Split payments can fail if the second payment has failed the first payment is
* refund/cancelled as well so if it is a split payment that failed cancel the order as well
*/
if ($previousAdyenEventCode != "AUTHORISATION : TRUE" ||
$this->_eventCode == Notification::ORDER_CLOSED
) {
$this->_holdCancelOrder(false);
} else {
$this->_order->setData('adyen_notification_event_code', $previousAdyenEventCode);
$this->_adyenLogger->addAdyenNotificationCronjob(
'order is not cancelled because previous notification
was an authorisation that succeeded'
);
}
} }
} else {
$this->_adyenLogger->addAdyenNotificationCronjob(
'Order is already processed so ignore this notification state is:' . $this->_order->getState()
);
} }
} else { } else {
$this->_adyenLogger->addAdyenNotificationCronjob( // Notification is successful
'Order is already processed so ignore this notification state is:' . $this->_order->getState() $this->_processNotification();
);
} }
} else {
// Notification is successful
$this->_processNotification();
}
try { try {
// set done to true // set done to true
$this->_order->save(); $this->_order->save();
} catch (\Exception $e) {
$this->_adyenLogger->addAdyenNotificationCronjob($e->getMessage());
}
$this->_updateNotification($notification, false, true);
$this->_adyenLogger->addAdyenNotificationCronjob(
sprintf("Notification %s is processed", $notification->getEntityId())
);
++$count;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->_adyenLogger->addAdyenNotificationCronjob($e->getMessage()); $this->_updateNotification($notification, false, false);
$this->_adyenLogger->addAdyenNotificationCronjob(
sprintf("Notification %s had an error: %s \n %s", $notification->getEntityId(), $e->getMessage(), $e->getTraceAsString())
);
} }
$this->_updateNotification($notification, false, true);
$this->_adyenLogger->addAdyenNotificationCronjob(
sprintf("Notification %s is processed", $notification->getEntityId())
);
++$count;
} }
if ($count > 0) { if ($count > 0) {
......
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