Skip to content

Commit

Permalink
Get customer subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslorentsen committed Jul 11, 2019
1 parent 1fd864c commit de5c7db
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ public function updateCustomerCard($id, $token)
return json_decode($response->getBody());
}

/**
* @param string $id
*
* @return object
*
* @throws CustomerNotFoundException
*/
public function customerSubscriptions($id)
{
try {
$response = $this->client->get('/customer/' . $id . '/subscription');
} catch (ClientException $exception) {
$response = $exception->getResponse();
$json = json_decode($response->getBody());
if (404 === $json->error->status) {
throw new CustomerNotFoundException($json->error->message, $json->error->status, $exception);
}
throw $exception;
}
if (200 !== $response->getStatusCode()) {
return [];
}
return json_decode($response->getBody());
}

/**
* @param \Psr\Http\Message\ResponseInterface $response
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Provider/ResponseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public static function newCustomer()
];
}

/**
* @return Response[]
*/
public static function getCustomerSubscription()
{
return [
[[new Response(200, [], '[{}]')]]
];
}

/**
* @return Response[]
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ public function testUpdateCustomerEmail($responses)
$this->assertInternalType('object', $response);
}

/**
* @param Response[] $responses
*
* @dataProvider \Test\Provider\ResponseProvider::getCustomerSubscription()
*/
public function testCustomerSubscription($responses)
{
$client = $this->getClientMock($responses);
$this->instance->setClient($client);
$response = $this->instance->customerSubscriptions('cus_12345');
$this->assertCount(1, $response);
}

/**
* @param Response[] $responses
*
Expand Down

0 comments on commit de5c7db

Please sign in to comment.