-
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.
Merge pull request #2 from answear/parcel-shop-list
Get parcel shop list
- Loading branch information
Showing
30 changed files
with
1,606 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
# ACS stations bundle | ||
|
||
ACS pickup point integration for Symfony. | ||
|
||
## Installation | ||
|
||
* install with Composer | ||
|
||
``` | ||
composer require [email protected]:answear/acs-bundle.git | ||
``` | ||
|
||
`Answear\AcsBundle\AnswearAcsBundle::class => ['all' => true],` | ||
should be added automatically to your `config/bundles.php` file by Symfony Flex. | ||
|
||
## Setup | ||
|
||
* provide required config data: `apiKey`, `companyId`, `companyId`, `userId`, `userPassword` | ||
|
||
```yaml | ||
# config/packages/answear_acs.yaml | ||
answear_gls: | ||
apiKey: | ||
companyId: | ||
companyPassword: | ||
userId: | ||
userPassword: | ||
language: //default GR | ||
``` | ||
## Usage | ||
### Get ParcelShops | ||
```php | ||
/** @var \Answear\AcsBundle\Service\ParcelShopsService $parcelShopService **/ | ||
$parcelShopService->getList(CountryIdEnum $countryId, ?int $kind = null); | ||
``` | ||
|
||
will return `\Answear\AcsBundle\Response\DTO\ParcelShop[]` array. | ||
|
||
Where `countryId` is Greece or Cyprus, and `kind` is shop kind according to ACS documentation, `null` means all kinds | ||
|
||
### Error handling | ||
|
||
- `Answear\AcsBundle\Exception\ServiceUnavailable` for all `GuzzleException` | ||
- `Answear\AcsBundle\Exception\MalformedResponse` for incorrect responses | ||
|
||
Final notes | ||
------------ | ||
|
||
Feel free to open pull requests with new features, improvements or bug fixes. The Answear team will be grateful for any comments. |
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
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\AcsBundle\Enum; | ||
|
||
use MabeEnum\Enum; | ||
|
||
class CountryIdEnum extends Enum | ||
{ | ||
public const GREECE = 'GR'; | ||
public const CYPRUS = 'CY'; | ||
|
||
public static function greece(): self | ||
{ | ||
return static::get(static::GREECE); | ||
} | ||
|
||
public static function cyprus(): self | ||
{ | ||
return static::get(static::CYPRUS); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\AcsBundle\Exception; | ||
|
||
class MalformedResponse extends \RuntimeException | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
private $response; | ||
|
||
public function __construct($message, $response, ?\Throwable $previous = null) | ||
{ | ||
parent::__construct($message, 0, $previous); | ||
|
||
$this->response = $response; | ||
} | ||
|
||
public function getResponse() | ||
{ | ||
return $this->response; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\AcsBundle\Request; | ||
|
||
class BaseInputParameters | ||
{ | ||
protected string $companyId; | ||
protected string $companyPassword; | ||
protected string $userId; | ||
protected string $userPassword; | ||
protected string $language; | ||
|
||
public function __construct(string $companyId, string $companyPassword, string $userId, string $userPassword, string $language) | ||
{ | ||
$this->companyId = $companyId; | ||
$this->companyPassword = $companyPassword; | ||
$this->userId = $userId; | ||
$this->userPassword = $userPassword; | ||
$this->language = $language; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'Company_ID' => $this->companyId, | ||
'Company_Password' => $this->companyPassword, | ||
'User_ID' => $this->userId, | ||
'User_Password' => $this->userPassword, | ||
'language' => $this->language, | ||
]; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\AcsBundle\Request; | ||
|
||
interface Request | ||
{ | ||
/** | ||
* Converts request object to json that will be sent via the API. | ||
*/ | ||
public function toJson(): string; | ||
} |
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 Answear\AcsBundle\Request; | ||
|
||
use Answear\AcsBundle\Enum\CountryIdEnum; | ||
|
||
class StationsRequest implements Request | ||
{ | ||
private const ALIAS = 'ACS_Stations'; | ||
|
||
private BaseInputParameters $baseInputParameters; | ||
private CountryIdEnum $countryId; | ||
private ?int $kind; | ||
|
||
public function __construct(BaseInputParameters $baseInputParameters, CountryIdEnum $countryId, ?int $kind = null) | ||
{ | ||
$this->baseInputParameters = $baseInputParameters; | ||
$this->countryId = $countryId; | ||
$this->kind = $kind; | ||
} | ||
|
||
public function toJson(): string | ||
{ | ||
$parameters = [ | ||
'ACS_SHOP_COUNTRY_ID' => $this->countryId->getValue(), | ||
]; | ||
|
||
if (null !== $this->kind) { | ||
$parameters['ACS_SHOP_KIND'] = $this->kind; | ||
} | ||
|
||
return json_encode([ | ||
'ACSAlias' => self::ALIAS, | ||
'ACSInputParameters' => array_merge($parameters, $this->baseInputParameters->toArray()), | ||
], JSON_THROW_ON_ERROR); | ||
} | ||
} |
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,9 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
Answear\AcsBundle\ConfigProvider: ~ | ||
Answear\AcsBundle\Service\Client: ~ | ||
Answear\AcsBundle\Service\ParcelShopsService: ~ |
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,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\AcsBundle\Response\DTO; | ||
|
||
use Webmozart\Assert\Assert; | ||
|
||
class Address | ||
{ | ||
private string $street; | ||
private string $zipCode; | ||
private string $city; | ||
private string $phones; | ||
private string $email; | ||
private string $fax; | ||
|
||
public function __construct( | ||
string $street, | ||
string $zipCode, | ||
string $city, | ||
string $phones, | ||
string $email, | ||
string $fax | ||
) { | ||
$this->street = $street; | ||
$this->zipCode = $zipCode; | ||
$this->city = $city; | ||
$this->phones = $phones; | ||
$this->email = $email; | ||
$this->fax = $fax; | ||
} | ||
|
||
public static function fromArray(array $parcelShopArray): self | ||
{ | ||
Assert::keyExists($parcelShopArray, 'ACS_SHOP_ADDRESS'); | ||
Assert::keyExists($parcelShopArray, 'ACS_SHOP_ZIPCODE'); | ||
Assert::keyExists($parcelShopArray, 'ACS_SHOP_CITY'); | ||
Assert::keyExists($parcelShopArray, 'ACS_SHOP_PHONES'); | ||
Assert::keyExists($parcelShopArray, 'ACS_SHOP_EMAIL'); | ||
Assert::keyExists($parcelShopArray, 'ACS_SHOP_FAX'); | ||
|
||
return new self( | ||
$parcelShopArray['ACS_SHOP_ADDRESS'], | ||
$parcelShopArray['ACS_SHOP_ZIPCODE'], | ||
$parcelShopArray['ACS_SHOP_CITY'], | ||
$parcelShopArray['ACS_SHOP_PHONES'], | ||
$parcelShopArray['ACS_SHOP_EMAIL'], | ||
$parcelShopArray['ACS_SHOP_FAX'] | ||
); | ||
} | ||
|
||
public function getZipCode(): string | ||
{ | ||
return $this->zipCode; | ||
} | ||
|
||
public function getCity(): string | ||
{ | ||
return $this->city; | ||
} | ||
|
||
public function getStreet(): string | ||
{ | ||
return $this->street; | ||
} | ||
|
||
public function getFax(): ?string | ||
{ | ||
return $this->fax; | ||
} | ||
|
||
public function getPhones(): ?string | ||
{ | ||
return $this->phones; | ||
} | ||
|
||
public function getEmail(): ?string | ||
{ | ||
return $this->email; | ||
} | ||
} |
Oops, something went wrong.