-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Set the region for Apple Pay orders
- Loading branch information
1 parent
96fdc1f
commit d79590c
Showing
3 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Service\Quote; | ||
|
||
use Magento\Directory\Api\CountryInformationAcquirerInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Quote\Api\Data\AddressInterface; | ||
|
||
class SetRegionFromApplePayAddress | ||
{ | ||
/** | ||
* @var CountryInformationAcquirerInterface | ||
*/ | ||
private $countryInformationAcquirer; | ||
|
||
public function __construct( | ||
CountryInformationAcquirerInterface $countryInformationAcquirer | ||
) { | ||
$this->countryInformationAcquirer = $countryInformationAcquirer; | ||
} | ||
|
||
public function execute(AddressInterface $address, array $input): void | ||
{ | ||
if (!array_key_exists('administrativeArea', $input)) { | ||
return; | ||
} | ||
|
||
try { | ||
$information = $this->countryInformationAcquirer->getCountryInfo($input['countryCode']); | ||
} catch (NoSuchEntityException $exception) { | ||
return; | ||
} | ||
|
||
$regions = $information->getAvailableRegions(); | ||
if ($regions === null) { | ||
$address->setRegion($input['administrativeArea']); | ||
return; | ||
} | ||
|
||
foreach ($regions as $region) { | ||
if ($region->getCode() === $input['administrativeArea']) { | ||
$address->setRegionId($region->getId()); | ||
return; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters