Beispiel #1
0
 /**
  * Process Configured Payment Action: Direct Sale, create invoice if state is Pending
  *
  * @return void
  */
 protected function _processDirectSale()
 {
     $order = $this->_getOrder();
     $status = $this->getRequest()->getParam('STATUS');
     try {
         if ($status == \Magento\Ogone\Model\Api::OGONE_AUTH_PROCESSING) {
             $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, \Magento\Ogone\Model\Api::WAITING_AUTHORIZATION, __('Authorization Waiting from Ogone'));
             $order->save();
         } elseif ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
             if ($status == \Magento\Ogone\Model\Api::OGONE_AUTHORIZED) {
                 if ($order->getStatus() != \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
                     $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, \Magento\Ogone\Model\Api::PROCESSING_OGONE_STATUS, __('Processed by Ogone'));
                 }
             } else {
                 $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, \Magento\Ogone\Model\Api::PROCESSED_OGONE_STATUS, __('Processed by Ogone'));
             }
             if (!$order->getInvoiceCollection()->getSize()) {
                 $invoice = $order->prepareInvoice();
                 $invoice->register();
                 $invoice->setState(\Magento\Sales\Model\Order\Invoice::STATE_PAID);
                 $invoice->getOrder()->setIsInProcess(true);
                 $this->_transactionFactory->create()->addObject($invoice)->addObject($invoice->getOrder())->save();
                 $order->sendNewOrderEmail();
             }
         } else {
             $order->save();
         }
         $this->_redirect('checkout/onepage/success');
         return;
     } catch (\Exception $e) {
         $this->messageManager->addError(__('Order can\'t save'));
         $this->_redirect('checkout/cart');
         return;
     }
 }
Beispiel #2
0
 /**
  * Save config section
  * Require set: section, website, store and groups
  *
  * @throws \Exception
  * @return $this
  */
 public function save()
 {
     $this->initScope();
     $sectionId = $this->getSection();
     $groups = $this->getGroups();
     if (empty($groups)) {
         return $this;
     }
     $oldConfig = $this->_getConfig(true);
     $deleteTransaction = $this->_transactionFactory->create();
     /* @var $deleteTransaction \Magento\Framework\DB\Transaction */
     $saveTransaction = $this->_transactionFactory->create();
     /* @var $saveTransaction \Magento\Framework\DB\Transaction */
     // Extends for old config data
     $extraOldGroups = array();
     foreach ($groups as $groupId => $groupData) {
         $this->_processGroup($groupId, $groupData, $groups, $sectionId, $extraOldGroups, $oldConfig, $saveTransaction, $deleteTransaction);
     }
     try {
         $deleteTransaction->delete();
         $saveTransaction->save();
         // re-init configuration
         $this->_appConfig->reinit();
         $this->_storeManager->reinitStores();
         // website and store codes can be used in event implementation, so set them as well
         $this->_eventManager->dispatch("admin_system_config_changed_section_{$this->getSection()}", array('website' => $this->getWebsite(), 'store' => $this->getStore()));
     } catch (\Exception $e) {
         // re-init configuration
         $this->_appConfig->reinit();
         $this->_storeManager->reinitStores();
         throw $e;
     }
     return $this;
 }
Beispiel #3
0
 /**
  * @param \Magento\Sales\Model\Order\Item $orderItem
  * @return void
  */
 protected function refundOrder(\Magento\Sales\Model\Order\Item $orderItem)
 {
     $creditmemoLoader = $this->creditmemoLoaderFactory->create();
     $creditmemoLoader->setOrderId($orderItem->getOrderId());
     $creditmemoLoader->setCreditmemo($this->getCreditmemoData($orderItem));
     $creditmemo = $creditmemoLoader->load();
     if ($creditmemo && $creditmemo->isValidGrandTotal()) {
         $creditmemo->setOfflineRequested(true);
         $creditmemo->register();
         $creditmemoTransaction = $this->transactionFactory->create()->addObject($creditmemo)->addObject($creditmemo->getOrder());
         $creditmemoTransaction->save();
     }
 }
 /**
  * Delete design configuration from storage
  *
  * @param DesignConfigInterface $designConfig
  * @return void
  */
 public function delete(DesignConfigInterface $designConfig)
 {
     $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
     /* @var $deleteTransaction \Magento\Framework\DB\Transaction */
     $deleteTransaction = $this->transactionFactory->create();
     foreach ($fieldsData as $fieldData) {
         /** @var ValueInterface|Value $backendModel */
         $backendModel = $this->backendModelFactory->create(['value' => $fieldData->getValue(), 'scope' => $designConfig->getScope(), 'scopeId' => $designConfig->getScopeId(), 'config' => $fieldData->getFieldConfig()]);
         if (!$backendModel->isObjectNew()) {
             $deleteTransaction->addObject($backendModel);
         }
     }
     $deleteTransaction->delete();
 }
 /**
  * @param \Magento\Sales\Model\Order\Item $orderItem
  * @return void
  */
 protected function shipOrder(\Magento\Sales\Model\Order\Item $orderItem)
 {
     $shipmentLoader = $this->shipmentLoaderFactory->create();
     $shipmentData = [$orderItem->getId() => $orderItem->getQtyToShip()];
     $shipmentLoader->setOrderId($orderItem->getOrderId());
     $shipmentLoader->setShipment($shipmentData);
     $shipment = $shipmentLoader->load();
     if ($shipment) {
         $shipment->register();
         $shipment->getOrder()->setIsInProcess(true);
         $shipmentTransaction = $this->transactionFactory->create()->addObject($shipment)->addObject($shipment->getOrder());
         $shipmentTransaction->save();
     }
 }
