-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
WorldlineConnect
authored and
jenkins
committed
Aug 28, 2024
1 parent
c5b7275
commit 4e05fe4
Showing
8 changed files
with
110 additions
and
160 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
39 changes: 39 additions & 0 deletions
39
Model/Worldline/RequestBuilder/Common/Order/AddressPersonalBuilder.php
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worldline\Connect\Model\Worldline\RequestBuilder\Common\Order; | ||
|
||
use Magento\Sales\Api\Data\OrderAddressInterface; | ||
use Worldline\Connect\Helper\Format; | ||
use Worldline\Connect\Sdk\V1\Domain\AddressPersonal; | ||
use Worldline\Connect\Sdk\V1\Domain\AddressPersonalFactory; | ||
|
||
use function array_key_exists; | ||
|
||
class AddressPersonalBuilder | ||
{ | ||
public function __construct( | ||
private readonly AddressPersonalFactory $addressPersonalFactory, | ||
private readonly Format $format, | ||
) { | ||
} | ||
|
||
public function build(OrderAddressInterface $orderAddress): AddressPersonal | ||
{ | ||
$addressPersonal = $this->addressPersonalFactory->create(); | ||
$addressPersonal->city = $this->format->limit($orderAddress->getCity(), 40); | ||
$addressPersonal->countryCode = $orderAddress->getCountryId(); | ||
$addressPersonal->state = $orderAddress->getRegion(); | ||
$addressPersonal->zip = $orderAddress->getPostcode(); | ||
|
||
$street = $orderAddress->getStreet(); | ||
if ($street !== null) { | ||
$addressPersonal->street = $this->format->limit(array_key_exists(0, $street) ? $street[0] : '', 50); | ||
$addressPersonal->houseNumber = $this->format->limit(array_key_exists(1, $street) ? $street[1] : '', 15); | ||
$addressPersonal->additionalInfo = $this->format->limit(array_key_exists(2, $street) ? $street[2] : '', 50); | ||
} | ||
|
||
return $addressPersonal; | ||
} | ||
} |
50 changes: 14 additions & 36 deletions
50
Model/Worldline/RequestBuilder/Common/Order/Customer/AddressBuilder.php
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 |
---|---|---|
@@ -1,55 +1,33 @@ | ||
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worldline\Connect\Model\Worldline\RequestBuilder\Common\Order\Customer; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Sales\Api\Data\OrderAddressInterface; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Worldline\Connect\Helper\Format; | ||
use Worldline\Connect\Model\Worldline\RequestBuilder\Common\Order\AbstractAddressBuilder; | ||
use Worldline\Connect\Model\Worldline\RequestBuilder\Common\Order\AddressPersonalBuilder; | ||
use Worldline\Connect\Sdk\V1\Domain\AddressPersonal; | ||
use Worldline\Connect\Sdk\V1\Domain\AddressPersonalFactory; | ||
|
||
class AddressBuilder extends AbstractAddressBuilder | ||
{ | ||
/** | ||
* @var AddressPersonalFactory | ||
*/ | ||
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint | ||
private $addressPersonalFactory; | ||
|
||
public function __construct(Format $format, AddressPersonalFactory $addressPersonalFactory) | ||
{ | ||
parent::__construct($format); | ||
|
||
$this->addressPersonalFactory = $addressPersonalFactory; | ||
} | ||
|
||
public function create(OrderInterface $order): AddressPersonal | ||
{ | ||
$addressPersonal = $this->addressPersonalFactory->create(); | ||
|
||
try { | ||
$billingAddress = $this->getBillingAddressFromOrder($order); | ||
$this->populateAddress($addressPersonal, $billingAddress); | ||
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch | ||
} catch (LocalizedException $e) { | ||
//Do nothing | ||
} | ||
use function __; | ||
|
||
return $addressPersonal; | ||
class AddressBuilder | ||
{ | ||
public function __construct( | ||
private readonly AddressPersonalBuilder $addressPersonalBuilder, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws LocalizedException | ||
*/ | ||
public function getBillingAddressFromOrder(OrderInterface $order): OrderAddressInterface | ||
public function create(OrderInterface $order): AddressPersonal | ||
{ | ||
$billingAddress = $order->getBillingAddress(); | ||
if ($billingAddress === null) { | ||
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName | ||
throw new LocalizedException(__('No billing address available for this order')); | ||
throw new LocalizedException(__('No shipping address available for this order')); | ||
} | ||
return $billingAddress; | ||
|
||
return $this->addressPersonalBuilder->build($billingAddress); | ||
} | ||
} |
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
Oops, something went wrong.