-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderLineData.php
More file actions
55 lines (50 loc) · 1.66 KB
/
Copy pathOrderLineData.php
File metadata and controls
55 lines (50 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace Vatly\API\Types;
use Vatly\API\Resources\OrderLine as ApiOrderLine;
/**
* Data for a single order line from Vatly.
*
* Carries the per-line breakdown so drivers can persist first-class order
* lines and traverse subscription↔orders via the generic
* (`productType`, `productId`) pair. A line links to a subscription when
* `productType === 'subscription'` → `productId` is the `subscription_…` id.
*
* `productType` is carried as the raw API string (no enum) so new backend
* product types flow through without an api-php release.
*
* Money fields (`basePrice`, `total`, `subtotal`) are {@see Money} values
* (decimal-string + currency). Consumers that need integer cents flatten at
* their own persistence edge via {@see Money::toCents()}.
*
* @immutable
*/
class OrderLineData
{
public function __construct(
public string $vatlyId,
public string $description,
public int $quantity,
public Money $basePrice,
public Money $total,
public Money $subtotal,
public ?TaxSummaryCollection $taxSummary = null,
public ?string $productType = null,
public ?string $productId = null,
) {
}
public static function fromApiOrderLine(ApiOrderLine $line): self
{
return new self(
vatlyId: $line->id,
description: $line->description,
quantity: $line->quantity,
basePrice: $line->basePrice,
total: $line->total,
subtotal: $line->subtotal,
taxSummary: $line->taxes,
productType: $line->productType,
productId: $line->productId,
);
}
}