Exemple #1
0
 public function execute()
 {
     $skipFraudDetection = false;
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $params = $this->getRequest()->getParams();
     if (!isset($params['order_id'])) {
         $this->_logger->critical('Exchange: order_id is not set in the request', $params);
         return $this->_result->setContents('FALSE| order_id is not set in the request');
     }
     try {
         $transaction = \Paynl\Transaction::get($params['order_id']);
     } catch (\Exception $e) {
         $this->_logger->critical($e, $params);
         return $this->_result->setContents('FALSE| Error fetching transaction. ' . $e->getMessage());
     }
     if ($transaction->isPending()) {
         return $this->_result->setContents("TRUE| Ignoring pending");
     }
     $orderId = $transaction->getDescription();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     if (empty($order)) {
         $this->_logger->critical('Cannot load order: ' . $orderId);
         return $this->_result->setContents('FALSE| Cannot load order');
     }
     if ($order->getTotalDue() <= 0) {
         $this->_logger->debug('Total due <= 0, so iam not touching the status of the order: ' . $orderId);
         return $this->_result->setContents('TRUE| Total due <= 0, so iam not touching the status of the order');
     }
     if ($transaction->isPaid()) {
         $payment = $order->getPayment();
         $payment->setTransactionId($transaction->getId());
         $payment->setCurrencyCode($transaction->getPaidCurrency());
         $payment->setIsTransactionClosed(0);
         $payment->registerCaptureNotification($transaction->getPaidCurrencyAmount(), $skipFraudDetection);
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice && !$order->getEmailSent()) {
             $this->_orderSender->send($order);
             $order->addStatusHistoryComment(__('New order email sent'))->setIsCustomerNotified(true)->save();
         }
         if ($invoice && !$invoice->getEmailSent()) {
             $this->_invoiceSender->send($invoice);
             $order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
         }
         return $this->_result->setContents("TRUE| PAID");
     } elseif ($transaction->isCanceled()) {
         $order->cancel()->save();
         return $this->_result->setContents("TRUE| CANCELED");
     }
 }
Exemple #2
0
 public function execute()
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $params = $this->getRequest()->getParams();
     if (!isset($params['orderId'])) {
         $this->messageManager->addNoticeMessage(__('Invalid return, no transactionId specified'));
         $this->_logger->critical('Invalid return, no transactionId specified', $params);
         $resultRedirect->setPath('checkout/cart');
         return $resultRedirect;
     }
     try {
         $transaction = \Paynl\Transaction::get($params['orderId']);
     } catch (\Exception $e) {
         $this->_logger->critical($e, $params);
         $this->messageManager->addExceptionMessage($e, __('There was an error checking the transaction status'));
         $resultRedirect->setPath('checkout/cart');
         return $resultRedirect;
     }
     if ($transaction->isPaid() || $transaction->isPending()) {
         $this->_getCheckoutSession()->start();
         $resultRedirect->setPath('checkout/onepage/success');
     } else {
         //canceled, re-activate quote
         try {
             $this->_getCheckoutSession()->restoreQuote();
             $this->messageManager->addNoticeMessage(__('Payment canceled'));
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->_logger->error($e);
             $this->messageManager->addExceptionMessage($e, $e->getMessage());
         } catch (\Exception $e) {
             $this->_logger->error($e);
             $this->messageManager->addExceptionMessage($e, __('Unable to cancel order'));
         }
         $resultRedirect->setPath('checkout/cart');
     }
     return $resultRedirect;
 }
Exemple #3
0
 private function _reload()
 {
     $result = \Paynl\Transaction::get($this->getId());
     $this->data = $result->getData();
 }