OrderTransactionResponseData.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Data\Pagarme\Response\OrderResponseData\OrderChargeResponseData;
  3. use App\Data\Pagarme\PagarmeResponseData;
  4. final readonly class OrderTransactionResponseData extends PagarmeResponseData
  5. {
  6. public function __construct(
  7. public ?string $id,
  8. public ?string $status,
  9. public ?int $amount,
  10. public ?string $createdAt,
  11. public ?string $acquirerMessage,
  12. public array $gatewayResponse,
  13. ) {}
  14. public static function fromArray(array $payload): static
  15. {
  16. return new self(
  17. id: static::arrString($payload, 'id'),
  18. status: static::arrString($payload, 'status'),
  19. amount: static::arrInt($payload, 'amount'),
  20. createdAt: static::arrString($payload, 'created_at'),
  21. acquirerMessage: static::arrString($payload, 'acquirer_message'),
  22. gatewayResponse: static::arrArray($payload, 'gateway_response'),
  23. );
  24. }
  25. public function toArray(): array
  26. {
  27. return [
  28. 'id' => $this->id,
  29. 'status' => $this->status,
  30. 'amount' => $this->amount,
  31. 'created_at' => $this->createdAt,
  32. 'acquirer_message' => $this->acquirerMessage,
  33. 'gateway_response' => $this->gatewayResponse,
  34. ];
  35. }
  36. }