/** * Retrieve payment method and assign additional template values * * @return $this * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function _beforeToHtml() { $methodInstance = $this->_quote->getPayment()->getMethodInstance(); $this->setPaymentMethodTitle($methodInstance->getTitle()); $this->setShippingRateRequired(true); if ($this->_quote->getIsVirtual()) { $this->setShippingRateRequired(false); } else { // prepare shipping rates $this->_address = $this->_quote->getShippingAddress(); $groups = $this->_address->getGroupedAllShippingRates(); if ($groups && $this->_address) { $this->setShippingRateGroups($groups); // determine current selected code & name foreach ($groups as $code => $rates) { foreach ($rates as $rate) { if ($this->_address->getShippingMethod() == $rate->getCode()) { $this->_currentShippingRate = $rate; break 2; } } } } $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()->getAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_BUTTON) == 1; // misc shipping parameters $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_controllerPath}/saveShippingMethod"))->setCanEditShippingAddress($canEditShippingAddress)->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod()); } $this->setEditUrl($this->getUrl("{$this->_controllerPath}/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_controllerPath}/placeOrder")); return parent::_beforeToHtml(); }
/** * Execute operation * * @param string $nonce * @param array $details * @param Quote $quote * @return void * @throws \InvalidArgumentException * @throws LocalizedException */ public function execute($nonce, array $details, Quote $quote) { if (empty($nonce) || empty($details)) { throw new \InvalidArgumentException('The "nonce" and "details" fields does not exists'); } $payment = $quote->getPayment(); $payment->setMethod(ConfigProvider::PAYPAL_CODE); $payment->setAdditionalInformation(DataAssignObserver::PAYMENT_METHOD_NONCE, $nonce); $this->updateQuote($quote, $details); }
/** * Covers \Magento\Multishipping\Block\Checkout\Payment\Info and \Magento\Multishipping\Block\Checkout\Overview * * @magentoConfigFixture current_store multishipping/options/checkout_multiple 1 */ public function testOverviewAction() { /** @var \Magento\Framework\Data\Form\FormKey $formKey */ $formKey = $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey'); $logger = $this->getMock('Psr\\Log\\LoggerInterface', [], [], '', false); /** @var \Magento\Customer\Api\AccountManagementInterface $service */ $service = $this->_objectManager->create('Magento\\Customer\\Api\\AccountManagementInterface'); $customer = $service->authenticate('*****@*****.**', 'password'); /** @var \Magento\Customer\Model\Session $customerSession */ $customerSession = $this->_objectManager->create('Magento\\Customer\\Model\\Session', [$logger]); $customerSession->setCustomerDataAsLoggedIn($customer); $this->checkoutSession->setCheckoutState(State::STEP_BILLING); $this->getRequest()->setPostValue('payment', ['method' => 'checkmo']); $this->dispatch('multishipping/checkout/overview'); $html = $this->getResponse()->getBody(); $this->assertContains('<div class="box box-billing-method">', $html); $this->assertContains('<div class="box box-shipping-method">', $html); $this->assertContains('<dt class="title">' . $this->quote->getPayment()->getMethodInstance()->getTitle() . '</dt>', $html); $this->assertContains('<span class="price">$10.00</span>', $html); $this->assertContains('<input name="form_key" type="hidden" value="' . $formKey->getFormKey(), $html); }
public function testGetPaymentIsDeleted() { $this->quote->setId(1); $payment = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', ['setQuote', 'isDeleted', 'getId', '__wakeup'], [], '', false); $payment->expects($this->exactly(2))->method('setQuote'); $payment->expects($this->once())->method('isDeleted')->willReturn(true); $payment->expects($this->once())->method('getId')->willReturn(1); $quotePaymentCollectionMock = $this->getMock('Magento\\Quote\\Model\\Resource\\Quote\\Payment\\Collection', ['setQuoteFilter', 'getFirstItem'], [], '', false); $quotePaymentCollectionMock->expects($this->once())->method('setQuoteFilter')->with(1)->will($this->returnSelf()); $quotePaymentCollectionMock->expects($this->once())->method('getFirstItem')->willReturn($payment); $this->quotePaymentCollectionFactoryMock->expects($this->once())->method('create')->willReturn($quotePaymentCollectionMock); $this->paymentFactoryMock->expects($this->once())->method('create')->willReturn($payment); $this->assertInstanceOf('\\Magento\\Quote\\Model\\Quote\\Payment', $this->quote->getPayment()); }
/** * Set create billing agreement flag to api call * * @return $this */ protected function _setBillingAgreementRequest() { if (!$this->_customerId) { return $this; } $isRequested = $this->_isBARequested || $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT); if (!($this->_config->getValue('allow_ba_signup') == PaypalConfig::EC_BA_SIGNUP_AUTO || $isRequested && $this->_config->shouldAskToCreateBillingAgreement())) { return $this; } if (!$this->_agreementFactory->create()->needToCreateForCustomer($this->_customerId)) { return $this; } $this->_api->setBillingType($this->_api->getBillingAgreementType()); return $this; }
/** * Validate quote before submit * * @param Quote $quote * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function validateBeforeSubmit(QuoteEntity $quote) { if (!$quote->isVirtual()) { if ($quote->getShippingAddress()->validate() !== true) { throw new \Magento\Framework\Exception\LocalizedException(__('Please check the shipping address information. %1', implode(' ', $quote->getShippingAddress()->validate()))); } $method = $quote->getShippingAddress()->getShippingMethod(); $rate = $quote->getShippingAddress()->getShippingRateByCode($method); if (!$quote->isVirtual() && (!$method || !$rate)) { throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a shipping method.')); } } if ($quote->getBillingAddress()->validate() !== true) { throw new \Magento\Framework\Exception\LocalizedException(__('Please check the billing address information. %1', implode(' ', $quote->getBillingAddress()->validate()))); } if (!$quote->getPayment()->getMethod()) { throw new \Magento\Framework\Exception\LocalizedException(__('Please select a valid payment method.')); } return $this; }
/** * Send email id payment was failed * * @param \Magento\Quote\Model\Quote $checkout * @param string $message * @param string $checkoutType * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage') { $this->inlineTranslation->suspend(); $template = $this->scopeConfig->getValue('checkout/payment_failed/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId()); $copyMethod = $this->scopeConfig->getValue('checkout/payment_failed/copy_method', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $bcc = []; if ($copyTo && $copyMethod == 'bcc') { $bcc = $copyTo; } $_receiver = $this->scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $sendTo = [['email' => $this->scopeConfig->getValue('trans_email/ident_' . $_receiver . '/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()), 'name' => $this->scopeConfig->getValue('trans_email/ident_' . $_receiver . '/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId())]]; if ($copyTo && $copyMethod == 'copy') { foreach ($copyTo as $email) { $sendTo[] = ['email' => $email, 'name' => null]; } } $shippingMethod = ''; if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) { $data = explode('_', $shippingInfo); $shippingMethod = $data[0]; } $paymentMethod = ''; if ($paymentInfo = $checkout->getPayment()) { $paymentMethod = $paymentInfo->getMethod(); } $items = ''; foreach ($checkout->getAllVisibleItems() as $_item) { /* @var $_item \Magento\Quote\Model\Quote\Item */ $items .= $_item->getProduct()->getName() . ' x ' . $_item->getQty() . ' ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n"; } $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal(); foreach ($sendTo as $recipient) { $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()])->setTemplateVars(['reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->formatDateTime(new \DateTime(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => $this->scopeConfig->getValue('carriers/' . $shippingMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'paymentMethod' => $this->scopeConfig->getValue('payment/' . $paymentMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'items' => nl2br($items), 'total' => $total])->setFrom($this->scopeConfig->getValue('checkout/payment_failed/identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))->addTo($recipient['email'], $recipient['name'])->addBcc($bcc)->getTransport(); $transport->sendMessage(); } $this->inlineTranslation->resume(); return $this; }
private function initializePaymentMethodData() { $quotePayment = $this->quote->getPayment(); $quotePayment->importData($this->proxyOrder->getPaymentData()); }
public function _populateQuotePaymentMethod(\Magento\Quote\Model\Quote $quote) { $quote->setPaymentMethod(self::METHOD_PAYMENT); $quote->getPayment()->setMethod(self::METHOD_PAYMENT); }