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