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

API Updates #1188

Merged
merged 4 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions lib/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ public function deleteDiscount($params = null, $opts = null)
$this->refreshFrom(['discount' => null], $opts, true);
}

/**
* @param null|array $params
* @param null|array|string $opts
* @param mixed $id
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Collection list of PaymentMethods
*/
public static function allPaymentMethods($id, $params = null, $opts = null)
{
$url = static::resourceUrl($id) . '/payment_methods';
list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
$obj->setLastResponse($response);

return $obj;
}

const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';

/**
Expand Down
16 changes: 16 additions & 0 deletions lib/Service/CustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ public function allBalanceTransactions($parentId, $params = null, $opts = null)
return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/balance_transactions', $parentId), $params, $opts);
}

/**
* Returns a list of PaymentMethods for a given Customer.
*
* @param string $id
* @param null|array $params
* @param null|array|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Collection
*/
public function allPaymentMethods($id, $params = null, $opts = null)
{
return $this->requestCollection('get', $this->buildPath('/v1/customers/%s/payment_methods', $id), $params, $opts);
}

/**
* List sources for a specified customer.
*
Expand Down
8 changes: 8 additions & 0 deletions tests/Stripe/GeneratedExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2491,4 +2491,12 @@ public function testDeleteWebhookEndpoint()
$result = $this->client->webhookEndpoints->delete('we_xxxxxxxxxxxxx', []);
static::assertInstanceOf(\Stripe\WebhookEndpoint::class, $result);
}

public function testListPaymentMethodsCustomer()
{
$this->expectsRequest('get', '/v1/customers/cus_xyz/payment_methods');
$result = $this->client->customers->allPaymentMethods('cus_xyz', []);
static::assertInstanceOf(\Stripe\Collection::class, $result);
static::assertInstanceOf(\Stripe\Customer::class, $result->data[0]);
}
}