Skip to content

Commit

Permalink
Support all parameters for list operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jlinn committed Jan 31, 2015
1 parent e171cb6 commit fa91533
Show file tree
Hide file tree
Showing 37 changed files with 808 additions and 232 deletions.
14 changes: 14 additions & 0 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use JMS\Serializer\Serializer;
use JMS\Serializer\SerializerBuilder;
use Stripe\Client;
use Stripe\Request\ListRequest;

abstract class AbstractApi
{
Expand All @@ -33,4 +34,17 @@ public function __construct(Client $client)
$this->client = $client;
$this->serializer = SerializerBuilder::create()->build();
}

/**
* Convenience method to perform a null check on the optional list request parameter
* @param ListRequest $request
* @return array
*/
protected function listRequestToParams(ListRequest $request = null)
{
if (!is_null($request)) {
return $request->toParams();
}
return array();
}
}
20 changes: 4 additions & 16 deletions src/Api/ApplicationFees.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Stripe\Api;


use Stripe\Request\ApplicationFees\ListApplicationFeesRequest;
use Stripe\Response\ApplicationFees\ApplicationFeeResponse;
use Stripe\Response\ApplicationFees\ListApplicationFeesResponse;

Expand Down Expand Up @@ -42,26 +43,13 @@ public function refundApplicationFee($applicationFeeId, $amount = null)
}

