sessionQuote = $sessionQuote; $this->gatewayConfig = $gatewayConfig; $this->ccType = $ccType; $this->paymentDataHelper = $paymentDataHelper; } /** * 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); } /** * Check if cvv validation is available * @return boolean */ public function useCvv() { return $this->gatewayConfig->isCvvEnabled($this->sessionQuote->getStoreId()); } /** * Check if vault enabled * @return bool */ public function isVaultEnabled() { $vaultPayment = $this->getVaultPayment(); return $vaultPayment->isActive($this->sessionQuote->getStoreId()); } /** * Get card types available for Braintree * @return array */ private function getConfiguredCardTypes() { $types = $this->ccType->getCcTypeLabelMap(); $configCardTypes = array_fill_keys( $this->gatewayConfig->getAvailableCardTypes($this->sessionQuote->getStoreId()), '' ); return array_intersect_key($types, $configCardTypes); } /** * Filter card types for specific country * @param array $configCardTypes * @param string $countryId * @return array */ private function filterCardTypesForCountry(array $configCardTypes, $countryId) { $filtered = $configCardTypes; $countryCardTypes = $this->gatewayConfig->getCountryAvailableCardTypes( $countryId, $this->sessionQuote->getStoreId() ); // filter card types only if specific card types are set for country if (!empty($countryCardTypes)) { $availableTypes = array_fill_keys($countryCardTypes, ''); $filtered = array_intersect_key($filtered, $availableTypes); } return $filtered; } /** * Get configured vault payment for Braintree * @return VaultPaymentInterface */ private function getVaultPayment() { return $this->paymentDataHelper->getMethodInstance(ConfigProvider::CC_VAULT_CODE); } }