/** * Copies paytype from payment additional data to session. * * @param \Magento\Checkout\Model\PaymentInformationManagement $subject * @param $cartId * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod */ public function beforeSavePaymentInformationAndPlaceOrder(\Magento\Checkout\Model\PaymentInformationManagement $subject, $cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod) { if ($paymentMethod->getMethod() === \Orba\Payupl\Model\Payupl::CODE) { $additionalData = $paymentMethod->getAdditionalData(); $this->session->setPaytype(isset($additionalData['paytype']) ? $additionalData['paytype'] : null); } }
/** * {@inheritdoc} */ public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->get($cartId); $method->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX]); $payment = $quote->getPayment(); $payment->importData($method->getData()); if ($quote->isVirtual()) { // check if billing address is set if ($quote->getBillingAddress()->getCountryId() === null) { throw new InvalidTransitionException(__('Billing address is not set')); } $quote->getBillingAddress()->setPaymentMethod($payment->getMethod()); } else { // check if shipping address is set if ($quote->getShippingAddress()->getCountryId() === null) { throw new InvalidTransitionException(__('Shipping address is not set')); } $quote->getShippingAddress()->setPaymentMethod($payment->getMethod()); } if (!$quote->isVirtual() && $quote->getShippingAddress()) { $quote->getShippingAddress()->setCollectShippingRates(true); } if (!$this->zeroTotalValidator->isApplicable($payment->getMethodInstance(), $quote)) { throw new InvalidTransitionException(__('The requested Payment Method is not available.')); } $quote->setTotalsCollectedFlag(false)->collectTotals()->save(); return $quote->getPayment()->getId(); }
/** * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod * @throws \Magento\Framework\Exception\CouldNotSaveException * @return void */ protected function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod) { $agreements = $paymentMethod->getExtensionAttributes() === null ? [] : $paymentMethod->getExtensionAttributes()->getAgreementIds(); if (!$this->agreementsValidator->isValid($agreements)) { throw new \Magento\Framework\Exception\CouldNotSaveException(__('Please agree to all the terms and conditions before placing the order.')); } }
/** * Sets payment to current quote * * @param PaymentInterface $payment * @return PaymentInterface */ public function setPayment(PaymentInterface $payment) { if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) { $payment->setId($old->getId()); } $this->addPayment($payment); return $payment; }
/** * {@inheritdoc} */ public function placeOrder($cartId, $agreements = null, PaymentInterface $paymentMethod = null) { $quote = $this->quoteRepository->getActive($cartId); if ($paymentMethod) { $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]); $quote->getPayment()->setQuote($quote); $data = $paymentMethod->getData(); if (isset($data['additional_data'])) { $data = array_merge($data, (array) $data['additional_data']); unset($data['additional_data']); } $quote->getPayment()->importData($data); } if ($quote->getCheckoutMethod() === self::METHOD_GUEST) { $quote->setCustomerId(null); $quote->setCustomerEmail($quote->getBillingAddress()->getEmail()); $quote->setCustomerIsGuest(true); $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID); } $order = $this->submit($quote); $this->checkoutSession->setLastQuoteId($quote->getId()); $this->checkoutSession->setLastSuccessQuoteId($quote->getId()); $this->checkoutSession->setLastOrderId($order->getId()); $this->checkoutSession->setLastRealOrderId($order->getIncrementId()); $this->checkoutSession->setLastOrderStatus($order->getStatus()); $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]); return $order->getId(); }
/** * @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject * @param int $cartId * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod * @param \Magento\Quote\Api\Data\AddressInterface $billingAddress * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeSavePaymentInformation(\Magento\Checkout\Api\PaymentInformationManagementInterface $subject, $cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress) { if ($this->isAgreementEnabled()) { $this->validateAgreements($paymentMethod->getExtensionAttributes()->getAgreementIds()); } }
/** * {@inheritdoc} */ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) { $quote = $this->quoteRepository->getActive($cartId); if ($paymentMethod) { $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]); $quote->getPayment()->setQuote($quote); $data = $paymentMethod->getData(); $quote->getPayment()->importData($data); } if ($quote->getCheckoutMethod() === self::METHOD_GUEST) { $quote->setCustomerId(null); $quote->setCustomerEmail($quote->getBillingAddress()->getEmail()); $quote->setCustomerIsGuest(true); $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID); } $this->eventManager->dispatch('checkout_submit_before', ['quote' => $quote]); $order = $this->submit($quote); if (null == $order) { throw new LocalizedException(__('Unable to place order. Please try again later.')); } $this->checkoutSession->setLastQuoteId($quote->getId()); $this->checkoutSession->setLastSuccessQuoteId($quote->getId()); $this->checkoutSession->setLastOrderId($order->getId()); $this->checkoutSession->setLastRealOrderId($order->getIncrementId()); $this->checkoutSession->setLastOrderStatus($order->getStatus()); $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]); return $order->getId(); }