-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new methods for payments, taxes history (#32)
* add new methods * update tests and codestyle * codestyle * add errorhadler * update codestyle, fix psalm errors * update readme
- Loading branch information
Showing
22 changed files
with
674 additions
and
12 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,59 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Shoman4eg\Nalog\Api; | ||
|
||
use Psr\Http\Client\ClientExceptionInterface; | ||
use Shoman4eg\Nalog\ErrorHandler; | ||
use Shoman4eg\Nalog\Exception\DomainException; | ||
use Shoman4eg\Nalog\Model\Tax\HistoryRecords; | ||
use Shoman4eg\Nalog\Model\Tax\PaymentRecords; | ||
use Shoman4eg\Nalog\Model\Tax\Tax as TaxModel; | ||
|
||
/** | ||
* @author Artem Dubinin <artem@dubinin.me> | ||
*/ | ||
final class Tax extends BaseHttpApi | ||
{ | ||
/** | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function get(): TaxModel | ||
{ | ||
$response = $this->httpGet('/taxes'); | ||
|
||
return $this->hydrator->hydrate($response, TaxModel::class); | ||
} | ||
|
||
/** | ||
* @throws \JsonException | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function history(?string $oktmo = null): HistoryRecords | ||
{ | ||
$response = $this->httpPost('/taxes/history', [ | ||
'oktmo' => $oktmo, | ||
]); | ||
|
||
return $this->hydrator->hydrate($response, HistoryRecords::class); | ||
} | ||
|
||
/** | ||
* @throws \JsonException | ||
* @throws ClientExceptionInterface | ||
* @throws DomainException | ||
*/ | ||
public function payments(?string $oktmo = null, bool $onlyPaid = false): PaymentRecords | ||
{ | ||
$response = $this->httpPost('/taxes/payments', [ | ||
'oktmo' => $oktmo, | ||
'onlyPaid' => $onlyPaid, | ||
]); | ||
|
||
if ($response->getStatusCode() >= 400) { | ||
(new ErrorHandler())->handleResponse($response); | ||
} | ||
|
||
return $this->hydrator->hydrate($response, PaymentRecords::class); | ||
} | ||
} |
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
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,123 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Shoman4eg\Nalog\Model\Tax; | ||
|
||
use Shoman4eg\Nalog\Model\CreatableFromArray; | ||
|
||
/** | ||
* @author Artem Dubinin <artem@dubinin.me> | ||
*/ | ||
final class History implements CreatableFromArray | ||
{ | ||
private int $taxPeriodId; | ||
private float $taxAmount; | ||
private float $bonusAmount; | ||
private float $paidAmount; | ||
private ?float $taxBaseAmount; | ||
private ?\DateTimeImmutable $chargeDate; | ||
private ?\DateTimeImmutable $dueDate; | ||
private string $oktmo; | ||
private string $regionName; | ||
private string $kbk; | ||
private string $taxOrganCode; | ||
private string $type; | ||
private int $krsbTaxChargeId; | ||
private int $receiptCount; | ||
|
||
private function __construct() {} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public static function createFromArray(array $data): self | ||
{ | ||
$model = new self(); | ||
$model->taxPeriodId = $data['taxPeriodId']; | ||
$model->taxAmount = $data['taxAmount']; | ||
$model->bonusAmount = $data['bonusAmount']; | ||
$model->paidAmount = $data['paidAmount']; | ||
$model->taxBaseAmount = $data['taxBaseAmount']; | ||
$model->chargeDate = $data['chargeDate'] ? new \DateTimeImmutable($data['chargeDate']) : null; | ||
$model->dueDate = $data['dueDate'] ? new \DateTimeImmutable($data['dueDate']) : null; | ||
$model->oktmo = $data['oktmo']; | ||
$model->regionName = $data['regionName']; | ||
$model->kbk = $data['kbk']; | ||
$model->taxOrganCode = $data['taxOrganCode']; | ||
$model->type = $data['type']; | ||
$model->krsbTaxChargeId = $data['krsbTaxChargeId']; | ||
$model->receiptCount = $data['receiptCount']; | ||
|
||
return $model; | ||
} | ||
|
||
public function getPaidAmount(): float | ||
{ | ||
return $this->paidAmount; | ||
} | ||
|
||
public function getBonusAmount(): float | ||
{ | ||
return $this->bonusAmount; | ||
} | ||
|
||
public function getTaxAmount(): float | ||
{ | ||
return $this->taxAmount; | ||
} | ||
|
||
public function getTaxPeriodId(): int | ||
{ | ||
return $this->taxPeriodId; | ||
} | ||
|
||
public function getOktmo(): string | ||
{ | ||
return $this->oktmo; | ||
} | ||
|
||
public function getRegionName(): string | ||
{ | ||
return $this->regionName; | ||
} | ||
|
||
public function getKbk(): string | ||
{ | ||
return $this->kbk; | ||
} | ||
|
||
public function getTaxOrganCode(): string | ||
{ | ||
return $this->taxOrganCode; | ||
} | ||
|
||
public function getKrsbTaxChargeId(): int | ||
{ | ||
return $this->krsbTaxChargeId; | ||
} | ||
|
||
public function getReceiptCount(): int | ||
{ | ||
return $this->receiptCount; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getChargeDate(): ?\DateTimeImmutable | ||
{ | ||
return $this->chargeDate; | ||
} | ||
|
||
public function getDueDate(): ?\DateTimeImmutable | ||
{ | ||
return $this->dueDate; | ||
} | ||
|
||
public function getTaxBaseAmount(): ?float | ||
{ | ||
return $this->taxBaseAmount; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Shoman4eg\Nalog\Model\Tax; | ||
|
||
use Shoman4eg\Nalog\Model\AbstractCollection; | ||
use Shoman4eg\Nalog\Model\CreatableFromArray; | ||
|
||
/** | ||
* @author Artem Dubinin <artem@dubinin.me> | ||
* | ||
* @extends AbstractCollection<History> | ||
*/ | ||
final class HistoryRecords extends AbstractCollection implements CreatableFromArray | ||
{ | ||
private function __construct() {} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public static function createFromArray(array $data): self | ||
{ | ||
$items = array_map(static fn (array $record) => History::createFromArray($record), $data['records']); | ||
|
||
$model = new self(); | ||
$model->setItems($items); | ||
|
||
return $model; | ||
} | ||
} |
Oops, something went wrong.