Skip to content

Commit

Permalink
Add InquiryByUid
Browse files Browse the repository at this point in the history
  • Loading branch information
kiankamgar committed Apr 13, 2024
1 parent 70a971e commit 1036e53
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Consts/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class Url
protected const FISCAL_INFORMATION_URL = self::BASE_URL . 'fiscal-information';
protected const TAX_PAYER_URL = self::BASE_URL . 'taxpayer';
protected const INQUIRY_BY_REFERENCE_ID_URL = self::BASE_URL . 'inquiry-by-reference-id';
protected const INQUIRY_BY_UID_URL = self::BASE_URL . 'inquiry-by-uid';
}
16 changes: 13 additions & 3 deletions src/Moadian.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use KianKamgar\MoadianPhp\Models\TaxPayerModel;
use KianKamgar\MoadianPhp\Services\FiscalInformation;
use KianKamgar\MoadianPhp\Services\InquiryByReferenceId;
use KianKamgar\MoadianPhp\Services\InquiryByUid;
use KianKamgar\MoadianPhp\Services\RandomChallenge;
use KianKamgar\MoadianPhp\Services\ServerInformation;
use KianKamgar\MoadianPhp\Services\SignNonce;
Expand All @@ -29,7 +30,7 @@ class Moadian
public function __construct(
private string $privateKeyPath,
private string $certificatePath,
private string $clientId,
private string $memoryId,
private string $economicCode,
)
{
Expand All @@ -50,7 +51,7 @@ public function getServerInformation(): ServerInformationModel
*/
public function getFiscalInformation(): FiscalInformationModel
{
return (new FiscalInformation($this->clientId))->request($this->getToken());
return (new FiscalInformation($this->memoryId))->request($this->getToken());
}

/**
Expand All @@ -70,6 +71,15 @@ public function getInquiryByReferenceIds(array $referenceIds, ?DateTime $start =
->request($this->getToken());
}

/**
* @throws GuzzleException
*/
public function getInquiryByUid(array $uidList, string $memoryId, ?DateTime $start = null, ?DateTime $end = null): InquiryResponseModel
{
return (new InquiryByUid($uidList, $memoryId, $start, $end))
->request($this->getToken());
}

/**
* @throws GuzzleException
* @throws Exception
Expand All @@ -81,7 +91,7 @@ private function getToken(): string
$this->privateKey,
$this->certificate,
$randomChallenge->getNonce(),
$this->clientId
$this->memoryId
);

return $signNonce->getToken();
Expand Down
47 changes: 47 additions & 0 deletions src/Services/InquiryByUid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace KianKamgar\MoadianPhp\Services;

use DateTime;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Query;
use KianKamgar\MoadianPhp\Consts\Url;
use KianKamgar\MoadianPhp\Helpers\InquiryHelper;
use KianKamgar\MoadianPhp\Helpers\RequestHelper;
use KianKamgar\MoadianPhp\Models\InquiryResponseModel;

class InquiryByUid extends Url
{
public function __construct(
private array $uidList,
private string $fiscalId,
private ?DateTime $start = null,
private ?DateTime $end = null,
)
{}

/**
* @throws GuzzleException
*/
public function request(string $token): InquiryResponseModel
{
$data = [
'uidList' => $this->uidList,
'fiscalId' => $this->fiscalId
];

if (!empty($this->start)) {

$data['start'] = InquiryHelper::getFormattedDate($this->start);
}

if (!empty($this->end)) {

$data['end'] = InquiryHelper::getFormattedDate($this->end);
}

return (new RequestHelper(self::INQUIRY_BY_UID_URL, InquiryResponseModel::class))
->setToken($token)
->get(Query::build($data));
}
}

0 comments on commit 1036e53

Please sign in to comment.