FileService.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. /**
  5. * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  6. * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  7. */
  8. class FileService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of the files that your account has access to. Stripe sorts and
  12. * returns the files by their creation dates, placing the most recently created
  13. * files at the top.
  14. *
  15. * @param null|array $params
  16. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  17. *
  18. * @throws \Stripe\Exception\ApiErrorException if the request fails
  19. *
  20. * @return \Stripe\Collection<\Stripe\File>
  21. */
  22. public function all($params = null, $opts = null)
  23. {
  24. return $this->requestCollection('get', '/v1/files', $params, $opts);
  25. }
  26. /**
  27. * Retrieves the details of an existing file object. After you supply a unique file
  28. * ID, Stripe returns the corresponding file object. Learn how to <a
  29. * href="/docs/file-upload#download-file-contents">access file contents</a>.
  30. *
  31. * @param string $id
  32. * @param null|array $params
  33. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  34. *
  35. * @throws \Stripe\Exception\ApiErrorException if the request fails
  36. *
  37. * @return \Stripe\File
  38. */
  39. public function retrieve($id, $params = null, $opts = null)
  40. {
  41. return $this->request('get', $this->buildPath('/v1/files/%s', $id), $params, $opts);
  42. }
  43. /**
  44. * Create a file.
  45. *
  46. * @param null|array $params
  47. * @param null|array|\Stripe\Util\RequestOptions $opts
  48. *
  49. * @return \Stripe\File
  50. */
  51. public function create($params = null, $opts = null)
  52. {
  53. $opts = \Stripe\Util\RequestOptions::parse($opts);
  54. if (!isset($opts->apiBase)) {
  55. $opts->apiBase = $this->getClient()->getFilesBase();
  56. }
  57. // Manually flatten params, otherwise curl's multipart encoder will
  58. // choke on nested null|arrays.
  59. $flatParams = \array_column(\Stripe\Util\Util::flattenParams($params), 1, 0);
  60. return $this->request('post', '/v1/files', $flatParams, $opts);
  61. }
  62. }