/** * Validate data * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function validate() { $info = $this->getInfoInstance(); if ($info instanceof \Magento\Sales\Model\Order\Payment) { $billingCountry = $info->getOrder()->getBillingAddress()->getCountryId(); } else { $billingCountry = $info->getQuote()->getBillingAddress()->getCountryId(); } if (!$this->config->canUseForCountry($billingCountry)) { throw new LocalizedException(__('Selected payment type is not allowed for billing country.')); } $ccType = $info->getCcType(); if (!$ccType) { $token = $this->getInfoInstance()->getAdditionalInformation('cc_token'); if ($token) { $ccType = $this->vault->getSavedCardType($token); } } if ($ccType) { $error = $this->config->canUseCcTypeForCountry($billingCountry, $ccType); if ($error) { throw new LocalizedException($error); } } return $this; }