Skip to content

Commit

Permalink
updated model
Browse files Browse the repository at this point in the history
  • Loading branch information
vasildakov committed Dec 28, 2023
1 parent dee0c93 commit 26caf57
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 2 deletions.
12 changes: 10 additions & 2 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use VasilDakov\Econt\Request\GetCitiesRequest;
use VasilDakov\Econt\Request\GetOfficesRequest;
use VasilDakov\Econt\Response\GetCitiesResponseFactory;
use VasilDakov\Econt\Response\GetClientProfilesResponse;
use VasilDakov\Econt\Response\GetOfficesResponseFactory;
use VasilDakov\Econt\Serializer\SerializerFactory;

chdir(dirname(__DIR__));

Expand All @@ -37,6 +39,12 @@
$factory = new RequestFactory();

$econt = new Econt($configuration, $client, $factory);
$json = $econt->getClientProfiles();

$serilizer = (new SerializerFactory())();
$object = $serilizer->deserialize($json, GetClientProfilesResponse::class, 'json');
dump($object);


/*
$json = $econt->getCities(new GetCitiesRequest(countryCode: 'BGR'));
Expand All @@ -45,7 +53,7 @@
dump($object->findByName('София'));
*/

$json = $econt->getOffices(new GetOfficesRequest(countryCode: 'BGR', cityId: '39'));
/* $json = $econt->getOffices(new GetOfficesRequest(countryCode: 'BGR', cityId: '39'));
$response = (new GetOfficesResponseFactory())($json);

dump($response);
*/
18 changes: 18 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@

final class Constants
{
public const ID = 'id';
public const NAME = 'name';
public const NUM = 'num';
public const CLIENT = 'client';
public const MONEY_TRANSFER = 'moneyTransfer';
public const OFFICE_CODE = 'officeCode';
public const IBAN = 'IBAN';
public const BIC = 'BIC';
public const BANK_CURRENCY = 'bankCurrency';
public const EXPRESS = 'express';
public const METHOD = 'method';
public const TYPE = 'type';
public const MESSAGE = 'message';
public const FIELDS = 'fields';
public const INNER_ERRORS = 'innerErrors';
public const NAME_EN = 'nameEn';
public const CITY = 'city';
public const CITY_ID = 'cityID';
public const ADDRESS = 'address';
public const PHONES = 'phones';
public const EMAIL = 'email';
public const DATE = 'date';
public const COUNTRY_CODE = 'countryCode';
public const SHIPMENT_TYPE = 'shipmentType';
Expand Down
32 changes: 32 additions & 0 deletions src/Model/CDPayOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;

final readonly class CDPayOptions
{
public function __construct(
#[Serializer\Type('string')]
public ?string $num,

#[Serializer\Type(ClientProfile::class)]
public ?ClientProfile $clientProfile,

#[Serializer\Type('bool')]
public ?bool $moneyTransfer,

#[Serializer\Type('bool')]
public ?bool $express,

#[Serializer\Type('string')]
public ?string $method,

#[Serializer\Type(Address::class)]
public ?Address $address,
) {

}
}
41 changes: 41 additions & 0 deletions src/Model/ClientProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;
use VasilDakov\Econt\Constants;

final readonly class ClientProfile
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id = null,

#[Serializer\Type('string')]
public ?string $name = null,

#[Serializer\Type('string')]
public ?string $nameEn = null,

#[Serializer\Type('array')]
public ?array $phones = null,

#[Serializer\Type('string')]
public ?string $email = null,
) {

}

public function toArray(): array
{
return [
Constants::ID => $this->id,
Constants::NAME => $this->name,
Constants::NAME_EN => $this->nameEn,
Constants::PHONES => $this->phones,
Constants::EMAIL => $this->email,
];
}
}
39 changes: 39 additions & 0 deletions src/Model/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;
use VasilDakov\Econt\Constants;

final readonly class Error
{
public function __construct(
#[Serializer\Type('string')]
public ?string $type = null,

#[Serializer\Type('string')]
public ?string $message = null,

#[Serializer\Type('string')]
public ?string $fields = null,

#[Serializer\Type('string')]
public ?string $innerErrors = null,
) {

}

public function toArray(): array
{
return [
Constants::TYPE => $this->type,
Constants::MESSAGE => $this->message,
Constants::FIELDS => $this->fields,
Constants::INNER_ERRORS => $this->innerErrors


];
}
}
2 changes: 2 additions & 0 deletions src/Model/GeoLocation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;
Expand Down
29 changes: 29 additions & 0 deletions src/Model/Instruction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;

final readonly class Instruction
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id = null,

#[Serializer\Type('string')]
public ?string $type = null,

#[Serializer\Type('string')]
public ?string $title = null,

#[Serializer\Type('string')]
public ?string $description = null,

#[Serializer\Type('array')]
public ?array $attachments = [],
) {

}
}
28 changes: 28 additions & 0 deletions src/Model/ProfilesResponseElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use Doctrine\Common\Collections\ArrayCollection;
use JMS\Serializer\Annotation as Serializer;


final class ProfilesResponseElement
{
public function __construct(
#[Serializer\Type(ClientProfile::class)]
public ?ClientProfile $client,

#[Serializer\Type('ArrayCollection<VasilDakov\Econt\Model\Address>')]
public ArrayCollection $addresses,

#[Serializer\Type(CDPayOptions::class)]
public ?CDPayOptions $cdPayOptions,

#[Serializer\Type(Instruction::class)]
public ?Instruction $instructionTemplates,
) {
$this->addresses = new ArrayCollection();
}
}
37 changes: 37 additions & 0 deletions src/Model/Quarter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;
use VasilDakov\Econt\Constants;

final readonly class Quarter
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id = null,

#[Serializer\Type('int')]
public ?int $cityId = null,

#[Serializer\Type('string')]
public ?string $name = null,

#[Serializer\Type('string')]
public ?string $nameEn = null,
) {

}

public function toArray(): array
{
return [
Constants::ID => $this->id,
Constants::CITY_ID => $this->cityId,
Constants::NAME => $this->name,
Constants::NAME_EN => $this->nameEn,
];
}
}
17 changes: 17 additions & 0 deletions src/Model/ShippingLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;

final readonly class ShippingLabel
{
public function __construct(
#[Serializer\Type('string')]
public ?string $shipmentNumber = null,
) {

}
}
37 changes: 37 additions & 0 deletions src/Model/Street.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Model;

use JMS\Serializer\Annotation as Serializer;
use VasilDakov\Econt\Constants;

final readonly class Street
{
public function __construct(
#[Serializer\Type('int')]
public ?int $id = null,

#[Serializer\Type('int')]
public ?int $cityId = null,

#[Serializer\Type('string')]
public ?string $name = null,

#[Serializer\Type('string')]
public ?string $nameEn = null,
) {

}

public function toArray(): array
{
return [
Constants::ID => $this->id,
Constants::CITY_ID => $this->cityId,
Constants::NAME => $this->name,
Constants::NAME_EN => $this->nameEn,
];
}
}
14 changes: 14 additions & 0 deletions src/Response/GetClientProfilesResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace VasilDakov\Econt\Response;

use Doctrine\Common\Collections\ArrayCollection;
use JMS\Serializer\Annotation as Serializer;

final readonly class GetClientProfilesResponse
{
#[Serializer\Type("ArrayCollection<VasilDakov\Econt\Model\ProfilesResponseElement>")]
private ArrayCollection $profiles;
}

0 comments on commit 26caf57

Please sign in to comment.