/** * Returns customer credit cards if applicable * * @return \Braintree_Customer|boolean */ public function getLoggedInCustomerCards() { $applicableCards = []; $useVault = (bool) (int) $this->scopeConfig->getValue(self::CONFIG_PATH_VAULT, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $this->sessionQuote->getStoreId()); if ($useVault) { $storedCards = false; if ($this->sessionQuote->getCustomerId()) { $customerId = $this->paymentHelper->generateCustomerId($this->sessionQuote->getCustomerId(), $this->sessionQuote->getQuote()->getCustomerEmail()); try { $storedCards = $this->braintreeCustomerAdapter->find($customerId)->creditCards; } catch (\Braintree_Exception $e) { $this->_logger->critical($e); } } if ($storedCards) { $country = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId(); $cardTypes = $this->paymentHelper->getCcAvailableCardTypes($country); $applicableCards = []; foreach ($storedCards as $card) { if (isset($cardTypes[$this->paymentHelper->getCcTypeCodeByName($card->cardType)])) { $applicableCards[] = $card; } } } } return $applicableCards; }
/** * @return array */ public function getOneClickCards() { $customerId = $this->_sessionQuote->getCustomerId(); $storeId = $this->_sessionQuote->getStoreId(); $grandTotal = $this->_sessionQuote->getQuote()->getGrandTotal(); // For backend only allow recurring payments $recurringType = \Adyen\Payment\Model\RecurringType::RECURRING; $cards = $this->_adyenHelper->getOneClickPaymentMethods($customerId, $storeId, $grandTotal, $recurringType); return $cards; }
/** * Cancel active partial authorizations * * @return void */ public function execute() { $result['success'] = false; try { $paymentMethod = $this->_objectManager->get('Magento\\Payment\\Helper\\Data')->getMethodInstance(\Magento\Authorizenet\Model\Authorizenet::METHOD_CODE); if ($paymentMethod) { $paymentMethod->setStore($this->_sessionQuote->getQuote()->getStoreId()); $paymentMethod->cancelPartialAuthorization($this->_sessionQuote->getQuote()->getPayment()); } $result['success'] = true; $result['update_html'] = $this->_objectManager->get('Magento\\Authorizenet\\Helper\\Data')->getPaymentMethodsHtml($this->_view); } catch (\Magento\Framework\Model\Exception $e) { $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $result['error_message'] = $e->getMessage(); } catch (\Exception $e) { $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $result['error_message'] = __('Something went wrong canceling the transactions.'); } $this->_sessionQuote->getQuote()->getPayment()->save(); $this->getResponse()->representJson($this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode($result)); }
/** * Retrieve availables credit card types * * @return array */ public function getCcAvailableTypes() { if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { $country = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId(); } else { $country = $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId(); } $applicableTypes = $this->config->getApplicableCardTypes($country); $types = $this->_paymentConfig->getCcTypes(); foreach (array_keys($types) as $code) { if (!in_array($code, $applicableTypes)) { unset($types[$code]); } } return $types; }
/** * Run test getQuote method * * @return void * @dataProvider getQuoteDataProvider */ public function testGetQuoteWithQuoteId($customerId, $quoteCustomerId, $expectedNumberOfInvokes) { $quoteId = 22; $storeId = 10; $this->quote->expects($this->any())->method('getQuoteId')->will($this->returnValue($quoteId)); $this->quote->expects($this->any())->method('setQuoteId')->with($quoteId); $this->quote->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->quote->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId)); $dataCustomerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerRepositoryMock->expects($this->{$expectedNumberOfInvokes}())->method('getById')->with($customerId)->willReturn($dataCustomerMock); $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['setStoreId', 'setCustomerGroupId', 'setIsActive', 'getId', 'assignCustomer', 'setIgnoreOldQty', 'setIsSuperMode', 'getCustomerId', '__wakeup'], [], '', false); $quoteMock->expects($this->once())->method('setStoreId')->with($storeId); $quoteMock->expects($this->{$expectedNumberOfInvokes}())->method('assignCustomer')->with($dataCustomerMock); $quoteMock->expects($this->once())->method('setIgnoreOldQty')->with(true); $quoteMock->expects($this->once())->method('setIsSuperMode')->with(true); $quoteMock->expects($this->once())->method('getCustomerId')->will($this->returnValue($quoteCustomerId)); $this->quoteRepositoryMock->expects($this->once())->method('get')->with($quoteId)->willReturn($quoteMock); $this->assertEquals($quoteMock, $this->quote->getQuote()); }
/** * Retrieve quote object * * @return \Magento\Quote\Model\Quote */ protected function _getQuote() { return $this->_session->getQuote(); }
/** * Enter description here... * * @return \Magento\Sales\Model\Quote */ public function getQuote() { return $this->_sessionQuote->getQuote(); }
/** * Get list of available card types of order billing address country * @return array */ public function getCcAvailableTypes() { $configuredCardTypes = $this->getConfiguredCardTypes(); $countryId = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId(); return $this->filterCardTypesForCountry($configuredCardTypes, $countryId); }
/** * Indicates that block can display gift message form * * @return bool */ public function canDisplayGiftmessageForm() { $quote = $this->_sessionQuote->getQuote(); return $this->_messageHelper->isMessagesAllowed('items', $quote, $quote->getStore()); }