Skip to content

Commit

Permalink
OP-558 - introduce FraudSuspicionCommonDTO and refactor converter
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusz-rup committed Jan 29, 2025
1 parent fb586be commit ae23695
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 44 deletions.
93 changes: 49 additions & 44 deletions src/Converter/FraudSuspicionCommonModelConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BitBag\SyliusBlacklistPlugin\Converter;

use BitBag\SyliusBlacklistPlugin\Dto\FraudSuspicionCommonDTO;
use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\FraudSuspicion;
use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\FraudSuspicionInterface;
use BitBag\SyliusBlacklistPlugin\Exception\WrongAddressTypeException;
Expand All @@ -28,47 +29,51 @@ public function __construct(

public function convertFraudSuspicionObject(FraudSuspicionInterface $fraudSuspicion): FraudSuspicionCommonModelInterface
{
$dto = new FraudSuspicionCommonDTO(
order: $fraudSuspicion->getOrder(),
customer: $fraudSuspicion->getCustomer(),
company: $fraudSuspicion->getCompany(),
firstName: $fraudSuspicion->getFirstName(),
lastName: $fraudSuspicion->getLastName(),
email: $fraudSuspicion->getEmail(),
phoneNumber: $fraudSuspicion->getPhoneNumber(),
street: $fraudSuspicion->getStreet(),
city: $fraudSuspicion->getCity(),
province: $fraudSuspicion->getProvince(),
country: $fraudSuspicion->getCountry(),
postcode: $fraudSuspicion->getPostcode(),
customerIp: $fraudSuspicion->getCustomerIp(),
);

return $this->populateFraudSuspicionCommonModel(
$this->fraudSuspicionCommonModelFactory->createNew(),
[
'order' => $fraudSuspicion->getOrder(),
'customer' => $fraudSuspicion->getCustomer(),
'company' => $fraudSuspicion->getCompany(),
'firstName' => $fraudSuspicion->getFirstName(),
'lastName' => $fraudSuspicion->getLastName(),
'email' => $fraudSuspicion->getEmail(),
'phoneNumber' => $fraudSuspicion->getPhoneNumber(),
'street' => $fraudSuspicion->getStreet(),
'city' => $fraudSuspicion->getCity(),
'province' => $fraudSuspicion->getProvince(),
'country' => $fraudSuspicion->getCountry(),
'postcode' => $fraudSuspicion->getPostcode(),
'customerIp' => $fraudSuspicion->getCustomerIp(),
],
$dto,
);
}

public function convertOrderObject(OrderInterface $order, string $addressType): FraudSuspicionCommonModelInterface
{
$address = $this->getAddressFromOrder($order, $addressType);

$dto = new FraudSuspicionCommonDTO(
order: $order,
customer: $order->getCustomer(),
company: $address->getCompany(),
firstName: $address->getFirstName(),
lastName: $address->getLastName(),
email: $order->getCustomer()?->getEmail(),
phoneNumber: $address->getPhoneNumber(),
street: $address->getStreet(),
city: $address->getCity(),
province: $address->getProvinceName(),
country: $address->getCountryCode(),
postcode: $address->getPostcode(),
customerIp: $order->getCustomerIp(),
);

return $this->populateFraudSuspicionCommonModel(
$this->fraudSuspicionCommonModelFactory->createNew(),
[
'order' => $order,
'customer' => $order->getCustomer(),
'company' => $address->getCompany(),
'firstName' => $address->getFirstName(),
'lastName' => $address->getLastName(),
'email' => $order->getCustomer()?->getEmail(),
'phoneNumber' => $address->getPhoneNumber(),
'street' => $address->getStreet(),
'city' => $address->getCity(),
'province' => $address->getProvinceName(),
'country' => $address->getCountryCode(),
'postcode' => $address->getPostcode(),
'customerIp' => $order->getCustomerIp(),
],
$dto,
);
}

Expand All @@ -83,21 +88,21 @@ private function getAddressFromOrder(OrderInterface $order, string $addressType)

private function populateFraudSuspicionCommonModel(
FraudSuspicionCommonModelInterface $model,
array $data,
FraudSuspicionCommonDTO $dto,
): FraudSuspicionCommonModelInterface {
$model->setOrder($data['order']);
$model->setCustomer($data['customer']);
$model->setCompany($data['company']);
$model->setFirstName($data['firstName']);
$model->setLastName($data['lastName']);
$model->setEmail($data['email']);
$model->setPhoneNumber($data['phoneNumber']);
$model->setStreet($data['street']);
$model->setCity($data['city']);
$model->setProvince($data['province']);
$model->setCountry($data['country']);
$model->setPostcode($data['postcode']);
$model->setCustomerIp($data['customerIp']);
$model->setOrder($dto->order);
$model->setCustomer($dto->customer);

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.2, Symfony ^6.4

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.2, Symfony ^7.1

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.3, Symfony ^6.4

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.3, Symfony ^7.1

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.2, Symfony ^6.4

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.2, Symfony ^7.1

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.3, Symfony ^6.4

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.

Check failure on line 94 in src/Converter/FraudSuspicionCommonModelConverter.php

View workflow job for this annotation

GitHub Actions / Sylius ~2.0.0, PHP 8.3, Symfony ^7.1

Parameter #1 $customer of method BitBag\SyliusBlacklistPlugin\Model\FraudSuspicionCommonModelInterface::setCustomer() expects Sylius\Component\Customer\Model\CustomerInterface|null, object|null given.
$model->setCompany($dto->company);
$model->setFirstName($dto->firstName);
$model->setLastName($dto->lastName);
$model->setEmail($dto->email);
$model->setPhoneNumber($dto->phoneNumber);
$model->setStreet($dto->street);
$model->setCity($dto->city);
$model->setProvince($dto->province);
$model->setCountry($dto->country);
$model->setPostcode($dto->postcode);
$model->setCustomerIp($dto->customerIp);

return $model;
}
Expand Down
34 changes: 34 additions & 0 deletions src/Dto/FraudSuspicionCommonDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusBlacklistPlugin\Dto;

use Sylius\Component\Order\Model\OrderInterface;

class FraudSuspicionCommonDTO
{
public function __construct(
public ?OrderInterface $order,
public ?object $customer,
public ?string $company,
public ?string $firstName,
public ?string $lastName,
public ?string $email,
public ?string $phoneNumber,
public ?string $street,
public ?string $city,
public ?string $province,
public ?string $country,
public ?string $postcode,
public ?string $customerIp,
) {
}
}

0 comments on commit ae23695

Please sign in to comment.