示例#1
0
 /**
  * Returns countries array
  * 
  * @return array
  */
 protected function _getCountries()
 {
     if (!$this->countries) {
         $restrictedCountries = $this->countrySource->getRestrictedCountries();
         $this->countries = $this->countryCollectionFactory->create()->addFieldToFilter('country_id', ['nin' => $restrictedCountries])->loadData()->toOptionArray(false);
     }
     return $this->countries;
 }
示例#2
0
 public function testToOptionArray()
 {
     $excludedCountries = $this->model->getRestrictedCountries();
     $countries = [['value' => 'US', 'lable' => 'United States'], ['value' => 'countryCode', 'lable' => 'countryName']];
     $this->countryCollectionMock->expects($this->once())->method('addFieldToFilter')->with('country_id', ['nin' => $excludedCountries])->willReturnSelf();
     $this->countryCollectionMock->expects($this->once())->method('loadData')->willReturnSelf();
     $this->countryCollectionMock->expects($this->once())->method('toOptionArray')->willReturn($countries);
     $header = ['value' => '', 'label' => new \Magento\Framework\Phrase('--Please Select--')];
     array_unshift($countries, $header);
     $this->assertEquals($countries, $this->model->toOptionArray());
 }
 /**
  * @dataProvider canUseForCountryNotAllowSpecificDataProvider
  */
 public function testCanUseForCountryNotAllowSpecific($isRestricted, $expected)
 {
     $countryId = 'non-existing';
     $prefix = 'payment/braintree/';
     $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with($prefix . Config::KEY_ALLOW_SPECIFIC, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)->willReturn(0);
     $this->sourceCountryMock->expects($this->once())->method('isCountryRestricted')->with($countryId)->willReturn($isRestricted);
     $this->assertEquals($expected, $this->model->canUseForCountry($countryId));
 }
示例#4
0
 /**
  * Loads country collection
  *
  * @return \Magento\Directory\Model\ResourceModel\Country\Collection
  */
 public function getCountryCollection()
 {
     $collection = $this->getData('country_collection');
     if ($collection == null) {
         $restrictedCountriesByBraintree = $this->countrySource->getRestrictedCountries();
         $collection = $this->_countryCollectionFactory->create()->addFieldToFilter('country_id', ['nin' => $restrictedCountriesByBraintree])->loadByStore();
         foreach ($collection as $item) {
             $countryCode = $item->getData('country_id');
             if (!$this->config->canUseForCountry($countryCode)) {
                 $restrictedCountriesByBraintree[] = $item->getData('country_id');
             }
         }
         $collection = $this->_countryCollectionFactory->create()->addFieldToFilter('country_id', ['nin' => $restrictedCountriesByBraintree])->loadByStore();
         $this->setData('country_collection', $collection);
     }
     return $collection;
 }
示例#5
0
 /**
  * To check billing country is allowed for the payment method
  *
  * @param string $country
  * @return bool
  */
 public function canUseForCountry($country)
 {
     /*
     for specific country, the flag will set up as 1
     */
     if ($this->getConfigData(self::KEY_ALLOW_SPECIFIC) == 1) {
         $availableCountries = explode(',', $this->getConfigData(self::KEY_SPECIFIC_COUNTRY));
         if (!in_array($country, $availableCountries)) {
             return false;
         }
     } elseif ($this->sourceCountry->isCountryRestricted($country)) {
         return false;
     }
     return true;
 }