Stripe.php 5.8 KB

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