Skip to content

Commit 02617b7

Browse files
committedJun 4, 2024
Merge branch 'sale-data-type' of https://github.com/bladeroot/php-billing into sale-data-type
2 parents 1d91fdd + dfeb822 commit 02617b7

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed
 

‎src/sale/Sale.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use hiqdev\php\billing\Exception\InvariantException;
1818
use hiqdev\php\billing\plan\PlanInterface;
1919
use hiqdev\php\billing\target\TargetInterface;
20+
use yii\helpers\Json;
2021

2122
/**
2223
* Sale.
@@ -52,15 +53,15 @@ class Sale implements SaleInterface
5253

5354
protected ?DateTimeImmutable $closeTime = null;
5455

55-
protected ?array $data = null;
56+
protected ?string $data = null;
5657

5758
public function __construct(
5859
$id,
5960
TargetInterface $target,
6061
CustomerInterface $customer,
6162
?PlanInterface $plan = null,
6263
?DateTimeImmutable $time = null,
63-
?array $data = null,
64+
?string $data = null,
6465
) {
6566
$this->id = $id;
6667
$this->target = $target;
@@ -129,9 +130,9 @@ public function setId($id)
129130
$this->id = $id;
130131
}
131132

132-
public function getData()
133+
public function getData(): ?array
133134
{
134-
return $this->data;
135+
return !empty($this->data) ? Json::decode($this->data, true) : null;
135136
}
136137

137138
public function jsonSerialize(): array

‎src/sale/SaleCreationDto.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ class SaleCreationDto
2828
public $closeTime;
2929

3030
public $data;
31+
32+
public $reason;
3133
}

‎src/sale/SaleFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SaleFactory implements SaleFactoryInterface
2323
*/
2424
public function create(SaleCreationDto $dto)
2525
{
26-
$sale = new Sale($dto->id, $dto->target, $dto->customer, $dto->plan, $dto->time);
26+
$sale = new Sale($dto->id, $dto->target, $dto->customer, $dto->plan, $dto->time, $dto->data);
2727

2828
if ($dto->closeTime !== null) {
2929
$sale->close($dto->closeTime);

‎src/sale/SaleInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public function getTime();
6262
public function getCloseTime(): ?DateTimeImmutable;
6363

6464
/**
65-
* @return string|array|null
65+
* @return array|null
6666
*/
67-
public function getData();
67+
public function getData(): ?array;
6868

6969
/**
7070
* @param DateTimeImmutable $time

0 commit comments

Comments
 (0)