Stripe.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class Stripe.
  5. */
  6. class Stripe
  7. {
  8. /** @var string The Stripe API key to be used for requests. */
  9. public static $apiKey;
  10. /** @var string The Stripe client_id to be used for Connect requests. */
  11. public static $clientId;
  12. /** @var string The base URL for the Stripe API. */
  13. public static $apiBase = 'https://api.stripe.com';
  14. /** @var string The base URL for the OAuth API. */
  15. public static $connectBase = 'https://connect.stripe.com';
  16. /** @var string The base URL for the Stripe API uploads endpoint. */
  17. public static $apiUploadBase = 'https://files.stripe.com';
  18. /** @var null|string The version of the Stripe API to use for requests. */
  19. public static $apiVersion = null;
  20. /** @var null|string The account ID for connected accounts requests. */
  21. public static $accountId = null;
  22. /** @var string Path to the CA bundle used to verify SSL certificates */
  23. public static $caBundlePath = null;
  24. /** @var bool Defaults to true. */
  25. public static $verifySslCerts = true;
  26. /** @var array The application's information (name, version, URL) */
  27. public static $appInfo = null;
  28. /**
  29. * @var null|Util\LoggerInterface the logger to which the library will
  30. * produce messages
  31. */
  32. public static $logger = null;
  33. /** @var int Maximum number of request retries */
  34. public static $maxNetworkRetries = 0;
  35. /** @var bool Whether client telemetry is enabled. Defaults to true. */
  36. public static $enableTelemetry = true;
  37. /** @var float Maximum delay between retries, in seconds */
  38. private static $maxNetworkRetryDelay = 2.0;
  39. /** @var float Maximum delay between retries, in seconds, that will be respected from the Stripe API */
  40. private static $maxRetryAfter = 60.0;
  41. /** @var float Initial delay between retries, in seconds */
  42. private static $initialNetworkRetryDelay = 0.5;
  43. const VERSION = '7.67.0';
  44. /**
  45. * @return string the API key used for requests
  46. */
  47. public static function getApiKey()
  48. {
  49. return self::$apiKey;
  50. }
  51. /**
  52. * @return string the client_id used for Connect requests
  53. */
  54. public static function getClientId()
  55. {
  56. return self::$clientId;
  57. }
  58. /**
  59. * @return Util\LoggerInterface the logger to which the library will
  60. * produce messages
  61. */
  62. public static function getLogger()
  63. {
  64. if (null === self::$logger) {
  65. return new Util\DefaultLogger();
  66. }
  67. return self::$logger;
  68. }
  69. /**
  70. * @param Util\LoggerInterface $logger the logger to which the library
  71. * will produce messages
  72. */
  73. public static function setLogger($logger)
  74. {
  75. self::$logger = $logger;
  76. }
  77. /**
  78. * Sets the API key to be used for requests.
  79. *
  80. * @param string $apiKey
  81. */
  82. public static function setApiKey($apiKey)
  83. {
  84. self::$apiKey = $apiKey;
  85. }
  86. /**
  87. * Sets the client_id to be used for Connect requests.
  88. *
  89. * @param string $clientId
  90. */
  91. public static function setClientId($clientId)
  92. {
  93. self::$clientId = $clientId;
  94. }
  95. /**
  96. * @return string The API version used for requests. null if we're using the
  97. * latest version.
  98. */
  99. public static function getApiVersion()
  100. {
  101. return self::$apiVersion;
  102. }
  103. /**
  104. * @param string $apiVersion the API version to use for requests
  105. */
  106. public static function setApiVersion($apiVersion)
  107. {
  108. self::$apiVersion = $apiVersion;
  109. }
  110. /**
  111. * @return string
  112. */
  113. private static function getDefaultCABundlePath()
  114. {
  115. return \realpath(__DIR__ . '/../data/ca-certificates.crt');
  116. }
  117. /**
  118. * @return string
  119. */
  120. public static function getCABundlePath()
  121. {
  122. return self::$caBundlePath ?: self::getDefaultCABundlePath();
  123. }
  124. /**
  125. * @param string $caBundlePath
  126. */
  127. public static function setCABundlePath($caBundlePath)
  128. {
  129. self::$caBundlePath = $caBundlePath;
  130. }
  131. /**
  132. * @return bool
  133. */
  134. public static function getVerifySslCerts()
  135. {
  136. return self::$verifySslCerts;
  137. }
  138. /**
  139. * @param bool $verify
  140. */
  141. public static function setVerifySslCerts($verify)
  142. {
  143. self::$verifySslCerts = $verify;
  144. }
  145. /**
  146. * @return string | null The Stripe account ID for connected account
  147. * requests
  148. */
  149. public static function getAccountId()
  150. {
  151. return self::$accountId;
  152. }
  153. /**
  154. * @param string $accountId the Stripe account ID to set for connected
  155. * account requests
  156. */
  157. public static function setAccountId($accountId)
  158. {
  159. self::$accountId = $accountId;
  160. }
  161. /**
  162. * @return array | null The application's information
  163. */
  164. public static function getAppInfo()
  165. {
  166. return self::$appInfo;
  167. }
  168. /**
  169. * @param string $appName The application's name
  170. * @param null|string $appVersion The application's version
  171. * @param null|string $appUrl The application's URL
  172. * @param null|string $appPartnerId The application's partner ID
  173. */
  174. public static function setAppInfo($appName, $appVersion = null, $appUrl = null, $appPartnerId = null)
  175. {
  176. self::$appInfo = self::$appInfo ?: [];
  177. self::$appInfo['name'] = $appName;
  178. self::$appInfo['partner_id'] = $appPartnerId;
  179. self::$appInfo['url'] = $appUrl;
  180. self::$appInfo['version'] = $appVersion;
  181. }
  182. /**
  183. * @return int Maximum number of request retries
  184. */
  185. public static function getMaxNetworkRetries()
  186. {
  187. return self::$maxNetworkRetries;
  188. }
  189. /**
  190. * @param int $maxNetworkRetries Maximum number of request retries
  191. */
  192. public static function setMaxNetworkRetries($maxNetworkRetries)
  193. {
  194. self::$maxNetworkRetries = $maxNetworkRetries;
  195. }
  196. /**
  197. * @return float Maximum delay between retries, in seconds
  198. */
  199. public static function getMaxNetworkRetryDelay()
  200. {
  201. return self::$maxNetworkRetryDelay;
  202. }
  203. /**
  204. * @return float Maximum delay between retries, in seconds, that will be respected from the Stripe API
  205. */
  206. public static function getMaxRetryAfter()
  207. {
  208. return self::$maxRetryAfter;
  209. }
  210. /**
  211. * @return float Initial delay between retries, in seconds
  212. */
  213. public static function getInitialNetworkRetryDelay()
  214. {
  215. return self::$initialNetworkRetryDelay;
  216. }
  217. /**
  218. * @return bool Whether client telemetry is enabled
  219. */
  220. public static function getEnableTelemetry()
  221. {
  222. return self::$enableTelemetry;
  223. }
  224. /**
  225. * @param bool $enableTelemetry Enables client telemetry.
  226. *
  227. * Client telemetry enables timing and request metrics to be sent back to Stripe as an HTTP Header
  228. * with the current request. This enables Stripe to do latency and metrics analysis without adding extra
  229. * overhead (such as extra network calls) on the client.
  230. */
  231. public static function setEnableTelemetry($enableTelemetry)
  232. {
  233. self::$enableTelemetry = $enableTelemetry;
  234. }
  235. }