Пример #1
0
 /**
  * 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);
     }
 }
Пример #3
0
 /**
  * Get active quote by id
  *
  * @param int $cartId
  * @param int[] $sharedStoreIds
  * @throws NoSuchEntityException
  * @return CartInterface
  */
 public function get($cartId, array $sharedStoreIds = [])
 {
     $quote = parent::get($cartId, $sharedStoreIds);
     if (!$quote->getIsActive()) {
         throw NoSuchEntityException::singleField('cartId', $cartId);
     }
     return $quote;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function get($cartId, array $sharedStoreIds = array())
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'get');
     if (!$pluginInfo) {
         return parent::get($cartId, $sharedStoreIds);
     } else {
         return $this->___callPlugins('get', func_get_args(), $pluginInfo);
     }
 }
 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($this->storeMock);
     $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;
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
 /**
  * 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.'));
     }
 }
Пример #9
0
 /**
  * Retrieve quote data
  *
  * @return array
  */
 private function getQuoteData()
 {
     $quoteData = [];
     if ($this->checkoutSession->getQuote()->getId()) {
         $quote = $this->quoteRepository->get($this->checkoutSession->getQuote()->getId());
         // the following condition is a legacy logic left here for compatibility
         if (!$quote->getCustomer()->getId()) {
             $this->quoteRepository->save($this->checkoutSession->getQuote()->setCheckoutMethod('guest'));
         } else {
             $this->quoteRepository->save($this->checkoutSession->getQuote()->setCheckoutMethod(null));
         }
         $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;
 }
Пример #10
0
 /**
  * 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
     }
 }
Пример #11
0
 /**
  * Retrieve quote model object
  *
  * @return \Magento\Quote\Model\Quote
  */
 public function getQuote()
 {
     if ($this->_quote === null) {
         $this->_quote = $this->quoteRepository->create();
         if ($this->getStoreId()) {
             if (!$this->getQuoteId()) {
                 $this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId())->setIsActive(false)->setStoreId($this->getStoreId());
                 $this->quoteRepository->save($this->_quote);
                 $this->setQuoteId($this->_quote->getId());
             } else {
                 $this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
                 $this->_quote->setStoreId($this->getStoreId());
             }
             if ($this->getCustomerId()) {
                 $customer = $this->customerRepository->getById($this->getCustomerId());
                 $this->_quote->assignCustomer($customer);
             }
         }
         $this->_quote->setIgnoreOldQty(true);
         $this->_quote->setIsSuperMode(true);
     }
     return $this->_quote;
 }
 /**
  * @return ConfigInterface
  */
 protected function getConfig()
 {
     $quote = $this->quoteRepository->get($this->sessionTransparent->getQuoteId());
     return $this->paymentManagement->get($quote->getId())->getMethodInstance()->getConfigInterface();
 }