/**
* @param string $charge
* @param string|array $created
* @param int $limit
* @param string $startingAfter
* @param ListApplicationFeesRequest $request
* @return ListApplicationFeesResponse
* @link https://stripe.com/docs/api#list_application_fees
*/
public function listApplicationFees($charge = null, $created = null, $limit = 10, $startingAfter = null)
public function listApplicationFees(ListApplicationFeesRequest $request = null)
{
$request = array('limit' => $limit);
if (!is_null($charge)) {
$request['charge'] = $charge;
}
if (!is_null($created)) {
$request['created'] = $created;
}
if (!is_null($startingAfter)) {
$request['starting_after'] = $startingAfter;
}
return $this->client->get($this->buildUrl(), self::LIST_APPLICATION_FEES_RESPONSE_CLASS, $request);
return $this->client->get($this->buildUrl(), self::LIST_APPLICATION_FEES_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getBalanceTransaction($transactionId)
*/
public function listBalanceHistory(ListBalanceHistoryRequest $request = null)
{
return $this->client->get('balance/history', self::LIST_BALANCE_TRANSACTIONS_RESPONSE_CLASS, $request);
return $this->client->get('balance/history', self::LIST_BALANCE_TRANSACTIONS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Api/Cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Stripe\Exception\InvalidExpiryYearException;
use Stripe\Request\Cards\CreateCardRequest;
use Stripe\Request\Cards\UpdateCardRequest;
use Stripe\Request\ListRequest;
use Stripe\Response\Cards\CardResponse;
use Stripe\Response\Cards\ListCardsResponse;
use Stripe\Response\DeleteResponse;
Expand Down Expand Up @@ -101,14 +102,13 @@ public function deleteCard($customerId, $cardId)

/**
* @param string $customerId
* @param int $count
* @param int $offset
* @param ListRequest $request
* @return ListCardsResponse
* @link https://stripe.com/docs/api/curl#list_cards
*/
public function listCards($customerId, $count = 10, $offset = 0)
public function listCards($customerId, ListRequest $request = null)
{
return $this->client->get($this->buildUrl($customerId), self::LIST_CARDS_RESPONSE_CLASS, null, array('count' => $count, 'offset' => $offset));
return $this->client->get($this->buildUrl($customerId), self::LIST_CARDS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
20 changes: 4 additions & 16 deletions src/Api/Charges.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


use Stripe\Request\Charges\CreateChargeRequest;
use Stripe\Request\ListRequest;
use Stripe\Response\Charges\ChargeResponse;
use Stripe\Response\Charges\ListChargesResponse;

Expand Down Expand Up @@ -95,26 +96,13 @@ public function captureCharge($chargeId, $amount = null, $applicationFee = null)
}

/**
* @param int $count
* @param int $offset
* @param string|array $created
* @param string $customerId
* @param ListRequest $request
* @return ListChargesResponse
* @link https://stripe.com/docs/api#list_charges
*/
public function listCharges($count = 10, $offset = 0, $created = null, $customerId = null)
public function listCharges(ListRequest $request = null)
{
$request = array(
'count' => $count,
'offset' => $offset
);
if (!is_null($created)) {
$request['created'] = $created;
}
if (!is_null($customerId)) {
$request['customer'] = $customerId;
}
return $this->client->get($this->buildUrl(), self::LIST_CHARGES_RESPONSE_CLASS, null, $request);
return $this->client->get($this->buildUrl(), self::LIST_CHARGES_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
14 changes: 4 additions & 10 deletions src/Api/Coupons.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


use Stripe\Request\Coupons\CreateCouponRequest;
use Stripe\Request\ListRequest;
use Stripe\Response\Coupons\CouponResponse;
use Stripe\Response\Coupons\ListCouponsResponse;
use Stripe\Response\DeleteResponse;
Expand Down Expand Up @@ -49,20 +50,13 @@ public function deleteCoupon($couponId)
}

/**
* @param int $limit
* @param string $startingAfter
* @param ListRequest $request
* @return ListCouponsResponse
* @link https://stripe.com/docs/api#list_coupons
*/
public function listCoupons($limit = 10, $startingAfter = null)
public function listCoupons(ListRequest $request = null)
{
$request = array(
'limit' => $limit
);
if (!is_null($startingAfter)) {
$request['starting_after'] = $startingAfter;
}
return $this->client->get($this->buildUrl(), self::LIST_COUPONS_RESPONSE_CLASS, null, $request);
return $this->client->get($this->buildUrl(), self::LIST_COUPONS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
16 changes: 4 additions & 12 deletions src/Api/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Stripe\Api;


use Stripe\Request\ListRequest;
use Stripe\Request\Customers\CreateCustomerRequest;
use Stripe\Request\Customers\UpdateCustomerRequest;
use Stripe\Response\Customers\CustomerResponse;
Expand Down Expand Up @@ -61,22 +62,13 @@ public function deleteCustomer($customerId)
}

/**
* @param int $count
* @param int $offset
* @param string|array $created
* @param ListRequest $request
* @return ListCustomersResponse
* @link https://stripe.com/docs/api/curl#list_customers
*/
public function listCustomers($count = 10, $offset = 0, $created = null)
public function listCustomers(ListRequest $request = null)
{
$params = array(
'count' => $count,
'offset' => $offset
);
if (!is_null($created)) {
$params['created'] = $created;
}
return $this->client->get('customers', self::LIST_CUSTOMERS_RESPONSE_CLASS, null, $params);
return $this->client->get('customers', self::LIST_CUSTOMERS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
20 changes: 4 additions & 16 deletions src/Api/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Stripe\Api;


use Stripe\Request\Events\ListEventsRequest;
use Stripe\Response\Events\EventResponse;
use Stripe\Response\Events\ListEventsResponse;

Expand All @@ -27,26 +28,13 @@ public function getEvent($eventId)
}

/**
* @param string|array $created
* @param string $type
* @param int $limit
* @param string $startingAfter
* @param ListEventsRequest $request
* @return ListEventsResponse
* @link https://stripe.com/docs/api#list_events
*/
public function listEvents($created = null, $type = null, $limit = 10, $startingAfter = null)
public function listEvents(ListEventsRequest $request = null)
{
$request = array('limit' => $limit);
if (!is_null($created)) {
$request['created'] = $created;
}
if (!is_null($type)) {
$request['type'] = $type;
}
if (!is_null($startingAfter)) {
$request['starting_after'] = $startingAfter;
}
return $this->client->get($this->buildUrl(), self::LIST_EVENTS_RESPONSE_CLASS, null, $request);
return $this->client->get($this->buildUrl(), self::LIST_EVENTS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
24 changes: 4 additions & 20 deletions src/Api/InvoiceItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


use Stripe\Request\InvoiceItems\CreateInvoiceItemRequest;
use Stripe\Request\InvoiceItems\ListInvoiceItemsRequest;
use Stripe\Response\DeleteResponse;
use Stripe\Response\InvoiceItems\InvoiceItemResponse;
use Stripe\Response\InvoiceItems\ListInvoiceItemsResponse;
Expand Down Expand Up @@ -72,30 +73,13 @@ public function deleteInvoiceItem($invoiceItemId)
}

/**
* @param int $count
* @param int $offset
* @param string|array $created
* @param string $customerId
* @param string $startingAfter
* @param ListInvoiceItemsRequest $request
* @return ListInvoiceItemsResponse
* @link https://stripe.com/docs/api#list_invoiceitems
*/
public function listInvoiceItems($count = 10, $offset = 0, $created = null, $customerId = null, $startingAfter = null)
public function listInvoiceItems(ListInvoiceItemsRequest $request = null)
{
$request = array(
'count' => $count,
'offset' => $offset
);
if (!is_null($created)) {
$request['created'] = $created;
}
if (!is_null($customerId)) {
$request['customer'] = $customerId;
}
if (!is_null($startingAfter)) {
$request['starting_after'] = $startingAfter;
}
return $this->client->get($this->buildUrl(), self::LIST_INVOICE_ITEMS_RESPONSE_CLASS, null, $request);
return $this->client->get($this->buildUrl(), self::LIST_INVOICE_ITEMS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Api/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


use Stripe\Request\Invoices\CreateInvoiceRequest;
use Stripe\Request\ListRequest;
use Stripe\Response\Invoices\InvoiceResponse;
use Stripe\Response\Invoices\ListInvoicesResponse;
use Stripe\Response\Invoices\ListLineItemsResponse;
Expand Down Expand Up @@ -75,14 +76,13 @@ public function payInvoice($invoiceId)
}

/**
* @param int $count
* @param int $offset
* @param ListRequest $request
* @return ListInvoicesResponse
* @link https://stripe.com/docs/api/curl#list_plans
*/
public function listInvoices($count = 10, $offset = 0)
public function listInvoices(ListRequest $request = null)
{
return $this->client->get('invoices', 'Stripe\Response\Invoices\ListInvoicesResponse', null, array('count' => $count, 'offset' => $offset));
return $this->client->get('invoices', 'Stripe\Response\Invoices\ListInvoicesResponse', null, $this->listRequestToParams($request));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/Api/Plans.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Stripe\Api;


use Stripe\Request\ListRequest;
use Stripe\Request\Plans\CreatePlanRequest;
use Stripe\Response\DeleteResponse;
use Stripe\Response\Plans\ListPlansResponse;
Expand All @@ -16,6 +17,7 @@
class Plans extends AbstractApi
{
const PLAN_RESPONSE_CLASS = 'Stripe\Response\Plans\PlanResponse';
const LIST_PLANS_RESPONSE_CLASS = 'Stripe\Response\Plans\ListPlansResponse';

/**
* @param CreatePlanRequest $request
Expand Down Expand Up @@ -67,14 +69,13 @@ public function deletePlan($planId)
}

/**
* @param int $count
* @param int $offset
* @param ListRequest $request
* @return ListPlansResponse
* @link https://stripe.com/docs/api/curl#list_plans
*/
public function listPlans($count = 10, $offset = 0)
public function listPlans(ListRequest $request = null)
{
return $this->client->get('plans', 'Stripe\Response\Plans\ListPlansResponse', null, array('count' => $count, 'offset' => $offset));
return $this->client->get('plans', self::LIST_PLANS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
18 changes: 4 additions & 14 deletions src/Api/Recipients.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


use Stripe\Request\Recipients\CreateRecipientRequest;
use Stripe\Request\Recipients\ListRecipientsRequest;
use Stripe\Request\Recipients\UpdateRecipientRequest;
use Stripe\Response\DeleteResponse;
use Stripe\Response\Recipients\ListRecipientsResponse;
Expand Down Expand Up @@ -61,24 +62,13 @@ public function deleteRecipient($recipientId)
}

/**
* @param int $limit
* @param string $startingAfter
* @param bool $verified
* @param ListRecipientsRequest $request
* @return ListRecipientsResponse
* @link https://stripe.com/docs/api#list_recipients
*/
public function listRecipients($limit = 10, $startingAfter = null, $verified = null)
public function listRecipients(ListRecipientsRequest $request = null)
{
$request = array(
'limit' => $limit
);
if (!is_null($startingAfter)) {
$request['starting_after'] = $startingAfter;
}
if (!is_null($verified)) {
$request['verified'] = $verified;
}
return $this->client->get($this->buildUrl(), self::LIST_RECIPIENTS_RESPONSE_CLASS, null, $request);
return $this->client->get($this->buildUrl(), self::LIST_RECIPIENTS_RESPONSE_CLASS, null, $this->listRequestToParams($request));
}

/**
Expand Down
Loading

0 comments on commit fa91533

Please sign in to comment.