Apps
2 months ago
Billing
2 months ago
BillingPortal
2 months ago
Checkout
2 months ago
Climate
2 months ago
Entitlements
2 months ago
FinancialConnections
2 months ago
Forwarding
2 months ago
Identity
2 months ago
Issuing
2 months ago
Radar
2 months ago
Reporting
2 months ago
Sigma
2 months ago
Tax
2 months ago
Terminal
2 months ago
TestHelpers
2 months ago
Treasury
2 months ago
V2
2 months ago
AbstractService.php
2 months ago
AbstractServiceFactory.php
2 months ago
AccountLinkService.php
2 months ago
AccountService.php
2 months ago
AccountSessionService.php
2 months ago
ApplePayDomainService.php
2 months ago
ApplicationFeeService.php
2 months ago
BalanceService.php
2 months ago
BalanceTransactionService.php
2 months ago
ChargeService.php
2 months ago
ConfirmationTokenService.php
2 months ago
CoreServiceFactory.php
2 months ago
CountrySpecService.php
2 months ago
CouponService.php
2 months ago
CreditNoteService.php
2 months ago
CustomerService.php
2 months ago
CustomerSessionService.php
2 months ago
DisputeService.php
2 months ago
EphemeralKeyService.php
2 months ago
EventService.php
2 months ago
ExchangeRateService.php
2 months ago
FileLinkService.php
2 months ago
FileService.php
2 months ago
InvoiceItemService.php
2 months ago
InvoiceRenderingTemplateService.php
2 months ago
InvoiceService.php
2 months ago
MandateService.php
2 months ago
OAuthService.php
2 months ago
PaymentIntentService.php
2 months ago
PaymentLinkService.php
2 months ago
PaymentMethodConfigurationService.php
2 months ago
PaymentMethodDomainService.php
2 months ago
PaymentMethodService.php
2 months ago
PayoutService.php
2 months ago
PlanService.php
2 months ago
PriceService.php
2 months ago
ProductService.php
2 months ago
PromotionCodeService.php
2 months ago
QuoteService.php
2 months ago
RefundService.php
2 months ago
ReviewService.php
2 months ago
ServiceNavigatorTrait.php
2 months ago
SetupAttemptService.php
2 months ago
SetupIntentService.php
2 months ago
ShippingRateService.php
2 months ago
SourceService.php
2 months ago
SubscriptionItemService.php
2 months ago
SubscriptionScheduleService.php
2 months ago
SubscriptionService.php
2 months ago
TaxCodeService.php
2 months ago
TaxIdService.php
2 months ago
TaxRateService.php
2 months ago
TokenService.php
2 months ago
TopupService.php
2 months ago
TransferService.php
2 months ago
WebhookEndpointService.php
2 months ago
AbstractService.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Stripe\Service; |
| 4 | |
| 5 | /** |
| 6 | * Abstract base class for all services. |
| 7 | */ |
| 8 | abstract class AbstractService |
| 9 | { |
| 10 | /** |
| 11 | * @var \Stripe\StripeClientInterface |
| 12 | */ |
| 13 | protected $client; |
| 14 | /** |
| 15 | * @var \Stripe\StripeStreamingClientInterface |
| 16 | */ |
| 17 | protected $streamingClient; |
| 18 | /** |
| 19 | * Initializes a new instance of the {@link AbstractService} class. |
| 20 | * |
| 21 | * @param \Stripe\StripeClientInterface $client |
| 22 | */ |
| 23 | public function __construct($client) |
| 24 | { |
| 25 | $this->client = $client; |
| 26 | $this->streamingClient = $client; |
| 27 | } |
| 28 | /** |
| 29 | * Gets the client used by this service to send requests. |
| 30 | * |
| 31 | * @return \Stripe\StripeClientInterface |
| 32 | */ |
| 33 | public function getClient() |
| 34 | { |
| 35 | return $this->client; |
| 36 | } |
| 37 | /** |
| 38 | * Gets the client used by this service to send requests. |
| 39 | * |
| 40 | * @return \Stripe\StripeStreamingClientInterface |
| 41 | */ |
| 42 | public function getStreamingClient() |
| 43 | { |
| 44 | return $this->streamingClient; |
| 45 | } |
| 46 | /** |
| 47 | * Translate null values to empty strings. For service methods, |
| 48 | * we interpret null as a request to unset the field, which |
| 49 | * corresponds to sending an empty string for the field to the |
| 50 | * API. |
| 51 | * |
| 52 | * @param null|array $params |
| 53 | */ |
| 54 | private static function formatParams($params) |
| 55 | { |
| 56 | if (null === $params) { |
| 57 | return null; |
| 58 | } |
| 59 | \array_walk_recursive($params, function (&$value, $key) { |
| 60 | if (null === $value) { |
| 61 | $value = ''; |
| 62 | } |
| 63 | }); |
| 64 | return $params; |
| 65 | } |
| 66 | protected function request($method, $path, $params, $opts) |
| 67 | { |
| 68 | return $this->getClient()->request($method, $path, self::formatParams($params), $opts); |
| 69 | } |
| 70 | protected function requestStream($method, $path, $readBodyChunkCallable, $params, $opts) |
| 71 | { |
| 72 | // TODO (MAJOR): Add this method to StripeClientInterface |
| 73 | // @phpstan-ignore-next-line |
| 74 | return $this->getStreamingClient()->requestStream($method, $path, $readBodyChunkCallable, self::formatParams($params), $opts); |
| 75 | } |
| 76 | protected function requestCollection($method, $path, $params, $opts) |
| 77 | { |
| 78 | // TODO (MAJOR): Add this method to StripeClientInterface |
| 79 | // @phpstan-ignore-next-line |
| 80 | return $this->getClient()->requestCollection($method, $path, self::formatParams($params), $opts); |
| 81 | } |
| 82 | protected function requestSearchResult($method, $path, $params, $opts) |
| 83 | { |
| 84 | // TODO (MAJOR): Add this method to StripeClientInterface |
| 85 | // @phpstan-ignore-next-line |
| 86 | return $this->getClient()->requestSearchResult($method, $path, self::formatParams($params), $opts); |
| 87 | } |
| 88 | protected function buildPath($basePath, ...$ids) |
| 89 | { |
| 90 | foreach ($ids as $id) { |
| 91 | if (null === $id || '' === \trim($id)) { |
| 92 | $msg = 'The resource ID cannot be null or whitespace.'; |
| 93 | throw new \ProfilePressVendor\Stripe\Exception\InvalidArgumentException($msg); |
| 94 | } |
| 95 | } |
| 96 | return \sprintf($basePath, ...\array_map('\urlencode', $ids)); |
| 97 | } |
| 98 | } |
| 99 |