Skip to content

Commit

Permalink
Added articles list to invoice rows converter
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoffer-webbhuset committed May 12, 2021
1 parent 057ac8a commit a7a681f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 23 deletions.
16 changes: 6 additions & 10 deletions src/Invoice/Administration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public function __construct(AdapterInterface $adapter)
public function partCreditInvoice(
$invoiceNo,
\Webbhuset\CollectorPaymentSDK\Invoice\Article\ArticleList $articleList,
$correlationId = 0): array
{

$correlationId = 0
): array {
$data = [
'CorrelationId' => $correlationId,
'CreditDate' => date("Y-m-d"),
Expand All @@ -45,8 +44,8 @@ public function partCreditInvoice(
public function partActivateInvoice(
$invoiceNo,
\Webbhuset\CollectorPaymentSDK\Invoice\Article\ArticleList $articleList,
$correlationId = 0): array
{
$correlationId = 0
): array {
$data = [
'CorrelationId' => $correlationId,
'InvoiceNo' => $invoiceNo,
Expand All @@ -62,8 +61,8 @@ public function partActivateInvoice(
public function adjustInvoice(
$invoiceNo,
$invoiceRows,
$correlationId = 0): array
{
$correlationId = 0
): array {
$data = [
'CorrelationId' => $correlationId,
'InvoiceNo' => $invoiceNo,
Expand Down Expand Up @@ -96,7 +95,6 @@ public function cancelInvoice($invoiceNo, $correlationId = 0): array
return $response;
}


public function creditInvoice($invoiceNo, $correlationId = 0): array
{
$data = [
Expand All @@ -109,7 +107,6 @@ public function creditInvoice($invoiceNo, $correlationId = 0): array
return $response;
}


public function getInvoiceInformation($invoiceNo, $clientIpAddress, $correlationId = 0): array
{
$data = [
Expand All @@ -126,5 +123,4 @@ public function getInvoiceInformation($invoiceNo, $clientIpAddress, $correlation

return $response;
}

}
34 changes: 32 additions & 2 deletions src/Invoice/Article/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@

namespace Webbhuset\CollectorPaymentSDK\Invoice\Article;

use Webbhuset\CollectorPaymentSDK\Adapter\AdapterInterface as AdapterInterface;
use Webbhuset\CollectorPaymentSDK\Invoice\Rows\InvoiceRow;

class Article
{
protected $articleId;
protected $description;
protected $quantity;
protected $sku;
protected $unitPrice;
protected $vat;

public function __construct(
string $articleId,
string $description,
int $quantity,
string $sku=""
string $sku="",
float $unitPrice = 0,
float $vat = 0
) {
$this->articleId = $articleId;
$this->description = $description;
$this->quantity = $quantity;
$this->sku = $sku;
$this->unitPrice = $unitPrice;
$this->vat = $vat;
}

/**
Expand Down Expand Up @@ -87,6 +93,30 @@ public function setQuantity(int $quantity)
$this->quantity = $quantity;
}

public function toInvoiceRow()
{
return new InvoiceRow(
(string) $this->articleId,
(string) $this->description,
(int) $this->quantity,
(float) $this->unitPrice,
(float) $this->vat
);
}


public function toAdjustInvoiceRow()
{
return new InvoiceRow(
(string) $this->articleId,
(string) $this->description,
(int) $this->quantity,
(float) $this->unitPrice * (-1),
(float) $this->vat
);
}


public function toArray()
{
return [
Expand Down
20 changes: 14 additions & 6 deletions src/Invoice/Article/ArticleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Webbhuset\CollectorPaymentSDK\Invoice\Article;

use Webbhuset\CollectorPaymentSDK\Adapter\AdapterInterface as AdapterInterface;
use Webbhuset\CollectorPaymentSDK\Invoice\Rows\InvoiceRows;

class ArticleList
{
protected $articles = [];

public function __construct()
{

}

public function addArticle($article)
Expand All @@ -22,7 +21,6 @@ public function getArticleBySku($sku)
{
foreach ($this->articles as $article) {
if ($sku == $article->getSku()) {

return $article;
}
}
Expand All @@ -34,8 +32,7 @@ public function removeDecimalRounding()
{
$result = [];
foreach ($this->articles as $article) {
if ("Currency rounding" != $article->getSku())
{
if (\Webbhuset\CollectorCheckout\Gateway\Config::CURRENCY_ROUNDING_SKU != $article->getSku()) {
$result[] = $article;
}
}
Expand All @@ -45,14 +42,25 @@ public function removeDecimalRounding()

public function getDecimalRounding()
{
return $this->getArticleBySku("Currency rounding");
return $this->getArticleBySku(\Webbhuset\CollectorCheckout\Gateway\Config::CURRENCY_ROUNDING_SKU);
}

public function getShippingArticle()
{
return $this->getArticleBySku("");
}

public function getInvoiceRows():InvoiceRows
{
$invoiceRows = new InvoiceRows();
/** @var Article $article */
foreach ($this->articles as $article) {
$invoiceRows->addInvoiceRow($article->toAdjustInvoiceRow());
}

return $invoiceRows;
}

public function getArticleList()
{
$result = [];
Expand Down
10 changes: 5 additions & 5 deletions src/Invoice/Rows/InvoiceRows.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ class InvoiceRows
{
protected $invoiceRows = [];

public function __construct()
{

}

public function addInvoiceRow(\Webbhuset\CollectorPaymentSDK\Invoice\Rows\InvoiceRow $invoiceRow)
{
$this->invoiceRows[] = $invoiceRow;
Expand All @@ -27,4 +22,9 @@ public function getInvoiceRows()

return $result;
}

public function toArray()
{
return $this->getInvoiceRows();
}
}

0 comments on commit a7a681f

Please sign in to comment.