PagarmeOrderTransactionResponseData.php 1.3 KB

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