dolibarr/htdocs/includes/stripe/stripe-php/lib/Stripe.php

279 lines
7.1 KiB
PHP
Raw Normal View History

2017-04-18 05:44:08 +02:00
<?php
namespace Stripe;
/**
2021-01-03 23:37:44 +01:00
* Class Stripe.
2017-04-18 05:44:08 +02:00
*/
class Stripe
{
2021-01-03 23:37:44 +01:00
/** @var string The Stripe API key to be used for requests. */
2017-04-18 05:44:08 +02:00
public static $apiKey;
2021-01-03 23:37:44 +01:00
/** @var string The Stripe client_id to be used for Connect requests. */
2018-03-06 13:52:56 +01:00
public static $clientId;
2021-01-03 23:37:44 +01:00
/** @var string The base URL for the Stripe API. */
2017-04-18 05:44:08 +02:00
public static $apiBase = 'https://api.stripe.com';
2021-01-03 23:37:44 +01:00
/** @var string The base URL for the OAuth API. */
2018-03-06 13:52:56 +01:00
public static $connectBase = 'https://connect.stripe.com';
2021-01-03 23:37:44 +01:00
/** @var string The base URL for the Stripe API uploads endpoint. */
2019-05-03 02:22:27 +02:00
public static $apiUploadBase = 'https://files.stripe.com';
2017-04-18 05:44:08 +02:00
2021-01-03 23:37:44 +01:00
/** @var null|string The version of the Stripe API to use for requests. */
2017-04-18 05:44:08 +02:00
public static $apiVersion = null;
2021-01-03 23:37:44 +01:00
/** @var null|string The account ID for connected accounts requests. */
2017-04-18 05:44:08 +02:00
public static $accountId = null;
2021-01-03 23:37:44 +01:00
/** @var string Path to the CA bundle used to verify SSL certificates */
2018-03-06 13:52:56 +01:00
public static $caBundlePath = null;
2021-01-03 23:37:44 +01:00
/** @var bool Defaults to true. */
2017-04-18 05:44:08 +02:00
public static $verifySslCerts = true;
2021-01-03 23:37:44 +01:00
/** @var array The application's information (name, version, URL) */
2017-04-18 05:44:08 +02:00
public static $appInfo = null;
2021-01-03 23:37:44 +01:00
/**
* @var null|Util\LoggerInterface the logger to which the library will
* produce messages
*/
2018-03-06 13:52:56 +01:00
public static $logger = null;
2021-01-03 23:37:44 +01:00
/** @var int Maximum number of request retries */
2018-03-06 13:52:56 +01:00
public static $maxNetworkRetries = 0;
2021-01-03 23:37:44 +01:00
/** @var bool Whether client telemetry is enabled. Defaults to true. */
public static $enableTelemetry = true;
2019-05-03 02:22:27 +02:00
2021-01-03 23:37:44 +01:00
/** @var float Maximum delay between retries, in seconds */
2018-03-06 13:52:56 +01:00
private static $maxNetworkRetryDelay = 2.0;
2021-01-03 23:37:44 +01:00
/** @var float Maximum delay between retries, in seconds, that will be respected from the Stripe API */
private static $maxRetryAfter = 60.0;
/** @var float Initial delay between retries, in seconds */
2018-03-06 13:52:56 +01:00
private static $initialNetworkRetryDelay = 0.5;
2021-01-03 23:37:44 +01:00
const VERSION = '7.67.0';
2017-04-18 05:44:08 +02:00
/**
2021-01-03 23:37:44 +01:00
* @return string the API key used for requests
2017-04-18 05:44:08 +02:00
*/
public static function getApiKey()
{
return self::$apiKey;
}
2018-03-06 13:52:56 +01:00
/**
2021-01-03 23:37:44 +01:00
* @return string the client_id used for Connect requests
2018-03-06 13:52:56 +01:00
*/
public static function getClientId()
{
return self::$clientId;
}
/**
2021-01-03 23:37:44 +01:00
* @return Util\LoggerInterface the logger to which the library will
* produce messages
2018-03-06 13:52:56 +01:00
*/
public static function getLogger()
{
2021-01-03 23:37:44 +01:00
if (null === self::$logger) {
2018-03-06 13:52:56 +01:00
return new Util\DefaultLogger();
}
2021-01-03 23:37:44 +01:00
2018-03-06 13:52:56 +01:00
return self::$logger;
}
/**
2021-01-03 23:37:44 +01:00
* @param Util\LoggerInterface $logger the logger to which the library
* will produce messages
2018-03-06 13:52:56 +01:00
*/
public static function setLogger($logger)
{
self::$logger = $logger;
}
2017-04-18 05:44:08 +02:00
/**
* Sets the API key to be used for requests.
*
* @param string $apiKey
*/
public static function setApiKey($apiKey)
{
self::$apiKey = $apiKey;
}
2018-03-06 13:52:56 +01:00
/**
* Sets the client_id to be used for Connect requests.
*
* @param string $clientId
*/
public static function setClientId($clientId)
{
self::$clientId = $clientId;
}
2017-04-18 05:44:08 +02:00
/**
* @return string The API version used for requests. null if we're using the
* latest version.
*/
public static function getApiVersion()
{
return self::$apiVersion;
}
/**
2021-01-03 23:37:44 +01:00
* @param string $apiVersion the API version to use for requests
2017-04-18 05:44:08 +02:00
*/
public static function setApiVersion($apiVersion)
{
self::$apiVersion = $apiVersion;
}
2018-03-06 13:52:56 +01:00
/**
* @return string
*/
private static function getDefaultCABundlePath()
{
2021-01-03 23:37:44 +01:00
return \realpath(__DIR__ . '/../data/ca-certificates.crt');
2018-03-06 13:52:56 +01:00
}
/**
* @return string
*/
public static function getCABundlePath()
{
return self::$caBundlePath ?: self::getDefaultCABundlePath();
}
/**
* @param string $caBundlePath
*/
public static function setCABundlePath($caBundlePath)
{
self::$caBundlePath = $caBundlePath;
}
2017-04-18 05:44:08 +02:00
/**
2021-01-03 23:37:44 +01:00
* @return bool
2017-04-18 05:44:08 +02:00
*/
public static function getVerifySslCerts()
{
return self::$verifySslCerts;
}
/**
2021-01-03 23:37:44 +01:00
* @param bool $verify
2017-04-18 05:44:08 +02:00
*/
public static function setVerifySslCerts($verify)
{
self::$verifySslCerts = $verify;
}
/**
* @return string | null The Stripe account ID for connected account
2021-01-03 23:37:44 +01:00
* requests
2017-04-18 05:44:08 +02:00
*/
public static function getAccountId()
{
return self::$accountId;
}
/**
2021-01-03 23:37:44 +01:00
* @param string $accountId the Stripe account ID to set for connected
* account requests
2017-04-18 05:44:08 +02:00
*/
public static function setAccountId($accountId)
{
self::$accountId = $accountId;
}
/**
* @return array | null The application's information
*/
public static function getAppInfo()
{
return self::$appInfo;
}
/**
* @param string $appName The application's name
2021-01-03 23:37:44 +01:00
* @param null|string $appVersion The application's version
* @param null|string $appUrl The application's URL
* @param null|string $appPartnerId The application's partner ID
2017-04-18 05:44:08 +02:00
*/
2019-05-03 02:22:27 +02:00
public static function setAppInfo($appName, $appVersion = null, $appUrl = null, $appPartnerId = null)
2017-04-18 05:44:08 +02:00
{
2018-03-06 13:52:56 +01:00
self::$appInfo = self::$appInfo ?: [];
2017-04-18 05:44:08 +02:00
self::$appInfo['name'] = $appName;
2019-05-03 02:22:27 +02:00
self::$appInfo['partner_id'] = $appPartnerId;
2017-04-18 05:44:08 +02:00
self::$appInfo['url'] = $appUrl;
2019-05-03 02:22:27 +02:00
self::$appInfo['version'] = $appVersion;
2017-04-18 05:44:08 +02:00
}
2018-03-06 13:52:56 +01:00
/**
* @return int Maximum number of request retries
*/
public static function getMaxNetworkRetries()
{
return self::$maxNetworkRetries;
}
/**
* @param int $maxNetworkRetries Maximum number of request retries
*/
public static function setMaxNetworkRetries($maxNetworkRetries)
{
self::$maxNetworkRetries = $maxNetworkRetries;
}
/**
* @return float Maximum delay between retries, in seconds
*/
public static function getMaxNetworkRetryDelay()
{
return self::$maxNetworkRetryDelay;
}
2021-01-03 23:37:44 +01:00
/**
* @return float Maximum delay between retries, in seconds, that will be respected from the Stripe API
*/
public static function getMaxRetryAfter()
{
return self::$maxRetryAfter;
}
2018-03-06 13:52:56 +01:00
/**
* @return float Initial delay between retries, in seconds
*/
public static function getInitialNetworkRetryDelay()
{
return self::$initialNetworkRetryDelay;
}
2019-05-03 02:22:27 +02:00
/**
* @return bool Whether client telemetry is enabled
*/
public static function getEnableTelemetry()
{
return self::$enableTelemetry;
}
/**
* @param bool $enableTelemetry Enables client telemetry.
*
* Client telemetry enables timing and request metrics to be sent back to Stripe as an HTTP Header
* with the current request. This enables Stripe to do latency and metrics analysis without adding extra
* overhead (such as extra network calls) on the client.
*/
public static function setEnableTelemetry($enableTelemetry)
{
self::$enableTelemetry = $enableTelemetry;
}
2017-04-18 05:44:08 +02:00
}