Exemplo n.º 1
0
 /**
  * @dataProvider getCountrySpecificCardTypeConfigDataProvider
  */
 public function testGetCountrySpecificCardTypeConfig($countryCardType, $expectedResult)
 {
     $prefix = 'payment/braintree/';
     $valueMap = [[$prefix . Cc::KEY_COUNTRY_CREDIT_CARD, ScopeInterface::SCOPE_STORE, null, $countryCardType]];
     $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturnMap($valueMap);
     $this->assertEquals($expectedResult, $this->model->getCountrySpecificCardTypeConfig());
 }
Exemplo n.º 2
0
 /**
  * @return array|void
  */
 public function getConfig()
 {
     if (!$this->config->isActive()) {
         return [];
     }
     $config = parent::getConfig();
     $clientToken = $this->config->getClientToken();
     $useVault = $this->config->useVault();
     $selectedCardToken = null;
     $storedCardOptions = [];
     if ($useVault) {
         $storedCards = $this->getStoredCards();
         if (count($storedCards) == 0) {
             $useVault = false;
         } else {
             foreach ($storedCards as $creditCard) {
                 $storedCardOptions[] = ['token' => $creditCard->token, 'maskedNumber' => $creditCard->maskedNumber . ' - ' . $creditCard->cardType, 'selected' => $creditCard->default, 'type' => $this->dataHelper->getCcTypeCodeByName($creditCard->cardType)];
                 if ($creditCard->default) {
                     $selectedCardToken = $creditCard->token;
                 }
             }
         }
     }
     $config = array_merge_recursive($config, ['payment' => ['braintree' => ['clientToken' => $clientToken, 'useVault' => $useVault, 'canSaveCard' => $this->canSaveCard(), 'show3dSecure' => $this->show3dSecure(), 'storedCards' => $storedCardOptions, 'selectedCardToken' => $selectedCardToken, 'creditCardExpMonth' => (int) $this->dataHelper->getTodayMonth(), 'creditCardExpYear' => (int) $this->dataHelper->getTodayYear(), 'countrySpecificCardTypes' => $this->config->getCountrySpecificCardTypeConfig(), 'isFraudDetectionEnabled' => $this->config->isFraudDetectionEnabled(), 'isCcDetectionEnabled' => $this->config->isCcDetectionEnabled(), 'availableCardTypes' => $this->getCcAvailableCcTypes(), 'braintreeDataJs' => $this->config->getBraintreeDataJs(), 'ajaxGenerateNonceUrl' => $this->getAjaxGenerateNonceUrl()]]]);
     return $config;
 }
Exemplo n.º 3
0
 /**
  * Retrieve available credit card types as associative array code & title
  *
  * @param string $country
  * @return array
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getCcAvailableCardTypes($country = null)
 {
     $types = array_flip(explode(',', $this->braintreeCcConfig->getConfigData('cctypes')));
     $mergedArray = [];
     if (is_array($types)) {
         foreach (array_keys($types) as $type) {
             $types[$type] = $this->getCcTypeNameByCode($type);
         }
     }
     //merge options then filter by a specific country
     $countrySpecificTypes = $this->braintreeCcConfig->getCountrySpecificCardTypeConfig();
     //include all country specific in types
     if (is_array($countrySpecificTypes)) {
         foreach ($countrySpecificTypes as $countryArray) {
             foreach ($countryArray as $ccType) {
                 $types[$ccType] = $this->getCcTypeNameByCode($ccType);
             }
         }
     }
     //preserve the same credit card order
     $allTypes = $this->getCcTypes();
     if (is_array($allTypes)) {
         foreach ($allTypes as $ccTypeCode => $ccTypeName) {
             if (array_key_exists($ccTypeCode, $types)) {
                 $mergedArray[$ccTypeCode] = $ccTypeName;
             }
         }
     }
     if ($country) {
         $countrySpecificTypesApplicable = $this->braintreeCcConfig->getApplicableCardTypes($country);
         if (!empty($countrySpecificTypesApplicable)) {
             foreach (array_keys($mergedArray) as $code) {
                 if (!in_array($code, $countrySpecificTypesApplicable)) {
                     unset($mergedArray[$code]);
                 }
             }
         }
     }
     return $mergedArray;
 }
Exemplo n.º 4
0
 /**
  * Retrieve country specific credit card types as json
  *
  * @return string
  */
 public function getCountrySpecificCardTypeConfig()
 {
     return $this->config->getCountrySpecificCardTypeConfig();
 }