Beispiel #6
0
 /**
  * If it's configured to capture on shipment - do this
  * 
  * @param \Magento\Framework\Object $observer
  * @return $this
  */
 public function processBraintreePayment(\Magento\Framework\Object $observer)
 {
     $shipment = $observer->getEvent()->getShipment();
     $order = $shipment->getOrder();
     if ($order->getPayment()->getMethod() == PaymentMethod::METHOD_CODE && $order->canInvoice() && $this->shouldInvoice()) {
         $qtys = [];
         foreach ($shipment->getAllItems() as $shipmentItem) {
             $qtys[$shipmentItem->getOrderItem()->getId()] = $shipmentItem->getQty();
         }
         foreach ($order->getAllItems() as $orderItem) {
             if (!array_key_exists($orderItem->getId(), $qtys)) {
                 $qtys[$orderItem->getId()] = 0;
             }
         }
         $invoice = $order->prepareInvoice($qtys);
         $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE);
         $invoice->register();
         /** @var \Magento\Framework\DB\Transaction $transaction */
         $transaction = $this->transactionFactory->create();
         $transaction->addObject($invoice)->addObject($invoice->getOrder())->save();
     }
     return $this;
 }
Beispiel #7
0
 /**
  * Create shipment
  *
  * @throws bool
  */
 protected function _createShipment()
 {
     $this->_adyenLogger->addAdyenNotificationCronjob('Creating shipment for order');
     // create shipment for cash payment
     $payment = $this->_order->getPayment()->getMethodInstance();
     if ($this->_order->canShip()) {
         $itemQty = [];
         $shipment = $this->_order->prepareShipment($itemQty);
         if ($shipment) {
             $shipment->register();
             $shipment->getOrder()->setIsInProcess(true);
             $comment = __('Shipment created by Adyen');
             $shipment->addComment($comment);
             /** @var \Magento\Framework\DB\Transaction $transaction */
             $transaction = $this->_transactionFactory->create();
             $transaction->addObject($shipment)->addObject($shipment->getOrder())->save();
             $this->_adyenLogger->addAdyenNotificationCronjob('Order is shipped');
         }
     } else {
         $this->_adyenLogger->addAdyenNotificationCronjob('Order can\'t be shipped');
     }
 }
Beispiel #8
0
 /**
  *
  */
 protected function _createShipment()
 {
     $this->_debugData['_createShipment'] = 'Creating shipment for order';
     // create shipment for cash payment
     $payment = $this->_order->getPayment()->getMethodInstance();
     if ($this->_order->canShip()) {
         $itemQty = array();
         $shipment = $this->_order->prepareShipment($itemQty);
         if ($shipment) {
             $shipment->register();
             $shipment->getOrder()->setIsInProcess(true);
             $comment = __('Shipment created by Adyen');
             $shipment->addComment($comment);
             /** @var \Magento\Framework\DB\Transaction $transaction */
             $transaction = $this->_transactionFactory->create();
             $transaction->addObject($shipment)->addObject($shipment->getOrder())->save();
             $this->_debugData['_createShipment done'] = 'Order is shipped';
         }
     } else {
         $this->_debugData['_createShipment error'] = 'Order can\'t be shipped';
     }
 }
Beispiel #9
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'));
     }
 }
