Skip to content

Commit 7301ba7

Browse files
HP-2883: Implement Business Central bills import service (#114)
* HP-2883: Implement Business Central bills import service * HP-2883: added support reversesId to Bill * HQD-21: fixing "Implicitly marking parameters as nullable is deprecated, the explicit nullable type must be used instead" deprecation warning in Bill * HQD-21: fixing "Implicitly marking parameters as nullable is deprecated, the explicit nullable type must be used instead" deprecation warning in batch of classes * HQD-21: fixing "Implicitly marking parameters as nullable is deprecated, the explicit nullable type must be used instead" deprecation warning in SinglePrice * HQD-21: fixing "Implicitly marking parameters as nullable is deprecated, the explicit nullable type must be used instead" deprecation warning in BillSource * HQD-21: fixing "Optional parameter $plan declared before required parameter $price is implicitly treated as a required parameter" deprecation warning in SinglePrice * HQD-129: thightly refectored BillReversesId
1 parent 3c954e4 commit 7301ba7

13 files changed

Lines changed: 155 additions & 10 deletions

File tree

src/bill/Bill.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ class Bill implements BillInterface
6464
/** @var UsageInterval */
6565
protected $usageInterval;
6666

67+
/** @var BillSource|null */
68+
protected $source;
69+
70+
/** @var BillTxn|null */
71+
protected $txn;
72+
73+
/** @var BillReversesId|null */
74+
protected $reversesId;
75+
6776
/**
6877
* @param int|string $id
6978
*/
@@ -77,7 +86,10 @@ public function __construct(
7786
?TargetInterface $target = null,
7887
?PlanInterface $plan = null,
7988
array $charges = [],
80-
?BillState $state = null
89+
?BillState $state = null,
90+
?BillSource $source = null,
91+
?BillTxn $txn = null,
92+
?BillReversesId $reversesId = null,
8193
) {
8294
$this->type = $type;
8395
$this->time = $time;
@@ -88,6 +100,9 @@ public function __construct(
88100
$this->plan = $plan;
89101
$this->charges = $charges;
90102
$this->state = $state;
103+
$this->source = $source;
104+
$this->txn = $txn;
105+
$this->reversesId = $reversesId;
91106
}
92107

93108
/**
@@ -241,6 +256,16 @@ public function getComment()
241256
return $this->comment;
242257
}
243258

259+
public function getSource(): ?BillSource
260+
{
261+
return $this->source;
262+
}
263+
264+
public function getTxn(): ?BillTxn
265+
{
266+
return $this->txn;
267+
}
268+
244269
public function setComment(string $comment)
245270
{
246271
$this->comment = $comment;
@@ -255,4 +280,18 @@ public function setUsageInterval(UsageInterval $usageInterval): void
255280
{
256281
$this->usageInterval = $usageInterval;
257282
}
283+
284+
public function getReversesId(): ?BillReversesId
285+
{
286+
return $this->reversesId;
287+
}
288+
289+
/**
290+
* @param BillReversesId|null $reversesId
291+
* @return void
292+
*/
293+
public function setReversesId($reversesId): void
294+
{
295+
$this->reversesId = $reversesId;
296+
}
258297
}

src/bill/BillInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,10 @@ public function getCharges();
5757
public function getUsageInterval(): UsageInterval;
5858

5959
public function setUsageInterval(UsageInterval $usageInterval): void;
60+
61+
public function getSource(): ?BillSource;
62+
63+
public function getTxn(): ?BillTxn;
64+
65+
public function getReversesId(): ?BillReversesId;
6066
}

src/bill/BillReversesId.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace hiqdev\php\billing\bill;
6+
7+
readonly class BillReversesId
8+
{
9+
public function __construct(private ?int $value = null)
10+
{
11+
}
12+
13+
public function getId(): ?int
14+
{
15+
return $this->value;
16+
}
17+
18+
public static function fromInt(int $id): self
19+
{
20+
return new self($id);
21+
}
22+
}

