Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix autopagination for Service #942

Merged
merged 4 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/BaseStripeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ public function request($method, $path, $params, $opts)
return $obj;
}

/**
* Sends a request to Stripe's API.
*
* @param string $method the HTTP method
* @param string $path the path of the request
* @param array $params the parameters of the request
* @param array|\Stripe\Util\RequestOptions $opts the special modifiers of the request
*
* @return \Stripe\Collection of ApiResources
*/
public function requestCollection($method, $path, $params, $opts)
{
$obj = $this->request($method, $path, $params, $opts);
if (!($obj instanceof \Stripe\Collection)) {
$received_class = \get_class($obj);
$msg = "Expected to receive `Stripe\\Collection` object from Stripe API. Instead received `{$received_class}`.";

throw new \Stripe\Exception\UnexpectedValueException($msg);
}
$obj->setFilters($params);

return $obj;
}

/**
* @param \Stripe\Util\RequestOptions $opts
*
Expand Down
5 changes: 5 additions & 0 deletions lib/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ protected function request($method, $path, $params, $opts)
return $this->getClient()->request($method, $path, static::formatParams($params), $opts);
}

protected function requestCollection($method, $path, $params, $opts)
{
return $this->getClient()->requestCollection($method, $path, static::formatParams($params), $opts);
}

protected function buildPath($basePath, ...$ids)
{
foreach ($ids as $id) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AccountService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/accounts', $params, $opts);
return $this->requestCollection('get', '/v1/accounts', $params, $opts);
}

/**
Expand All @@ -35,7 +35,7 @@ public function all($params = null, $opts = null)
*/
public function allCapabilities($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/accounts/%s/capabilities', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/accounts/%s/capabilities', $parentId), $params, $opts);
}

/**
Expand All @@ -51,7 +51,7 @@ public function allCapabilities($parentId, $params = null, $opts = null)
*/
public function allExternalAccounts($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/accounts/%s/external_accounts', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/accounts/%s/external_accounts', $parentId), $params, $opts);
}

/**
Expand All @@ -69,7 +69,7 @@ public function allExternalAccounts($parentId, $params = null, $opts = null)
*/
public function allPersons($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/accounts/%s/persons', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/accounts/%s/persons', $parentId), $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ApplePayDomainService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ApplePayDomainService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/apple_pay/domains', $params, $opts);
return $this->requestCollection('get', '/v1/apple_pay/domains', $params, $opts);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/ApplicationFeeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApplicationFeeService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/application_fees', $params, $opts);
return $this->requestCollection('get', '/v1/application_fees', $params, $opts);
}

/**
Expand All @@ -37,7 +37,7 @@ public function all($params = null, $opts = null)
*/
public function allRefunds($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/application_fees/%s/refunds', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/application_fees/%s/refunds', $parentId), $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/BalanceTransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BalanceTransactionService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/balance_transactions', $params, $opts);
return $this->requestCollection('get', '/v1/balance_transactions', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ChargeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChargeService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/charges', $params, $opts);
return $this->requestCollection('get', '/v1/charges', $params, $opts);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/Checkout/SessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SessionService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/checkout/sessions', $params, $opts);
return $this->requestCollection('get', '/v1/checkout/sessions', $params, $opts);
}

/**
Expand All @@ -35,7 +35,7 @@ public function all($params = null, $opts = null)
*/
public function allLineItems($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/checkout/sessions/%s/line_items', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/checkout/sessions/%s/line_items', $parentId), $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CountrySpecService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CountrySpecService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/country_specs', $params, $opts);
return $this->requestCollection('get', '/v1/country_specs', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CouponService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CouponService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/coupons', $params, $opts);
return $this->requestCollection('get', '/v1/coupons', $params, $opts);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/CreditNoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CreditNoteService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/credit_notes', $params, $opts);
return $this->requestCollection('get', '/v1/credit_notes', $params, $opts);
}

/**
Expand All @@ -34,7 +34,7 @@ public function all($params = null, $opts = null)
*/
public function allLines($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/credit_notes/%s/lines', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/credit_notes/%s/lines', $parentId), $params, $opts);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/CustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CustomerService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/customers', $params, $opts);
return $this->requestCollection('get', '/v1/customers', $params, $opts);
}

/**
Expand All @@ -34,7 +34,7 @@ public function all($params = null, $opts = null)
*/
public function allBalanceTransactions($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
}

/**
Expand All @@ -50,7 +50,7 @@ public function allBalanceTransactions($parentId, $params = null, $opts = null)
*/
public function allSources($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/sources', $parentId), $params, $opts);
}

/**
Expand All @@ -66,7 +66,7 @@ public function allSources($parentId, $params = null, $opts = null)
*/
public function allTaxIds($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/tax_ids', $parentId), $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/DisputeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DisputeService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/disputes', $params, $opts);
return $this->requestCollection('get', '/v1/disputes', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/EventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EventService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/events', $params, $opts);
return $this->requestCollection('get', '/v1/events', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ExchangeRateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ExchangeRateService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/exchange_rates', $params, $opts);
return $this->requestCollection('get', '/v1/exchange_rates', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/FileLinkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FileLinkService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/file_links', $params, $opts);
return $this->requestCollection('get', '/v1/file_links', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FileService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/files', $params, $opts);
return $this->requestCollection('get', '/v1/files', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/InvoiceItemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InvoiceItemService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/invoiceitems', $params, $opts);
return $this->requestCollection('get', '/v1/invoiceitems', $params, $opts);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/InvoiceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InvoiceService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/invoices', $params, $opts);
return $this->requestCollection('get', '/v1/invoices', $params, $opts);
}

/**
Expand All @@ -37,7 +37,7 @@ public function all($params = null, $opts = null)
*/
public function allLines($parentId, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/invoices/%s/lines', $parentId), $params, $opts);
return $this->requestCollection('get', $this->buildPath('/v1/invoices/%s/lines', $parentId), $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Issuing/AuthorizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AuthorizationService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/issuing/authorizations', $params, $opts);
return $this->requestCollection('get', '/v1/issuing/authorizations', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Issuing/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CardService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/issuing/cards', $params, $opts);
return $this->requestCollection('get', '/v1/issuing/cards', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Issuing/CardholderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CardholderService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/issuing/cardholders', $params, $opts);
return $this->requestCollection('get', '/v1/issuing/cardholders', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Issuing/DisputeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DisputeService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/issuing/disputes', $params, $opts);
return $this->requestCollection('get', '/v1/issuing/disputes', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Issuing/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TransactionService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/issuing/transactions', $params, $opts);
return $this->requestCollection('get', '/v1/issuing/transactions', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/OrderReturnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OrderReturnService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/order_returns', $params, $opts);
return $this->requestCollection('get', '/v1/order_returns', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OrderService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/orders', $params, $opts);
return $this->requestCollection('get', '/v1/orders', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PaymentIntentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PaymentIntentService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/payment_intents', $params, $opts);
return $this->requestCollection('get', '/v1/payment_intents', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PaymentMethodService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/payment_methods', $params, $opts);
return $this->requestCollection('get', '/v1/payment_methods', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PayoutService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PayoutService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/payouts', $params, $opts);
return $this->requestCollection('get', '/v1/payouts', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PlanService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PlanService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/plans', $params, $opts);
return $this->requestCollection('get', '/v1/plans', $params, $opts);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PriceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PriceService extends \Stripe\Service\AbstractService
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/prices', $params, $opts);
return $this->requestCollection('get', '/v1/prices', $params, $opts);
}

/**
Expand Down
Loading