| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Data\Pagarme\Response;
- final readonly class PagarmeCardResponseData
- {
- public function __construct(
- public ?string $id,
- public ?string $firstSixDigits,
- public ?string $lastFourDigits,
- public ?string $brand,
- public ?string $holderName,
- public ?int $expMonth,
- public ?int $expYear,
- public ?string $status,
- public ?string $type,
- public ?string $createdAt = null,
- public ?string $updatedAt = null,
- ) {}
- public function brand(): ?string
- {
- return $this->brand;
- }
- public function id(): ?string
- {
- return $this->id;
- }
- public function lastFourDigits(): ?string
- {
- return $this->lastFourDigits;
- }
- public function requireId(): string
- {
- if (! $this->id) {
- throw new \RuntimeException('Pagar.me card creation returned an empty id.');
- }
- return $this->id;
- }
- //
- public static function fromArray(array $payload): self
- {
- return new self(
- id: $payload['id'] ?? null,
- firstSixDigits: $payload['first_six_digits'] ?? null,
- lastFourDigits: $payload['last_four_digits'] ?? null,
- brand: $payload['brand'] ?? null,
- holderName: $payload['holder_name'] ?? null,
- expMonth: isset($payload['exp_month']) ? (int) $payload['exp_month'] : null,
- expYear: isset($payload['exp_year']) ? (int) $payload['exp_year'] : null,
- status: $payload['status'] ?? null,
- type: $payload['type'] ?? null,
- createdAt: $payload['created_at'] ?? null,
- updatedAt: $payload['updated_at'] ?? null,
- );
- }
- public function toArray(): array
- {
- return [
- 'id' => $this->id,
- 'first_six_digits' => $this->firstSixDigits,
- 'last_four_digits' => $this->lastFourDigits,
- 'brand' => $this->brand,
- 'holder_name' => $this->holderName,
- 'exp_month' => $this->expMonth,
- 'exp_year' => $this->expYear,
- 'status' => $this->status,
- 'type' => $this->type,
- 'created_at' => $this->createdAt,
- 'updated_at' => $this->updatedAt,
- ];
- }
- }
|