Ejemplo n.º 1
0
 /**
  * @throws Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _createInvoice()
 {
     $this->_adyenLogger->addAdyenNotificationCronjob('Creating invoice for order');
     if ($this->_order->canInvoice()) {
         /* We do not use this inside a transaction because order->save()
          * is always done on the end of the notification
          * and it could result in a deadlock see https://github.com/Adyen/magento/issues/334
          */
         try {
             $invoice = $this->_order->prepareInvoice();
             $invoice->getOrder()->setIsInProcess(true);
             // set transaction id so you can do a online refund from credit memo
             $invoice->setTransactionId($this->_pspReference);
             $autoCapture = $this->_isAutoCapture();
             $createPendingInvoice = (bool) $this->_getConfigData('create_pending_invoice', 'adyen_abstract', $this->_order->getStoreId());
             if (!$autoCapture && $createPendingInvoice) {
                 // if amount is zero create a offline invoice
                 $value = (int) $this->_value;
                 if ($value == 0) {
                     $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_OFFLINE);
                 } else {
                     $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::NOT_CAPTURE);
                 }
                 $invoice->register();
             } else {
                 $invoice->register()->pay();
             }
             $invoice->save();
             $this->_adyenLogger->addAdyenNotificationCronjob('Created invoice');
         } catch (Exception $e) {
             $this->_adyenLogger->addAdyenNotificationCronjob('Error saving invoice. The error message is: ' . $e->getMessage());
             throw new Exception(sprintf('Error saving invoice. The error message is:', $e->getMessage()));
         }
         $this->_setPaymentAuthorized();
         $invoiceAutoMail = (bool) $this->_getConfigData('send_invoice_update_mail', 'adyen_abstract', $this->_order->getStoreId());
         if ($invoiceAutoMail) {
             $invoice->sendEmail();
         }
     } else {
         $this->_adyenLogger->addAdyenNotificationCronjob('It is not possible to create invoice for this order');
     }
 }
Ejemplo n.º 2
0
 protected function _processInvoice()
 {
     if ($this->_order->canInvoice()) {
         $invoice = $this->_order->prepareInvoice();
         switch ($this->_paymentInst->getConfigPaymentAction()) {
             case \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE:
                 $invoice->register();
                 $this->_order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, 'authorized');
                 break;
             case \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE_CAPTURE:
                 $this->_paymentInst->setAssistCaptureResponse(true);
                 $invoice->register()->capture();
                 break;
         }
         /** @var \Magento\Framework\DB\Transaction $transaction */
         $transaction = $this->_transactionFactory->create();
         $transaction->addObject($invoice)->addObject($invoice->getOrder())->save();
         $this->_invoiceSender->send($invoice);
     } elseif ($this->_order->isCanceled()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Order canceled'));
     } else {
         throw new \Magento\Framework\Exception\LocalizedException(__('Order paid'));
     }
 }