Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions Controller/Apm/IsAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Payplug\Payments\Controller\Apm;

use Exception;
use Magento\Directory\Model\Country;
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
Expand Down Expand Up @@ -68,23 +69,24 @@ public function execute(): Json
$countryCollection->addFieldToFilter('country_id', ['in' => $allowedCountryIds]);
$countryCollection->loadData();

$countryNames = [];
/**
* @return string
* @var Country $country
*/
$countryNames = array_map(
static fn (Country $country) => $country->getName(),
$countryCollection->getItems()
);

foreach ($countryCollection as $country) {
$countryNames[] = $country->getName();
}
$countries = implode(', ', $countryNames);

if (count($countryNames) === 1) {
$message = __(
'Billing address is not eligible with this payment method. Allowed country : %1',
implode(',', $countryNames)
);
} else {
$message = __(
'Billing address is not eligible with this payment method. Allowed countries : %1',
implode(',', $countryNames)
);
}
$message = count($countryNames) === 1 ? __(
'Billing address is not eligible with this payment method. Allowed country : %1',
$countries
) : __(
'Billing address is not eligible with this payment method. Allowed countries : %1',
$countries
);

$result->setData([
'success' => false,
Expand Down
Loading