Skip to content

Commit

Permalink
API Updates (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe authored Oct 11, 2021
1 parent 87f27d3 commit 3917659
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
run: composer install --prefer-dist --no-progress --no-suggest

- name: Start stripe-mock
run: docker pull stripemock/stripe-mock && docker run -d -p 12111-12112:12111-12112 stripemock/stripe-mock && sleep 5
run: docker pull stripe/stripe-mock && docker run -d -p 12111-12112:12111-12112 stripe/stripe-mock && sleep 5

- name: Run test suite
run: |
Expand Down
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
11 changes: 11 additions & 0 deletions tests/Stripe/GeneratedExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2491,4 +2491,15 @@ 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',
['type' => 'card']
);
static::assertInstanceOf(\Stripe\Collection::class, $result);
static::assertInstanceOf(\Stripe\PaymentMethod::class, $result->data[0]);
}
}

0 comments on commit 3917659

Please sign in to comment.