public function execute(Observer $observer) { if (!$this->_api->enabled()) { return; } try { /** @var $order Order */ $order = $observer->getEvent()->getOrder(); // Check if a payment is available for this order yet if ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) { return; } // Check if case already exists for this order if ($this->_helper->doesCaseExist($order)) { return; } $orderData = $this->_helper->processOrderData($order); // Add order to database $case = $this->_helper->createNewCase($order); // Post case to signifyd service $result = $this->_helper->postCaseToSignifyd($orderData, $order); if ($order->canHold()) { $order->hold()->getResource()->save($order); } if ($result) { $case->setCode($result); $case->setMagentoStatus(CaseRetry::IN_REVIEW_STATUS)->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time())); $case->getResource()->save($case); } } catch (\Exception $ex) { $this->_logger->error($ex->getMessage()); } }
public function execute() { if (!$this->_api->enabled()) { $this->getResponse()->appendBody("This plugin is not currently enabled"); $this->Result400(); return; } $rawRequest = $this->getRawPost(); $request = $this->getRequest(); $hash = $request->getHeader('X-SIGNIFYD-SEC-HMAC-SHA256'); $topic = $request->getHeader('X-SIGNIFYD-TOPIC'); if ($hash == null) { $this->getResponse()->appendBody("You have successfully reached the webhook endpoint"); $this->Result200(); return; } if ($this->_api->validWebhookRequest($rawRequest, $hash, $topic)) { // For the webhook test, all of the request data will be invalid if ($topic === 'cases/test') { $this->Result200(); return; } $request = json_decode($rawRequest); $caseData = $this->initRequest($request); $caseObj = $this->_objectManager->create('Signifyd\\Connect\\Model\\Casedata'); $caseObj->updateCase($caseData); $this->Result200(); return; } else { $this->Result403(); return; } }