Beispiel #10
0
 /**
  * Submit the quote. Quote submit process will create the order based on quote data
  *
  * @return \Magento\Sales\Model\Order
  * @throws \Exception
  */
 public function submitOrderWithDataObject()
 {
     $this->_deleteNominalItems();
     $this->_validate();
     $quote = $this->_quote;
     $isVirtual = $quote->isVirtual();
     $transaction = $this->_transactionFactory->create();
     $customerData = null;
     if (!$quote->getCustomerIsGuest()) {
         $customerData = $quote->getCustomerData();
         $addresses = $quote->getCustomerAddressData();
         $customerDetails = $this->_customerDetailsBuilder->setCustomer($customerData)->setAddresses($addresses)->create();
         if ($customerData->getId()) {
             $this->_customerAccountService->updateCustomer($customerDetails);
         } else {
             //for new customers
             $customerData = $this->_customerAccountService->createCustomerWithPasswordHash($customerDetails, $quote->getPasswordHash());
             $addresses = $this->_customerAddressService->getAddresses($customerData->getId());
             //Update quote address information
             foreach ($addresses as $address) {
                 if ($address->isDefaultBilling()) {
                     $quote->getBillingAddress()->setCustomerAddressData($address);
                 } else {
                     if ($address->isDefaultShipping()) {
                         $quote->getShippingAddress()->setCustomerAddressData($address);
                     }
                 }
             }
             if ($quote->getShippingAddress() && $quote->getShippingAddress()->getSameAsBilling()) {
                 $quote->getShippingAddress()->setCustomerAddressData($quote->getBillingAddress()->getCustomerAddressData());
             }
         }
         $quote->setCustomerData($customerData)->setCustomerAddressData($addresses);
     }
     $transaction->addObject($quote);
     $quote->reserveOrderId();
     if ($isVirtual) {
         $order = $this->_convertor->addressToOrder($quote->getBillingAddress());
     } else {
         $order = $this->_convertor->addressToOrder($quote->getShippingAddress());
     }
     $order->setBillingAddress($this->_convertor->addressToOrderAddress($quote->getBillingAddress()));
     if ($quote->getBillingAddress()->getCustomerAddressData()) {
         $order->getBillingAddress()->setCustomerAddressData($quote->getBillingAddress()->getCustomerAddressData());
     }
     if (!$isVirtual) {
         $order->setShippingAddress($this->_convertor->addressToOrderAddress($quote->getShippingAddress()));
         if ($quote->getShippingAddress()->getCustomerAddressData()) {
             $order->getShippingAddress()->setCustomerAddressData($quote->getShippingAddress()->getCustomerAddressData());
         }
     }
     $order->setPayment($this->_convertor->paymentToOrderPayment($quote->getPayment()));
     foreach ($this->_orderData as $key => $value) {
         $order->setData($key, $value);
     }
     foreach ($quote->getAllItems() as $item) {
         $orderItem = $this->_convertor->itemToOrderItem($item);
         if ($item->getParentItem()) {
             $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
         }
         $order->addItem($orderItem);
     }
     if ($customerData) {
         $order->setCustomerId($customerData->getId());
     }
     $order->setQuote($quote);
     $transaction->addObject($order);
     $transaction->addCommitCallback(array($order, 'place'));
     $transaction->addCommitCallback(array($order, 'save'));
     /**
      * We can use configuration data for declare new order status
      */
     $this->_eventManager->dispatch('checkout_type_onepage_save_order', array('order' => $order, 'quote' => $quote));
     $this->_eventManager->dispatch('sales_model_service_quote_submit_before', array('order' => $order, 'quote' => $quote));
     try {
         $transaction->save();
         $this->_inactivateQuote();
         $this->_eventManager->dispatch('sales_model_service_quote_submit_success', array('order' => $order, 'quote' => $quote));
     } catch (\Exception $e) {
         //reset order ID's on exception, because order not saved
         $order->setId(null);
         /** @var $item \Magento\Sales\Model\Order\Item */
         foreach ($order->getItemsCollection() as $item) {
             $item->setOrderId(null);
             $item->setItemId(null);
         }
         $this->_eventManager->dispatch('sales_model_service_quote_submit_failure', array('order' => $order, 'quote' => $quote));
         throw $e;
     }
     $this->_order = $order;
     return $order;
 }
Beispiel #11
0
 protected function _createInvoice($order, $message)
 {
     if (!$order->hasInvoices()) {
         $invoice = $order->prepareInvoice();
         $invoice->register();
         $invoice->pay();
         $this->_transactionFactory->create()->addObject($invoice)->addObject($invoice->getOrder())->save();
         $this->_invoiceSender->send($invoice, true, $message);
     }
 }