Skip to content

Commit

Permalink
Improve Proforma invoice creation return types and series config
Browse files Browse the repository at this point in the history
The commit introduces a new use statement for CreateProformaInvoiceResponse process and changes return types in ProformaEndpoint class. It also updates the seriesName config reference in the ProformaInvoice constructor and adds a new file for handling API responses. These changes ensure a clearly defined response type when creating a Proforma invoice and proper configuration for its series name.
  • Loading branch information
ag84ark committed Jan 27, 2024
1 parent 413b7d1 commit cf35495
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
65 changes: 65 additions & 0 deletions src/ApiResponse/CreateProformaInvoiceResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Ag84ark\SmartBill\ApiResponse;

use Illuminate\Contracts\Support\Arrayable;

class CreateProformaInvoiceResponse implements Arrayable
{
private string $errorText = '';
private string $message = '';

private string $number = '';

private string $series = '';

private string $url = '';

public static function fromArray(array $data): CreateProformaInvoiceResponse
{
$invoiceResponse = new CreateProformaInvoiceResponse();
$invoiceResponse->errorText = $data['errorText'];
$invoiceResponse->message = $data['message'];
$invoiceResponse->number = $data['number'];
$invoiceResponse->series = $data['series'];
$invoiceResponse->url = $data['url'];

return $invoiceResponse;
}

public function getErrorText(): string
{
return $this->errorText;
}

public function getMessage(): string
{
return $this->message;
}

public function getNumber(): string
{
return $this->number;
}

public function getSeries(): string
{
return $this->series;
}

public function getUrl(): string
{
return $this->url;
}

public function toArray(): array
{
return [
'errorText' => $this->errorText,
'message' => $this->message,
'number' => $this->number,
'series' => $this->series,
'url' => $this->url,
];
}
}
7 changes: 4 additions & 3 deletions src/Endpoints/ProformaEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ag84ark\SmartBill\Endpoints;

use Ag84ark\SmartBill\ApiResponse\CreateProformaInvoiceResponse;
use Ag84ark\SmartBill\Resources\ProformaInvoice;
use Ag84ark\SmartBill\SmartBillCloudRestClient;

Expand All @@ -25,7 +26,7 @@ public function getPDFProforma($number)
return $this->rest_read($url, 'Accept: application/octet-stream');
}

public function createProforma(ProformaInvoice $invoice)
public function createProforma(ProformaInvoice $invoice): CreateProformaInvoiceResponse
{
return $this->createProformaFromArray($invoice->toArray());
}
Expand Down Expand Up @@ -58,9 +59,9 @@ public function getStatusProforma($number)
return $this->rest_read($url);
}

public function createProformaFromArray(array $data)
public function createProformaFromArray(array $data): CreateProformaInvoiceResponse
{
return $this->rest_create(self::PROFORMA_URL, $data);
return CreateProformaInvoiceResponse::fromArray($this->rest_create(self::PROFORMA_URL, $data));
}

public function setSeriesName(string $seriesName): void
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/ProformaInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ProformaInvoice
public function __construct()
{
$this->companyVatCode = config('smartbill.vatCode');
$this->seriesName = config('smartbill.invoiceSeries');
$this->seriesName = config('smartbill.proformaSeries');
$this->dueDate = date('Y-m-d', time() + config('smartbill.defaultDueDays') * 86400);
$this->products = collect();
$this->issueDate = date('Y-m-d');
Expand Down

0 comments on commit cf35495

Please sign in to comment.