| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | namespace NxSys\Library\Clients\Brex\API\Expenses\Endpoint; |
| 12: | |
| 13: | class ReceiptUpload extends \NxSys\Library\Clients\Brex\API\Expenses\Runtime\Client\BaseEndpoint implements \NxSys\Library\Clients\Brex\API\Expenses\Runtime\Client\Endpoint |
| 14: | { |
| 15: | use \NxSys\Library\Clients\Brex\API\Expenses\Runtime\Client\EndpointTrait; |
| 16: | protected $expense_id; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | public function __construct(string $expenseId, \NxSys\Library\Clients\Brex\API\Expenses\Model\ReceiptUploadRequest $requestBody) |
| 24: | { |
| 25: | $this->expense_id = $expenseId; |
| 26: | $this->body = $requestBody; |
| 27: | } |
| 28: | |
| 29: | public function getMethod(): string |
| 30: | { |
| 31: | return 'POST'; |
| 32: | } |
| 33: | |
| 34: | public function getUri(): string |
| 35: | { |
| 36: | return str_replace(['{expense_id}'], [$this->expense_id], '/v1/expenses/card/{expense_id}/receipt_upload'); |
| 37: | } |
| 38: | |
| 39: | public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array |
| 40: | { |
| 41: | if ($this->body instanceof \NxSys\Library\Clients\Brex\API\Expenses\Model\ReceiptUploadRequest) { |
| 42: | return [['Content-Type' => ['application/json']], $serializer->serialize($this->body, 'json')]; |
| 43: | } |
| 44: | |
| 45: | return [[], null]; |
| 46: | } |
| 47: | |
| 48: | public function getExtraHeaders(): array |
| 49: | { |
| 50: | return ['Accept' => ['application/json']]; |
| 51: | } |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null) |
| 64: | { |
| 65: | $status = $response->getStatusCode(); |
| 66: | $body = (string) $response->getBody(); |
| 67: | if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) { |
| 68: | return $serializer->deserialize($body, 'NxSys\\Library\\Clients\\Brex\\API\\Expenses\\Model\\CreateAsyncFileUploadResponse', 'json'); |
| 69: | } |
| 70: | if (400 === $status) { |
| 71: | throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadBadRequestException($response); |
| 72: | } |
| 73: | if (401 === $status) { |
| 74: | throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadUnauthorizedException($response); |
| 75: | } |
| 76: | if (403 === $status) { |
| 77: | throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadForbiddenException($response); |
| 78: | } |
| 79: | if (404 === $status) { |
| 80: | throw new \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadNotFoundException($response); |
| 81: | } |
| 82: | } |
| 83: | |
| 84: | public function getAuthenticationScopes(): array |
| 85: | { |
| 86: | return ['oAuth2ClientCredentials']; |
| 87: | } |
| 88: | } |
| 89: | |