Stripe.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 string The version of the Stripe API to use for requests. */
  19. public static $apiVersion = \Stripe\Util\ApiVersion::CURRENT;
  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 = '15.1.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 \Psr\Log\LoggerInterface|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
  97. */
  98. public static function getApiVersion()
  99. {
  100. return self::$apiVersion;
  101. }
  102. /**
  103. * @param string $apiVersion the API version to use for requests
  104. */
  105. public static function setApiVersion($apiVersion)
  106. {
  107. self::$apiVersion = $apiVersion;
  108. }
  109. /**
  110. * @return string
  111. */
  112. private static function getDefaultCABundlePath()
  113. {
  114. return \realpath(__DIR__ . '/../data/ca-certificates.crt');
  115. }
  116. /**
  117. * @return string
  118. */
  119. public static function getCABundlePath()
  120. {
  121. return self::$caBundlePath ?: self::getDefaultCABundlePath();
  122. }
  123. /**
  124. * @param string $caBundlePath
  125. */
  126. public static function setCABundlePath($caBundlePath)
  127. {
  128. self::$caBundlePath = $caBundlePath;
  129. }
  130. /**
  131. * @return bool
  132. */
  133. public static function getVerifySslCerts()
  134. {
  135. return self::$verifySslCerts;
  136. }
  137. /**
  138. * @param bool $verify
  139. */
  140. public static function setVerifySslCerts($verify)
  141. {
  142. self::$verifySslCerts = $verify;
  143. }
  144. /**
  145. * @return null|string The Stripe account ID for connected account
  146. * requests
  147. */
  148. public static function getAccountId()
  149. {
  150. return self::$accountId;
  151. }
  152. /**
  153. * @param null|string $accountId the Stripe account ID to set for connected
  154. * account requests
  155. */
  156. public static function setAccountId($accountId)
  157. {
  158. self::$accountId = $accountId;
  159. }
  160. /**
  161. * @return null|array The application's information
  162. */
  163. public static function getAppInfo()
  164. {
  165. return self::$appInfo;
  166. }
  167. /**
  168. * @param string $appName The application's name
  169. * @param null|string $appVersion The application's version
  170. * @param null|string $appUrl The application's URL
  171. * @param null|string $appPartnerId The application's partner ID
  172. */
  173. public static function setAppInfo($appName, $appVersion = null, $appUrl = null, $appPartnerId = null)
  174. {
  175. self::$appInfo = self::$appInfo ?: [];
  176. self::$appInfo['name'] = $appName;
  177. self::$appInfo['partner_id'] = $appPartnerId;
  178. self::$appInfo['url'] = $appUrl;
  179. self::$appInfo['version'] = $appVersion;
  180. }
  181. /**
  182. * @return int Maximum number of request retries
  183. */
  184. public static function getMaxNetworkRetries()
  185. {
  186. return self::$maxNetworkRetries;
  187. }
  188. /**
  189. * @param int $maxNetworkRetries Maximum number of request retries
  190. */
  191. public static function setMaxNetworkRetries($maxNetworkRetries)
  192. {
  193. self::$maxNetworkRetries = $maxNetworkRetries;
  194. }
  195. /**
  196. * @return float Maximum delay between retries, in seconds
  197. */
  198. public static function getMaxNetworkRetryDelay()
  199. {
  200. return self::$maxNetworkRetryDelay;
  201. }
  202. /**
  203. * @return float Maximum delay between retries, in seconds, that will be respected from the Stripe API
  204. */
  205. public static function getMaxRetryAfter()
  206. {
  207. return self::$maxRetryAfter;
  208. }
  209. /**
  210. * @return float Initial delay between retries, in seconds
  211. */
  212. public static function getInitialNetworkRetryDelay()
  213. {
  214. return self::$initialNetworkRetryDelay;
  215. }
  216. /**
  217. * @return bool Whether client telemetry is enabled
  218. */
  219. public static function getEnableTelemetry()
  220. {
  221. return self::$enableTelemetry;
  222. }
  223. /**
  224. * @param bool $enableTelemetry Enables client telemetry.
  225. *
  226. * Client telemetry enables timing and request metrics to be sent back to Stripe as an HTTP Header
  227. * with the current request. This enables Stripe to do latency and metrics analysis without adding extra
  228. * overhead (such as extra network calls) on the client.
  229. */
  230. public static function setEnableTelemetry($enableTelemetry)
  231. {
  232. self::$enableTelemetry = $enableTelemetry;
  233. }
  234. }