/**
  * {@inheritDoc}
  */
 public function getPaymentInformation($cartId)
 {
     /** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */
     $paymentDetails = $this->paymentDetailsFactory->create();
     $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
     $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId));
     return $paymentDetails;
 }
 /**
  * {@inheritDoc}
  */
 public function collectTotals($cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, $shippingCarrierCode = null, $shippingMethodCode = null, \Magento\Quote\Api\Data\TotalsAdditionalDataInterface $additionalData = null)
 {
     if ($shippingCarrierCode && $shippingMethodCode) {
         $this->shippingMethodManagement->set($cartId, $shippingCarrierCode, $shippingMethodCode);
     }
     $this->paymentMethodManagement->set($cartId, $paymentMethod);
     if ($additionalData !== null) {
         $this->dataProcessor->process($additionalData, $cartId);
     }
     return $this->cartTotalsRepository->get($cartId);
 }
 public function testSavePaymentInQuote()
 {
     $quoteId = 1;
     $response = new DataObject();
     $payment = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
     $payment->expects($this->once())->method('setAdditionalInformation')->with('pnref');
     $this->errorHandlerMock->expects($this->once())->method('handle')->with($payment, $response);
     $quote = $this->getMock('Magento\\Quote\\Api\\Data\\CartInterface', [], [], '', false);
     $quote->expects($this->exactly(2))->method('getId')->willReturn($quoteId);
     $this->sessionTransparent->expects($this->once())->method('getQuoteId')->willReturn($quoteId);
     $this->quoteRepository->expects($this->once())->method('get')->willReturn($quote);
     $this->paymentMethodManagementInterface->expects($this->once())->method('get')->willReturn($payment);
     $this->paymentMethodManagementInterface->expects($this->once())->method('set');
     $this->model->savePaymentInQuote($response);
 }
 /**
  * {@inheritDoc}
  */
 public function saveAddressInformation($cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
 {
     $address = $addressInformation->getShippingAddress();
     $billingAddress = $addressInformation->getBillingAddress();
     $carrierCode = $addressInformation->getShippingCarrierCode();
     $methodCode = $addressInformation->getShippingMethodCode();
     if (!$address->getCountryId()) {
         throw new StateException(__('Shipping address is not set'));
     }
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     $quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode);
     $this->validateQuote($quote);
     $quote->setIsMultiShipping(false);
     if ($billingAddress) {
         $quote->setBillingAddress($billingAddress);
     }
     try {
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save shipping information. Please check input data.'));
     }
     $shippingAddress = $quote->getShippingAddress();
     if (!$shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod())) {
         throw new NoSuchEntityException(__('Carrier with such method not found: %1, %2', $carrierCode, $methodCode));
     }
     /** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */
     $paymentDetails = $this->paymentDetailsFactory->create();
     $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
     $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId));
     return $paymentDetails;
 }
Exemplo n.º 5
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);
 }
 /**
  * {@inheritDoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function saveAddressInformation($cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation)
 {
     $address = $addressInformation->getShippingAddress();
     $carrierCode = $addressInformation->getShippingCarrierCode();
     $methodCode = $addressInformation->getShippingMethodCode();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException(__('Cart contains virtual product(s) only. Shipping address is not applicable.'));
     }
     if (0 == $quote->getItemsCount()) {
         throw new InputException(__('Shipping method is not applicable for empty cart'));
     }
     $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0;
     $sameAsBilling = $address->getSameAsBilling() ? 1 : 0;
     $customerAddressId = $address->getCustomerAddressId();
     $this->addressValidator->validate($address);
     $quote->setShippingAddress($address);
     $address = $quote->getShippingAddress();
     if ($customerAddressId) {
         $addressData = $this->addressRepository->getById($customerAddressId);
         $address = $quote->getShippingAddress()->importCustomerAddressData($addressData);
     }
     $address->setSameAsBilling($sameAsBilling);
     $address->setSaveInAddressBook($saveInAddressBook);
     $address->setCollectShippingRates(true);
     if (!$address->getCountryId()) {
         throw new StateException(__('Shipping address is not set'));
     }
     $address->setShippingMethod($carrierCode . '_' . $methodCode);
     try {
         $address->save();
         $address->collectTotals();
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save address. Please, check input data.'));
     }
     if (!$address->getShippingRateByCode($address->getShippingMethod())) {
         throw new NoSuchEntityException(__('Carrier with such method not found: %1, %2', $carrierCode, $methodCode));
     }
     if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
         throw new InputException($this->scopeConfig->getValue('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $quote->getStoreId()));
     }
     try {
         $address->save();
         $quote->collectTotals();
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         throw new InputException(__('Unable to save shipping information. Please, check input data.'));
     }
     /** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */
     $paymentDetails = $this->paymentDetailsFactory->create();
     $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
     $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId));
     return $paymentDetails;
 }
Exemplo n.º 7
0
 /**
  * @{inheritdoc}
  */
 public function saveAddresses($cartId, \Magento\Quote\Api\Data\AddressInterface $billingAddress, \Magento\Quote\Api\Data\AddressInterface $shippingAddress = null, \Magento\Quote\Api\Data\AddressAdditionalDataInterface $additionalData = null, $checkoutMethod = null)
 {
     $this->billingAddressManagement->assign($cartId, $billingAddress);
     /** @var \Magento\Quote\Api\Data\AddressDetailsInterface  $addressDetails */
     $addressDetails = $this->addressDetailsFactory->create();
     if ($shippingAddress) {
         $this->shippingAddressManagement->assign($cartId, $shippingAddress);
         $addressDetails->setFormattedShippingAddress($this->shippingAddressManagement->get($cartId)->format('html'));
         $addressDetails->setShippingMethods($this->shippingMethodManagement->getList($cartId));
     }
     $addressDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
     if ($additionalData !== null) {
         $this->dataProcessor->process($additionalData);
     }
     if ($checkoutMethod != null) {
         $this->quoteRepository->save($this->quoteRepository->getActive($cartId)->setCheckoutMethod($checkoutMethod));
     }
     $addressDetails->setFormattedBillingAddress($this->billingAddressManagement->get($cartId)->format('html'));
     $addressDetails->setTotals($this->cartTotalsRepository->get($cartId));
     return $addressDetails;
 }
 /**
  * {@inheritDoc}
  */
 public function savePaymentInformation($cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress)
 {
     $this->billingAddressManagement->assign($cartId, $billingAddress);
     $this->paymentMethodManagement->set($cartId, $paymentMethod);
     return true;
 }
 /**
  * @return ConfigInterface
  */
 protected function getConfig()
 {
     $quote = $this->quoteRepository->get($this->sessionTransparent->getQuoteId());
     return $this->paymentManagement->get($quote->getId())->getMethodInstance()->getConfigInterface();
 }
 /**
  * {@inheritdoc}
  */
 public function getList($cartId)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->paymentMethodManagement->getList($quoteIdMask->getQuoteId());
 }
Exemplo n.º 11
0
 /**
  * Returns array of payment methods
  * @return array
  */
 private function getPaymentMethods()
 {
     $paymentMethods = [];
     $quote = $this->checkoutSession->getQuote();
     if ($quote->getIsVirtual()) {
         foreach ($this->paymentMethodManagement->getList($quote->getId()) as $paymentMethod) {
             $paymentMethods[] = ['code' => $paymentMethod->getCode(), 'title' => $paymentMethod->getTitle()];
         }
     }
     return $paymentMethods;
 }