ApiOperations
2 years ago
BillingPortal
2 years ago
Checkout
2 years ago
Exception
4 years ago
FinancialConnections
2 years ago
HttpClient
2 years ago
Identity
2 years ago
Issuing
2 years ago
Radar
2 years ago
Reporting
4 years ago
Service
2 years ago
Sigma
4 years ago
Terminal
2 years ago
TestHelpers
2 years ago
Util
2 years ago
Account.php
2 years ago
AccountLink.php
4 years ago
AlipayAccount.php
4 years ago
ApiRequestor.php
2 years ago
ApiResource.php
2 years ago
ApiResponse.php
4 years ago
ApplePayDomain.php
4 years ago
ApplicationFee.php
2 years ago
ApplicationFeeRefund.php
4 years ago
Balance.php
4 years ago
BalanceTransaction.php
4 years ago
BankAccount.php
4 years ago
BaseStripeClient.php
2 years ago
BaseStripeClientInterface.php
4 years ago
BitcoinReceiver.php
2 years ago
BitcoinTransaction.php
4 years ago
Capability.php
4 years ago
Card.php
2 years ago
CashBalance.php
2 years ago
Charge.php
2 years ago
Collection.php
2 years ago
CountrySpec.php
4 years ago
Coupon.php
2 years ago
CreditNote.php
2 years ago
CreditNoteLineItem.php
4 years ago
Customer.php
2 years ago
CustomerBalanceTransaction.php
4 years ago
Discount.php
2 years ago
Dispute.php
4 years ago
EphemeralKey.php
4 years ago
ErrorObject.php
4 years ago
Event.php
2 years ago
ExchangeRate.php
4 years ago
File.php
2 years ago
FileLink.php
4 years ago
FundingInstructions.php
2 years ago
Invoice.php
2 years ago
InvoiceItem.php
2 years ago
InvoiceLineItem.php
2 years ago
LineItem.php
4 years ago
LoginLink.php
4 years ago
Mandate.php
4 years ago
OAuth.php
4 years ago
OAuthErrorObject.php
4 years ago
Order.php
2 years ago
OrderItem.php
4 years ago
OrderReturn.php
4 years ago
PaymentIntent.php
2 years ago
PaymentLink.php
2 years ago
PaymentMethod.php
2 years ago
Payout.php
4 years ago
Person.php
2 years ago
Plan.php
2 years ago
Price.php
2 years ago
Product.php
2 years ago
PromotionCode.php
2 years ago
Quote.php
2 years ago
Recipient.php
2 years ago
RecipientTransfer.php
4 years ago
Refund.php
2 years ago
RequestTelemetry.php
4 years ago
Review.php
4 years ago
SKU.php
2 years ago
SearchResult.php
2 years ago
SetupAttempt.php
4 years ago
SetupIntent.php
2 years ago
ShippingRate.php
2 years ago
SingletonApiResource.php
2 years ago
Source.php
4 years ago
SourceTransaction.php
4 years ago
Stripe.php
2 years ago
StripeClient.php
2 years ago
StripeClientInterface.php
4 years ago
StripeObject.php
2 years ago
StripeStreamingClientInterface.php
4 years ago
Subscription.php
2 years ago
SubscriptionItem.php
2 years ago
SubscriptionSchedule.php
2 years ago
TaxCode.php
2 years ago
TaxId.php
2 years ago
TaxRate.php
4 years ago
ThreeDSecure.php
4 years ago
Token.php
4 years ago
Topup.php
4 years ago
Transfer.php
2 years ago
TransferReversal.php
4 years ago
UsageRecord.php
4 years ago
UsageRecordSummary.php
4 years ago
Webhook.php
4 years ago
WebhookEndpoint.php
4 years ago
WebhookSignature.php
4 years ago
Stripe.php
279 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Stripe; |
| 4 | |
| 5 | /** |
| 6 | * Class Stripe. |
| 7 | */ |
| 8 | class Stripe |
| 9 | { |
| 10 | /** @var string The Stripe API key to be used for requests. */ |
| 11 | public static $apiKey; |
| 12 | |
| 13 | /** @var string The Stripe client_id to be used for Connect requests. */ |
| 14 | public static $clientId; |
| 15 | |
| 16 | /** @var string The base URL for the Stripe API. */ |
| 17 | public static $apiBase = 'https://api.stripe.com'; |
| 18 | |
| 19 | /** @var string The base URL for the OAuth API. */ |
| 20 | public static $connectBase = 'https://connect.stripe.com'; |
| 21 | |
| 22 | /** @var string The base URL for the Stripe API uploads endpoint. */ |
| 23 | public static $apiUploadBase = 'https://files.stripe.com'; |
| 24 | |
| 25 | /** @var null|string The version of the Stripe API to use for requests. */ |
| 26 | public static $apiVersion = null; |
| 27 | |
| 28 | /** @var null|string The account ID for connected accounts requests. */ |
| 29 | public static $accountId = null; |
| 30 | |
| 31 | /** @var string Path to the CA bundle used to verify SSL certificates */ |
| 32 | public static $caBundlePath = null; |
| 33 | |
| 34 | /** @var bool Defaults to true. */ |
| 35 | public static $verifySslCerts = true; |
| 36 | |
| 37 | /** @var array The application's information (name, version, URL) */ |
| 38 | public static $appInfo = null; |
| 39 | |
| 40 | /** |
| 41 | * @var null|Util\LoggerInterface the logger to which the library will |
| 42 | * produce messages |
| 43 | */ |
| 44 | public static $logger = null; |
| 45 | |
| 46 | /** @var int Maximum number of request retries */ |
| 47 | public static $maxNetworkRetries = 0; |
| 48 | |
| 49 | /** @var bool Whether client telemetry is enabled. Defaults to true. */ |
| 50 | public static $enableTelemetry = true; |
| 51 | |
| 52 | /** @var float Maximum delay between retries, in seconds */ |
| 53 | private static $maxNetworkRetryDelay = 2.0; |
| 54 | |
| 55 | /** @var float Maximum delay between retries, in seconds, that will be respected from the Stripe API */ |
| 56 | private static $maxRetryAfter = 60.0; |
| 57 | |
| 58 | /** @var float Initial delay between retries, in seconds */ |
| 59 | private static $initialNetworkRetryDelay = 0.5; |
| 60 | |
| 61 | const VERSION = '7.128.0'; |
| 62 | |
| 63 | /** |
| 64 | * @return string the API key used for requests |
| 65 | */ |
| 66 | public static function getApiKey() |
| 67 | { |
| 68 | return self::$apiKey; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return string the client_id used for Connect requests |
| 73 | */ |
| 74 | public static function getClientId() |
| 75 | { |
| 76 | return self::$clientId; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return Util\LoggerInterface the logger to which the library will |
| 81 | * produce messages |
| 82 | */ |
| 83 | public static function getLogger() |
| 84 | { |
| 85 | if (null === self::$logger) { |
| 86 | return new Util\DefaultLogger(); |
| 87 | } |
| 88 | |
| 89 | return self::$logger; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @param Util\LoggerInterface $logger the logger to which the library |
| 94 | * will produce messages |
| 95 | */ |
| 96 | public static function setLogger($logger) |
| 97 | { |
| 98 | self::$logger = $logger; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Sets the API key to be used for requests. |
| 103 | * |
| 104 | * @param string $apiKey |
| 105 | */ |
| 106 | public static function setApiKey($apiKey) |
| 107 | { |
| 108 | self::$apiKey = $apiKey; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Sets the client_id to be used for Connect requests. |
| 113 | * |
| 114 | * @param string $clientId |
| 115 | */ |
| 116 | public static function setClientId($clientId) |
| 117 | { |
| 118 | self::$clientId = $clientId; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @return string The API version used for requests. null if we're using the |
| 123 | * latest version. |
| 124 | */ |
| 125 | public static function getApiVersion() |
| 126 | { |
| 127 | return self::$apiVersion; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @param string $apiVersion the API version to use for requests |
| 132 | */ |
| 133 | public static function setApiVersion($apiVersion) |
| 134 | { |
| 135 | self::$apiVersion = $apiVersion; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @return string |
| 140 | */ |
| 141 | private static function getDefaultCABundlePath() |
| 142 | { |
| 143 | return \realpath(__DIR__ . '/../data/ca-certificates.crt'); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @return string |
| 148 | */ |
| 149 | public static function getCABundlePath() |
| 150 | { |
| 151 | return self::$caBundlePath ?: self::getDefaultCABundlePath(); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * @param string $caBundlePath |
| 156 | */ |
| 157 | public static function setCABundlePath($caBundlePath) |
| 158 | { |
| 159 | self::$caBundlePath = $caBundlePath; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @return bool |
| 164 | */ |
| 165 | public static function getVerifySslCerts() |
| 166 | { |
| 167 | return self::$verifySslCerts; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @param bool $verify |
| 172 | */ |
| 173 | public static function setVerifySslCerts($verify) |
| 174 | { |
| 175 | self::$verifySslCerts = $verify; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @return null|string The Stripe account ID for connected account |
| 180 | * requests |
| 181 | */ |
| 182 | public static function getAccountId() |
| 183 | { |
| 184 | return self::$accountId; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * @param string $accountId the Stripe account ID to set for connected |
| 189 | * account requests |
| 190 | */ |
| 191 | public static function setAccountId($accountId) |
| 192 | { |
| 193 | self::$accountId = $accountId; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * @return null|array The application's information |
| 198 | */ |
| 199 | public static function getAppInfo() |
| 200 | { |
| 201 | return self::$appInfo; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @param string $appName The application's name |
| 206 | * @param null|string $appVersion The application's version |
| 207 | * @param null|string $appUrl The application's URL |
| 208 | * @param null|string $appPartnerId The application's partner ID |
| 209 | */ |
| 210 | public static function setAppInfo($appName, $appVersion = null, $appUrl = null, $appPartnerId = null) |
| 211 | { |
| 212 | self::$appInfo = self::$appInfo ?: []; |
| 213 | self::$appInfo['name'] = $appName; |
| 214 | self::$appInfo['partner_id'] = $appPartnerId; |
| 215 | self::$appInfo['url'] = $appUrl; |
| 216 | self::$appInfo['version'] = $appVersion; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * @return int Maximum number of request retries |
| 221 | */ |
| 222 | public static function getMaxNetworkRetries() |
| 223 | { |
| 224 | return self::$maxNetworkRetries; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * @param int $maxNetworkRetries Maximum number of request retries |
| 229 | */ |
| 230 | public static function setMaxNetworkRetries($maxNetworkRetries) |
| 231 | { |
| 232 | self::$maxNetworkRetries = $maxNetworkRetries; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * @return float Maximum delay between retries, in seconds |
| 237 | */ |
| 238 | public static function getMaxNetworkRetryDelay() |
| 239 | { |
| 240 | return self::$maxNetworkRetryDelay; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * @return float Maximum delay between retries, in seconds, that will be respected from the Stripe API |
| 245 | */ |
| 246 | public static function getMaxRetryAfter() |
| 247 | { |
| 248 | return self::$maxRetryAfter; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * @return float Initial delay between retries, in seconds |
| 253 | */ |
| 254 | public static function getInitialNetworkRetryDelay() |
| 255 | { |
| 256 | return self::$initialNetworkRetryDelay; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * @return bool Whether client telemetry is enabled |
| 261 | */ |
| 262 | public static function getEnableTelemetry() |
| 263 | { |
| 264 | return self::$enableTelemetry; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * @param bool $enableTelemetry Enables client telemetry. |
| 269 | * |
| 270 | * Client telemetry enables timing and request metrics to be sent back to Stripe as an HTTP Header |
| 271 | * with the current request. This enables Stripe to do latency and metrics analysis without adding extra |
| 272 | * overhead (such as extra network calls) on the client. |
| 273 | */ |
| 274 | public static function setEnableTelemetry($enableTelemetry) |
| 275 | { |
| 276 | self::$enableTelemetry = $enableTelemetry; |
| 277 | } |
| 278 | } |
| 279 |