SessionResponseData.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Data\Didit\Session;
  3. use App\Data\Didit\DiditData;
  4. final readonly class SessionResponseData extends DiditData
  5. {
  6. public function __construct(
  7. public string $sessionId,
  8. public string $url,
  9. public ?string $sessionToken = null,
  10. public ?string $workflowId = null,
  11. public ?string $status = null,
  12. public ?string $vendorData = null,
  13. ) {}
  14. public static function fromResponse(array $response): self
  15. {
  16. return new self(
  17. sessionId: (string) data_get($response, 'session_id'),
  18. url: (string) data_get($response, 'url'),
  19. sessionToken: data_get($response, 'session_token'),
  20. workflowId: data_get($response, 'workflow_id'),
  21. status: data_get($response, 'status'),
  22. vendorData: data_get($response, 'vendor_data'),
  23. );
  24. }
  25. public function toArray(): array
  26. {
  27. return [
  28. 'session_id' => $this->sessionId,
  29. 'url' => $this->url,
  30. 'session_token' => $this->sessionToken,
  31. 'workflow_id' => $this->workflowId,
  32. 'status' => $this->status,
  33. 'vendor_data' => $this->vendorData,
  34. ];
  35. }
  36. }