Skip to content

Commit

Permalink
Add invoice builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kiankamgar committed Apr 14, 2024
1 parent ed94248 commit 9bab155
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 509 deletions.
49 changes: 49 additions & 0 deletions src/Invoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace KianKamgar\MoadianPhp;

use KianKamgar\MoadianPhp\Models\Invoice\InvoiceBody;
use KianKamgar\MoadianPhp\Models\Invoice\InvoiceHeader;
use KianKamgar\MoadianPhp\Models\Invoice\InvoiceModel;
use KianKamgar\MoadianPhp\Models\Invoice\InvoicePayment;

class Invoice
{
private array $header;
private array $body = [];
private array $payments = [];

public function header(string $memoryId): InvoiceHeader
{
$header = (new InvoiceHeader())
->setMemoryId($memoryId);
$this->header[] = $header;

return $header;
}

public function body(): InvoiceBody
{
$body = new InvoiceBody();
$this->body[] = $body;

return $body;
}

public function payment(): InvoicePayment
{
$payment = new InvoicePayment();
$this->payments[] = $payment;

return $payment;
}

public function build(): array
{
return (new InvoiceModel())
->setHeader($this->header[0]->build())
->setBody($this->body)
->setPayments($this->payments)
->getInvoice();
}
}
16 changes: 5 additions & 11 deletions src/Moadian.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use KianKamgar\MoadianPhp\Helpers\SignHelper;
use KianKamgar\MoadianPhp\Models\FiscalInformationResponse;
use KianKamgar\MoadianPhp\Models\InquiryArrayResponse;
use KianKamgar\MoadianPhp\Models\Invoice\Invoice;
use KianKamgar\MoadianPhp\Models\Invoice\InvoiceHeader;
use KianKamgar\MoadianPhp\Models\RandomChallengeResponse;
use KianKamgar\MoadianPhp\Models\SendInvoiceResponse;
use KianKamgar\MoadianPhp\Models\SendInvoiceResultResponse;
Expand Down Expand Up @@ -103,15 +101,6 @@ public function getInquiryByTime(int $pageNumber = 1, int $pageSize = 10, ?strin
->request($this->getToken());
}

public function createInvoice(InvoiceHeader $header, array $body, array $payments = []): array
{
return (new Invoice())
->setHeader($header->setMemoryId($this->memoryId)->getHeader())
->setBody($body)
->setPayments($payments)
->getInvoice();
}

/**
* @throws GuzzleException
*/
Expand Down Expand Up @@ -164,6 +153,11 @@ public function arrayResponse(bool $arrayResponse = true): Moadian
return $this;
}

public function getMemoryId(): string
{
return $this->memoryId;
}

/**
* @throws GuzzleException
*/
Expand Down
Loading

0 comments on commit 9bab155

Please sign in to comment.