src/bill/BillSource.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace hiqdev\php\billing\bill;
6+
7+
class BillSource
8+
{
9+
/** @var int|string|null */
10+
protected $id;
11+
12+
protected ?string $name = null;
13+
14+
public function __construct($id = null, ?string $name = null)
15+
{
16+
$this->id = $id;
17+
$this->name = $name;
18+
}
19+
20+
public function getId()
21+
{
22+
return $this->id;
23+
}
24+
25+
public function getName(): ?string
26+
{
27+
return $this->name;
28+
}
29+
}

src/bill/BillTxn.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace hiqdev\php\billing\bill;
6+
7+
/**
8+
* BillTxn
9+
*
10+
* Represents an immutable external payment transaction identifier.
11+
*
12+
* A TransactionId uniquely identifies a financial transaction
13+
* as defined by an external payment or accounting system
14+
* (e.g. Business Central, merchant gateways, banks).
15+
*
16+
* This value:
17+
* - Is created by an external system, never generated internally
18+
* - Is stable across retries, webhooks, and re-imports
19+
* - Is used for idempotency and reconciliation
20+
* - Has meaning outside of the database and application boundaries
21+
*
22+
* Uniqueness is guaranteed only within the scope of a source system
23+
* (see Source / external system).
24+
*
25+
* Typical examples:
26+
* - UUIDs
27+
* - Gateway transaction references
28+
* - Accounting document numbers
29+
*/
30+
class BillTxn
31+
{
32+
/** @var int|string|null */
33+
protected $value;
34+
35+
public function __construct($txn = null)
36+
{
37+
$this->value = $txn;
38+
}
39+
40+
public function getValue()
41+
{
42+
return $this->value;
43+
}
44+
45+
public static function fromString(string $txn): self
46+
{
47+
return new self($txn);
48+
}
49+
}

src/charge/modifiers/Installment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function buildPrice(Money $sum)
4141
$target = $this->getTarget();
4242
$prepaid = Quantity::create('items', 0);
4343

44-
return new SinglePrice(null, $type, $target, null, $prepaid, $sum);
44+
return new SinglePrice(null, $type, $target, $prepaid, $sum);
4545
}
4646

4747
public function getType()

src/price/PriceFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function createRatePrice(PriceCreationDto $dto)
9191

9292
public function createSinglePrice(PriceCreationDto $dto)
9393
{
94-
return new SinglePrice($dto->id, $dto->type, $dto->target, $dto->plan, $dto->prepaid, $dto->price);
94+
return new SinglePrice($dto->id, $dto->type, $dto->target, $dto->prepaid, $dto->price, $dto->plan);
9595
}
9696

9797
public function createProgressivePrice(PriceCreationDto $dto): ProgressivePrice

src/price/SinglePrice.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function __construct(
3636
$id,
3737
TypeInterface $type,
3838
TargetInterface $target,
39-
?PlanInterface $plan = null,
4039
?QuantityInterface $prepaid = null,
41-
?Money $price = null
40+
?Money $price = null,
41+
?PlanInterface $plan = null,
4242
) {
4343
parent::__construct($id, $type, $target, $plan);
4444
$this->prepaid = $prepaid;

tests/behat/bootstrap/FeatureContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function priceIs($target, $type, $sum, $currency, $unit, $quantity = 0)
9797
$target = new Target(Target::ANY, $target);
9898
$quantity = Quantity::create($unit, $quantity);
9999
$sum = $this->moneyParser->parse($sum, new Currency($currency));
100-
$this->setPrice(new SinglePrice(null, $type, $target, null, $quantity, $sum));
100+
$this->setPrice(new SinglePrice(null, $type, $target, $quantity, $sum));
101101
}
102102

103103
protected array $progressivePrice = [];

tests/unit/action/ActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function setUp(): void
8787
$this->target = new Target(2, 'server');
8888
$this->prepaid = Quantity::gigabyte(1);
8989
$this->money = Money::USD(10000);
90-
$this->price = new SinglePrice(5, $this->type, $this->target, null, $this->prepaid, $this->money);
90+
$this->price = new SinglePrice(5, $this->type, $this->target, $this->prepaid, $this->money);
9191
$this->customer = new Customer(2, 'client');
9292
$this->time = new DateTimeImmutable('now');
9393
$this->generalizer = new Generalizer();

0 commit comments

Comments
 (0)