1: <?php
2:
3: declare(strict_types=1);
4:
5: /*
6: * This file has been auto generated by Jane,
7: *
8: * Do no edit it directly.
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: The `uri` will be a pre-signed S3 URL allowing you to upload the receipt securely. This URL can only be used for a `PUT` operation and expires 30 minutes after its creation. Once your upload is complete, we will try to match the receipt with existing expenses.
20:
21: Refer to these [docs](https://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html) on how to upload to this pre-signed S3 URL. We highly recommend using one of AWS SDKs if they're available for your language to upload these files.
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: * {@inheritdoc}
55: *
56: * @return \NxSys\Library\Clients\Brex\API\Expenses\Model\CreateAsyncFileUploadResponse|null
57: *
58: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadBadRequestException
59: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadUnauthorizedException
60: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadForbiddenException
61: * @throws \NxSys\Library\Clients\Brex\API\Expenses\Exception\ReceiptUploadNotFoundException
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: