*/ public array $products = []; /** @var array */ public array $prices = []; /** @var array */ public array $archived = []; /** Idempotency key → the id first returned for it. @var array */ public array $keys = []; public function isConfigured(): bool { return $this->configured; } public function createProduct(string $name, array $metadata = [], ?string $idempotencyKey = null): string { // Replays the first answer for a repeated key, as Stripe does. if ($idempotencyKey !== null && isset($this->keys[$idempotencyKey])) { return $this->keys[$idempotencyKey]; } $id = 'prod_'.substr(sha1($name.count($this->products)), 0, 12); $this->products[$id] = ['name' => $name, 'metadata' => $metadata]; if ($idempotencyKey !== null) { $this->keys[$idempotencyKey] = $id; } return $id; } public function createPrice( string $productId, int $amountCents, string $currency, string $interval, array $metadata = [], ?string $idempotencyKey = null, ): string { if ($idempotencyKey !== null && isset($this->keys[$idempotencyKey])) { return $this->keys[$idempotencyKey]; } $id = 'price_'.substr(sha1($productId.$amountCents.$interval.count($this->prices)), 0, 12); $this->prices[$id] = [ 'product' => $productId, 'amount' => $amountCents, 'currency' => $currency, 'interval' => $interval, 'metadata' => $metadata, ]; if ($idempotencyKey !== null) { $this->keys[$idempotencyKey] = $id; } return $id; } public function archivePrice(string $priceId): void { $this->archived[] = $priceId; } }