protected function _updateAdyenAttributes($notification) { $this->_debugData['_updateAdyenAttributes'] = 'Updating the Adyen attributes of the order'; $additionalData = unserialize($notification->getAdditionalData()); $_paymentCode = $this->_paymentMethodCode(); if ($this->_eventCode == Notification::AUTHORISATION || $this->_eventCode == Notification::HANDLED_EXTERNALLY || $this->_eventCode == Notification::CAPTURE && $_paymentCode == "adyen_pos") { // if current notification is authorisation : false and the previous notification was authorisation : true do not update pspreference if (strcmp($this->_success, 'false') == 0 || strcmp($this->_success, '0') == 0 || strcmp($this->_success, '') == 0) { $previousAdyenEventCode = $this->_order->getData('adyen_notification_event_code'); if ($previousAdyenEventCode != "AUTHORISATION : TRUE") { $this->_updateOrderPaymentWithAdyenAttributes($additionalData); } } else { $this->_updateOrderPaymentWithAdyenAttributes($additionalData); } } }
/** * Ensure that order is created correctly via createOrder(). * * @param \Magento\Sales\Model\Order $order * @param string $shippingMethod */ protected function _verifyCreatedOrder($order, $shippingMethod) { /** Selectively check order data */ $orderData = $order->getData(); $this->assertNotEmpty($orderData['increment_id'], 'Order increment ID is empty.'); $this->assertEquals($this->_model->getQuote()->getId(), $orderData['quote_id'], 'Quote ID is invalid.'); $this->assertEquals($this->_model->getQuote()->getCustomer()->getEmail(), $orderData['customer_email'], 'Customer email is invalid.'); $this->assertEquals($this->_model->getQuote()->getCustomer()->getFirstname(), $orderData['customer_firstname'], 'Customer first name is invalid.'); $this->assertEquals($shippingMethod, $orderData['shipping_method'], 'Shipping method is invalid.'); }
/** * Retrieve order item value by key * * @param \Magento\Sales\Model\Order $order * @param string $key * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function getOrderItemValue(\Magento\Sales\Model\Order $order, $key) { $escape = true; switch ($key) { case 'order_increment_id': $value = $order->getIncrementId(); break; case 'created_at': $value = $this->formatDate($order->getCreatedAt(), \IntlDateFormatter::SHORT, true); break; case 'shipping_address': $value = $order->getShippingAddress() ? $this->escapeHtml($order->getShippingAddress()->getName()) : __('N/A'); break; case 'order_total': $value = $order->formatPrice($order->getGrandTotal()); $escape = false; break; case 'status_label': $value = $order->getStatusLabel(); break; case 'view_url': $value = $this->getUrl('sales/order/view', ['order_id' => $order->getId()]); break; default: $value = $order->getData($key) ? $order->getData($key) : __('N/A'); break; } return $escape ? $this->escapeHtml($value) : $value; }
/** * @param \Magento\Sales\Model\Order $object * @return \Magento\Sales\Service\V1\Data\Order */ public function extractDto(\Magento\Sales\Model\Order $object) { $this->orderBuilder->populateWithArray($object->getData()); $this->orderBuilder->setItems($this->getItems($object)); $this->orderBuilder->setPayments($this->getPayments($object)); $this->orderBuilder->setBillingAddress($this->getBillingAddress($object)); $this->orderBuilder->setShippingAddress($this->getShippingAddress($object)); return $this->orderBuilder->create(); }
public function processNotification() { $this->_order = null; $this->_logger->info("START OF THE CRONJOB"); //fixme somehow the created_at is saved in my timzone $dateStart = new \DateTime(); // loop over notifications that are not processed and from 1 minute ago $dateStart = new \DateTime(); $dateStart->modify('-1 day'); // excecute notifications from 2 minute or earlier because order could not yet been created by mangento $dateEnd = new \DateTime(); $dateEnd->modify('-2 minute'); $dateRange = ['from' => $dateStart, 'to' => $dateEnd, 'datetime' => true]; $notifications = $this->_notificationFactory->create(); $notifications->addFieldToFilter('done', 0); $notifications->addFieldToFilter('created_at', $dateRange); foreach ($notifications as $notification) { // get order $incrementId = $notification->getMerchantReference(); $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId); if (!$this->_order->getId()) { throw new Exception(sprintf('Wrong order ID: "%1".', $incrementId)); } // declare all variables that are needed $this->_declareVariables($notification); // add notification to comment history status is current status $this->_addStatusHistoryComment(); // $previousAdyenEventCode = $this->order->getAdyenNotificationEventCode(); $previousAdyenEventCode = $this->_order->getData('adyen_notification_event_code'); // set pspReference on payment object $this->_order->getPayment()->setAdditionalInformation('pspReference', $this->_pspReference); // check if success is true of false if (strcmp($this->_success, 'false') == 0 || strcmp($this->_success, '0') == 0) { // 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 ($this->_order->getState() === \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT || $this->_order->getState() === \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW || $this->_eventCode == \Magento\Sales\Model\Order::ADYEN_EVENT_ORDER_CLOSED) { $this->_debugData['_updateOrder info'] = 'Going to cancel the order'; // if payment is API check, check if API result pspreference is the same as reference if ($this->_eventCode == Adyen_Payment_Model_Event::ADYEN_EVENT_AUTHORISATION && $this->_getPaymentMethodType() == 'api') { if ($this->_pspReference == $this->_order->getPayment()->getAdditionalInformation('pspReference')) { // don't cancel the order if previous state is authorisation with success=true if ($previousAdyenEventCode != "AUTHORISATION : TRUE") { $this->_holdCancelOrder(false); } else { //$this->_order->setAdyenEventCode($previousAdyenEventCode); // do not update the adyenEventCode $this->_order->setData('adyen_notification_event_code', $previousAdyenEventCode); $this->_debugData['_updateOrder warning'] = 'order is not cancelled because previous notification was a authorisation that succeeded'; } } else { $this->_debugData['_updateOrder warning'] = 'order is not cancelled because pspReference does not match with the order'; } } else { // don't cancel the order if previous state is authorisation with success=true if ($previousAdyenEventCode != "AUTHORISATION : TRUE") { $this->_holdCancelOrder(false); } else { // $this->_order->setAdyenEventCode($previousAdyenEventCode); // do not update the adyenEventCode $this->_order->setData('adyen_notification_event_code', $previousAdyenEventCode); $this->_debugData['_updateOrder warning'] = 'order is not cancelled because previous notification was a authorisation that succeeded'; } } } else { $this->_debugData['_updateOrder info'] = 'Order is already processed so ignore this notification state is:' . $this->_order->getState(); } } else { // Notification is successful $this->_processNotification(); } $this->_order->save(); foreach ($this->_debugData as $debug) { $this->_logger->info($debug); } // set done to true $dateEnd = new \DateTime(); $notification->setDone(true); $notification->setUpdatedAt($dateEnd); $notification->save(); } $this->_logger->info("END OF THE CRONJOB"); }