示例#1
0
 /**
  * @throws Exception
  */
 protected function _prepareInvoice()
 {
     $this->_adyenLogger->addAdyenNotificationCronjob('Prepare invoice for order');
     //Set order state to new because with order state payment_review it is not possible to create an invoice
     if (strcmp($this->_order->getState(), \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW) == 0) {
         $this->_order->setState(\Magento\Sales\Model\Order::STATE_NEW);
     }
     $paymentObj = $this->_order->getPayment();
     // set pspReference as transactionId
     $paymentObj->setCcTransId($this->_pspReference);
     $paymentObj->setLastTransId($this->_pspReference);
     // set transaction
     $paymentObj->setTransactionId($this->_pspReference);
     //capture mode
     if (!$this->_isAutoCapture()) {
         $this->_order->addStatusHistoryComment(__('Capture Mode set to Manual'));
         $this->_adyenLogger->addAdyenNotificationCronjob('Capture mode is set to Manual');
         // show message if order is in manual review
         if ($this->_fraudManualReview) {
             // check if different status is selected
             $fraudManualReviewStatus = $this->_getFraudManualReviewStatus();
             if ($fraudManualReviewStatus != "") {
                 $status = $fraudManualReviewStatus;
                 $comment = "Adyen Payment is in Manual Review check the Adyen platform";
                 $this->_order->addStatusHistoryComment(__($comment), $status);
             }
         }
         $createPendingInvoice = (bool) $this->_getConfigData('create_pending_invoice', 'adyen_abstract', $this->_order->getStoreId());
         if (!$createPendingInvoice) {
             $this->_adyenLogger->addAdyenNotificationCronjob('Setting pending invoice is off so don\'t create an invoice wait for the capture notification');
             return;
         }
     }
     // validate if amount is total amount
     $orderCurrencyCode = $this->_order->getOrderCurrencyCode();
     $amount = $this->_adyenHelper->originalAmount($this->_value, $orderCurrencyCode);
     // add to order payment
     $date = new \DateTime();
     $this->_adyenOrderPaymentFactory->create()->setPspreference($this->_pspReference)->setMerchantReference($this->_merchantReference)->setPaymentId($paymentObj->getId())->setPaymentMethod($this->_paymentMethod)->setAmount($amount)->setTotalRefunded(0)->setCreatedAt($date)->setUpdatedAt($date)->save();
     if ($this->_isTotalAmount($paymentObj->getEntityId(), $orderCurrencyCode)) {
         $this->_createInvoice();
     } else {
         $this->_adyenLogger->addAdyenNotificationCronjob('This is a partial AUTHORISATION and the full amount is not reached');
     }
 }