/** * 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; }
/** * If customer exists in Braintree * * @param int $customerId * @return bool */ public function exists($customerId) { try { $this->braintreeCustomer->find($customerId); } catch (\Braintree_Exception $e) { $this->logger->critical($e); return false; } return true; }