Ejemplo n.º 1
0
 /**
  * @param $response
  * @return bool
  */
 private function _validateResponse($response)
 {
     $result = false;
     if ($response != null && $response['result'] != "" && $this->_validateChecksum($response)) {
         $incrementId = $response['merchantReference'];
         $responseResult = $response['result'];
         if ($incrementId) {
             $order = $this->_getOrder($incrementId);
             if ($order->getId()) {
                 $comment = __('%1 <br /> Result: %2 <br /> paymentMethod: %3', 'Adyen App Result URL Notification:', $responseResult, 'POS');
                 if ($responseResult == 'APPROVED') {
                     $this->_adyenLogger->addAdyenResult('Result is approved');
                     $history = $this->_orderHistoryFactory->create()->setComment($comment)->setEntityName('order')->setOrder($order);
                     $history->save();
                     // needed  becuase then we need to save $order objects
                     $order->setAdyenResulturlEventCode("POS_APPROVED");
                     // save order
                     $order->save();
                     return true;
                 } else {
                     $this->_adyenLogger->addAdyenResult('Result is:' . $responseResult);
                     $history = $this->_orderHistoryFactory->create()->setComment($comment)->setEntityName('order')->setOrder($order);
                     $history->save();
                     // cancel the order
                     if ($order->canCancel()) {
                         $order->cancel()->save();
                         $this->_adyenLogger->addAdyenResult('Order is cancelled');
                     } else {
                         $this->_adyenLogger->addAdyenResult('Order can not be cancelled');
                     }
                 }
             } else {
                 $this->_adyenLogger->addAdyenResult('Order does not exists with increment_id: ' . $incrementId);
             }
         } else {
             $this->_adyenLogger->addAdyenResult('Empty merchantReference');
         }
     } else {
         $this->_adyenLogger->addAdyenResult('actionName or checksum failed or response is empty');
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param $order
  * @param $params
  */
 protected function _validateUpdateOrder($order, $response)
 {
     $result = false;
     $this->_adyenLogger->addAdyenResult('Updating the order');
     $authResult = $response['authResult'];
     $paymentMethod = isset($response['paymentMethod']) ? trim($response['paymentMethod']) : '';
     $pspReference = isset($response['pspReference']) ? trim($response['pspReference']) : '';
     $type = 'Adyen Result URL response:';
     $comment = __('%1 <br /> authResult: %2 <br /> pspReference: %3 <br /> paymentMethod: %4', $type, $authResult, $pspReference, $paymentMethod);
     $history = $this->_orderHistoryFactory->create()->setComment($comment)->setEntityName('order')->setOrder($order);
     $history->save();
     // needed  becuase then we need to save $order objects
     $order->setAdyenResulturlEventCode($authResult);
     switch ($authResult) {
         case \Adyen\Payment\Model\Notification::AUTHORISED:
         case \Adyen\Payment\Model\Notification::PENDING:
             // do nothing wait for the notification
             $result = true;
             $this->_adyenLogger->addAdyenResult('Do nothing wait for the notification');
             break;
         case \Adyen\Payment\Model\Notification::CANCELLED:
             $this->_adyenLogger->addAdyenResult('Cancel or Hold the order');
             $result = false;
             break;
         case \Adyen\Payment\Model\Notification::REFUSED:
             // if refused there will be a AUTHORIZATION : FALSE notification send only exception is idea
             $this->_adyenLogger->addAdyenResult('Cancel or Hold the order');
             $result = false;
             break;
         case \Adyen\Payment\Model\Notification::ERROR:
             //attempt to hold/cancel
             $this->_adyenLogger->addAdyenResult('Cancel or Hold the order');
             $result = false;
             break;
         default:
             $this->_adyenLogger->addAdyenResult('This event is not supported: ' . $authResult);
             $result = false;
             break;
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Add a comment to order
  * Different or default status may be specified
  *
  * @param string $comment
  * @param bool|string $status
  * @return OrderStatusHistoryInterface
  */
 public function addStatusHistoryComment($comment, $status = false)
 {
     if (false === $status) {
         $status = $this->getStatus();
     } elseif (true === $status) {
         $status = $this->getConfig()->getStateDefaultStatus($this->getState());
     } else {
         $this->setStatus($status);
     }
     $history = $this->_orderHistoryFactory->create()->setStatus($status)->setComment($comment)->setEntityName($this->entityType);
     $this->addStatusHistory($history);
     return $history;
 }