-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryReserver.php
More file actions
38 lines (32 loc) · 1.04 KB
/
Copy pathInventoryReserver.php
File metadata and controls
38 lines (32 loc) · 1.04 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
<?php
declare(strict_types=1);
namespace Be\Pattern\OrderProcessing\Reason;
use Be\Pattern\OrderProcessing\Moment\Potential\InventoryReservation;
/**
* Inventory Reserver - Reason (stateless gateway)
*
* Creates InventoryReservation moments that can be realized.
*/
final class InventoryReserver implements InventoryReserverInterface
{
public function lock(string $warehouseId, string $productId, int $quantity): InventoryReservation
{
// Create provisional reservation ID
$reservationId = sprintf(
'RSV-%s-%s-%d',
substr($warehouseId, 3, 5),
date('YmdHis'),
random_int(1000, 9999)
);
// Return Moment with realize callback
return new InventoryReservation(
$reservationId,
fn () => $this->confirm($reservationId),
);
}
private function confirm(string $reservationId): void
{
// External system call to confirm reservation
// In production: $this->api->confirmReservation($reservationId);
}
}