Secret.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Apps;
  4. /**
  5. * Secret Store is an API that allows Stripe Apps developers to securely persist secrets for use by UI Extensions and app backends.
  6. *
  7. * The primary resource in Secret Store is a <code>secret</code>. Other apps can't view secrets created by an app. Additionally, secrets are scoped to provide further permission control.
  8. *
  9. * All Dashboard users and the app backend share <code>account</code> scoped secrets. Use the <code>account</code> scope for secrets that don't change per-user, like a third-party API key.
  10. *
  11. * A <code>user</code> scoped secret is accessible by the app backend and one specific Dashboard user. Use the <code>user</code> scope for per-user secrets like per-user OAuth tokens, where different users might have different permissions.
  12. *
  13. * Related guide: <a href="https://stripe.com/docs/stripe-apps/store-auth-data-custom-objects">Store data between page reloads</a>
  14. *
  15. * @property string $id Unique identifier for the object.
  16. * @property string $object String representing the object's type. Objects of the same type share the same value.
  17. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  18. * @property null|bool $deleted If true, indicates that this secret has been deleted
  19. * @property null|int $expires_at The Unix timestamp for the expiry time of the secret, after which the secret deletes.
  20. * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
  21. * @property string $name A name for the secret that's unique within the scope.
  22. * @property null|string $payload The plaintext secret value to be stored.
  23. * @property \Stripe\StripeObject $scope
  24. */
  25. class Secret extends \Stripe\ApiResource
  26. {
  27. const OBJECT_NAME = 'apps.secret';
  28. /**
  29. * Create or replace a secret in the secret store.
  30. *
  31. * @param null|array $params
  32. * @param null|array|string $options
  33. *
  34. * @throws \Stripe\Exception\ApiErrorException if the request fails
  35. *
  36. * @return \Stripe\Apps\Secret the created resource
  37. */
  38. public static function create($params = null, $options = null)
  39. {
  40. self::_validateParams($params);
  41. $url = static::classUrl();
  42. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  43. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  44. $obj->setLastResponse($response);
  45. return $obj;
  46. }
  47. /**
  48. * List all secrets stored on the given scope.
  49. *
  50. * @param null|array $params
  51. * @param null|array|string $opts
  52. *
  53. * @throws \Stripe\Exception\ApiErrorException if the request fails
  54. *
  55. * @return \Stripe\Collection<\Stripe\Apps\Secret> of ApiResources
  56. */
  57. public static function all($params = null, $opts = null)
  58. {
  59. $url = static::classUrl();
  60. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  61. }
  62. /**
  63. * @param null|array $params
  64. * @param null|array|string $opts
  65. *
  66. * @throws \Stripe\Exception\ApiErrorException if the request fails
  67. *
  68. * @return \Stripe\Apps\Secret the deleted secret
  69. */
  70. public static function deleteWhere($params = null, $opts = null)
  71. {
  72. $url = static::classUrl() . '/delete';
  73. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  74. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  75. $obj->setLastResponse($response);
  76. return $obj;
  77. }
  78. /**
  79. * @param null|array $params
  80. * @param null|array|string $opts
  81. *
  82. * @throws \Stripe\Exception\ApiErrorException if the request fails
  83. *
  84. * @return \Stripe\Apps\Secret the finded secret
  85. */
  86. public static function find($params = null, $opts = null)
  87. {
  88. $url = static::classUrl() . '/find';
  89. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  90. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  91. $obj->setLastResponse($response);
  92. return $obj;
  93. }
  94. }