/** * {@inheritdoc} */ public function placeOrder($cartId, $agreements = null, PaymentInterface $paymentMethod = null) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); $this->cartRepository->get($quoteIdMask->getQuoteId())->setCheckoutMethod(CartManagementInterface::METHOD_GUEST); return $this->quoteManagement->placeOrder($quoteIdMask->getQuoteId(), $agreements, $paymentMethod); }
/** * Saves payment information in quote * * @param Object $response * @return void */ public function savePaymentInQuote($response) { $quote = $this->quoteRepository->get($this->sessionTransparent->getQuoteId()); /** @var InfoInterface $payment */ $payment = $this->paymentManagement->get($quote->getId()); $payment->setAdditionalInformation('pnref', $response->getPnref()); $this->errorHandler->handle($payment, $response); $this->paymentManagement->set($quote->getId(), $payment); }
/** * Return shipping options items for shipping address from request * * @return void */ public function execute() { try { $quoteId = $this->getRequest()->getParam('quote_id'); $this->_quote = $this->quoteRepository->get($quoteId); $this->_initCheckout(); $response = $this->_checkout->getShippingOptionsCallbackResponse($this->getRequest()->getParams()); $this->getResponse()->setBody($response); } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); } }
/** * {@inheritDoc} */ public function calculate($cartId, \Magento\Checkout\Api\Data\TotalsInformationInterface $addressInformation) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->cartRepository->get($cartId); $this->validateQuote($quote); if ($quote->getIsVirtual()) { $quote->setBillingAddress($addressInformation->getAddress()); } else { $quote->setShippingAddress($addressInformation->getAddress()); $quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod($addressInformation->getShippingCarrierCode() . '_' . $addressInformation->getShippingMethodCode()); } $quote->collectTotals(); return $this->cartTotalRepository->get($cartId); }
protected function recordOrder($order) { $customOrderId = null; //https://github.com/magento/magento2/issues/4233 $quoteId = $order->getQuoteId(); $quote = $this->quoteRepository->get($quoteId); $shippingAddress = $quote->getShippingAddress(); $carrierType = $shippingAddress->getCarrierType(); // $order->setCarrierType($carrierType); $order->setDestinationType($shippingAddress->getDestinationType()); $order->setValidationStatus($shippingAddress->getValidationStatus()); $this->carrierGroupHelper->saveOrderDetail($order, $shippingAddress); $this->carrierGroupHelper->recordOrderItems($order); $this->packageHelper->saveOrderPackages($order, $shippingAddress); if (strstr($order->getShippingMethod(), 'shqshared_')) { $orderDetailArray = $this->carrierGroupHelper->loadOrderDetailByOrderId($order->getId()); //SHQ16- Review for splits foreach ($orderDetailArray as $orderDetail) { $original = $orderDetail->getCarrierType(); $carrierTypeArray = explode('_', $orderDetail->getCarrierType()); if (is_array($carrierTypeArray)) { $orderDetail->setCarrierType($carrierTypeArray[1]); //SHQ16-1026 $currentShipDescription = $order->getShippingDescription(); $shipDescriptionArray = explode('-', $currentShipDescription); $cgArray = $this->shipperDataHelper->decodeShippingDetails($orderDetail->getCarrierGroupDetail()); foreach ($cgArray as $key => $cgDetail) { if (isset($cgDetail['carrierType']) && $cgDetail['carrierType'] == $original) { $cgDetail['carrierType'] = $carrierTypeArray[1]; } if (is_array($shipDescriptionArray) && isset($cgDetail['carrierTitle'])) { $shipDescriptionArray[0] = $cgDetail['carrierTitle'] . ' '; $newShipDescription = implode('-', $shipDescriptionArray); $order->setShippingDescription($newShipDescription); } $cgArray[$key] = $cgDetail; } $encoded = $this->shipperDataHelper->encode($cgArray); $orderDetail->setCarrierGroupDetail($encoded); $orderDetail->save(); } $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Rates displayed as single carrier', 'Resetting carrier type on order to be ' . $carrierTypeArray[1]); } } if ($this->shipperDataHelper->useDefaultCarrierCodes()) { $order->setShippingMethod($this->getDefaultCarrierShipMethod($order, $shippingAddress)); } $order->save(); }
/** * @param $quoteId * * @return Quote */ public function reOrder($quoteId) { $quote = $this->_quoteRepository->get($quoteId); $quote->setIsActive(1)->setReservedOrderId(null); $this->_quoteRepository->save($quote); return $quote; }
/** * Retrieve quote model object * * @return \Magento\Quote\Model\Quote */ public function getQuote() { if ($this->_quote === null) { $this->_quote = $this->quoteFactory->create(); if ($this->getStoreId()) { if (!$this->getQuoteId()) { $this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId()); $this->_quote->setIsActive(false); $this->_quote->setStoreId($this->getStoreId()); $this->quoteRepository->save($this->_quote); $this->setQuoteId($this->_quote->getId()); $this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]); } else { $this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]); $this->_quote->setStoreId($this->getStoreId()); } if ($this->getCustomerId() && $this->getCustomerId() != $this->_quote->getCustomerId()) { $customer = $this->customerRepository->getById($this->getCustomerId()); $this->_quote->assignCustomer($customer); $this->quoteRepository->save($this->_quote); } } $this->_quote->setIgnoreOldQty(true); $this->_quote->setIsSuperMode(true); } return $this->_quote; }
public function testGetWithSharedStoreIds() { $cartId = 16; $sharedStoreIds = [1, 2]; $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getId')->willReturn(1); $this->quoteMock->expects($this->once())->method('setSharedStoreIds')->with($sharedStoreIds)->willReturnSelf(); $this->quoteMock->expects($this->once())->method('load')->with($cartId)->willReturn($this->storeMock); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); $this->assertEquals($this->quoteMock, $this->model->get($cartId, $sharedStoreIds)); $this->assertEquals($this->quoteMock, $this->model->get($cartId, $sharedStoreIds)); }
/** * Retrieve quote data * * @return array */ private function getQuoteData() { $quoteData = []; if ($this->checkoutSession->getQuote()->getId()) { $quote = $this->quoteRepository->get($this->checkoutSession->getQuote()->getId()); $quoteData = $quote->toArray(); $quoteData['is_virtual'] = $quote->getIsVirtual(); if (!$quote->getCustomer()->getId()) { /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create(); $quoteData['entity_id'] = $quoteIdMask->load($this->checkoutSession->getQuote()->getId(), 'quote_id')->getMaskedId(); } } return $quoteData; }
/** * Restore last active quote * * @return bool True if quote restored successfully, false otherwise */ public function restoreQuote() { /** @var \Magento\Sales\Model\Order $order */ $order = $this->getLastRealOrder(); if ($order->getId()) { try { $quote = $this->quoteRepository->get($order->getQuoteId()); $quote->setIsActive(1)->setReservedOrderId(null); $this->quoteRepository->save($quote); $this->replaceQuote($quote)->unsLastRealOrderId(); $this->_eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]); return true; } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { } } return false; }
/** * Operate with order using information from silent post * * @param \Magento\Sales\Model\Order $order * @return void * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _processOrder(\Magento\Sales\Model\Order $order) { $response = $this->getResponse(); $payment = $order->getPayment(); $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0); $canSendNewOrderEmail = true; if ($response->getResult() == self::RESPONSE_CODE_FRAUDSERVICE_FILTER || $response->getResult() == self::RESPONSE_CODE_DECLINED_BY_FILTER) { $canSendNewOrderEmail = false; $payment->setIsTransactionPending(true)->setIsFraudDetected(true); $fraudMessage = $response->getData('respmsg'); if ($response->getData('fps_prexmldata')) { $xml = new \SimpleXMLElement($response->getData('fps_prexmldata')); $fraudMessage = (string) $xml->rule->triggeredMessage; } $payment->setAdditionalInformation(Info::PAYPAL_FRAUD_FILTERS, $fraudMessage); } if ($response->getData('avsdata') && strstr(substr($response->getData('avsdata'), 0, 2), 'N')) { $payment->setAdditionalInformation(Info::PAYPAL_AVS_CODE, substr($response->getData('avsdata'), 0, 2)); } if ($response->getData('cvv2match') && $response->getData('cvv2match') != 'Y') { $payment->setAdditionalInformation(Info::PAYPAL_CVV_2_MATCH, $response->getData('cvv2match')); } switch ($response->getType()) { case self::TRXTYPE_AUTH_ONLY: $payment->registerAuthorizationNotification($payment->getBaseAmountAuthorized()); break; case self::TRXTYPE_SALE: $payment->registerCaptureNotification($payment->getBaseAmountAuthorized()); break; default: break; } $order->save(); try { if ($canSendNewOrderEmail) { $this->orderSender->send($order); } $quote = $this->quoteRepository->get($order->getQuoteId())->setIsActive(false); $this->quoteRepository->save($quote); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(__('We cannot send the new order email.')); } }
/** * Operate with order using information from Authorize.net. * Authorize order or authorize and capture it. * * @param \Magento\Sales\Model\Order $order * @return void * @throws \Magento\Framework\Exception\LocalizedException * @throws \Exception * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function processOrder(\Magento\Sales\Model\Order $order) { try { $this->checkResponseCode(); $this->checkTransId(); } catch (\Exception $e) { //decline the order (in case of wrong response code) but don't return money to customer. $message = $e->getMessage(); $this->declineOrder($order, $message, false); throw $e; } $response = $this->getResponse(); //create transaction. need for void if amount will not match. $payment = $order->getPayment(); $this->fillPaymentByResponse($payment); $payment->getMethodInstance()->setIsInitializeNeeded(false); $payment->getMethodInstance()->setResponseData($response->getData()); $this->processPaymentFraudStatus($payment); $payment->place(); $this->addStatusComment($payment); $order->save(); //match amounts. should be equals for authorization. //decline the order if amount does not match. if (!$this->matchAmount($payment->getBaseAmountAuthorized())) { $message = __('Something went wrong: the paid amount doesn\'t match the order amount.' . ' Please correct this and try again.'); $this->declineOrder($order, $message, true); throw new \Magento\Framework\Exception\LocalizedException($message); } try { if (!$response->hasOrderSendConfirmation() || $response->getOrderSendConfirmation()) { $this->orderSender->send($order); } $quote = $this->quoteRepository->get($order->getQuoteId())->setIsActive(false); $this->quoteRepository->save($quote); } catch (\Exception $e) { // do not cancel order if we couldn't send email } }
/** * {@inheritdoc} */ public function getList($cartId) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->get($cartId); return $this->methodList->getAvailableMethods($quote); }
/** * @return ConfigInterface */ protected function getConfig() { $quote = $this->quoteRepository->get($this->sessionTransparent->getQuoteId()); return $this->paymentManagement->get($quote->getId())->getMethodInstance()->getConfigInterface(); }
/** * {@inheritdoc} */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->quoteRepository->get($quoteIdMask->getQuoteId()); }