Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Feb 26, 2020
1 parent 6ba0a23 commit 5b8209d
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 49 deletions.
15 changes: 15 additions & 0 deletions lib/Service/Checkout/SessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

class SessionService extends \Stripe\Service\AbstractService
{
/**
* Returns a list of Checkout Sessions.
*
* @param null|array $params
* @param null|array|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Collection
*/
public function all($params = null, $opts = null)
{
return $this->request('get', '/v1/checkout/sessions', $params, $opts);
}

/**
* Creates a Session object.
*
Expand Down
30 changes: 14 additions & 16 deletions lib/Service/SourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

class SourceService extends \Stripe\Service\AbstractService
{
/**
* @param string $id
* @param null|array $params
* @param null|array|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Source
*/
public function allTransactions($id, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/sources/%s/source_transactions', $id), $params, $opts);
}

/**
* Creates a new source object.
*
Expand Down Expand Up @@ -54,22 +68,6 @@ public function retrieve($id, $params = null, $opts = null)
return $this->request('get', $this->buildPath('/v1/sources/%s', $id), $params, $opts);
}

/**
* List source transactions for a given source.
*
* @param string $id
* @param null|array $params
* @param null|array|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Source
*/
public function sourceTransactions($id, $params = null, $opts = null)
{
return $this->request('get', $this->buildPath('/v1/sources/%s/source_transactions', $id), $params, $opts);
}

/**
* Updates the specified source by setting the values of the parameters passed. Any
* parameters not provided will be left unchanged.
Expand Down
14 changes: 14 additions & 0 deletions lib/Service/TransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ public function allReversals($parentId, $params = null, $opts = null)
return $this->request('get', $this->buildPath('/v1/transfers/%s/reversals', $parentId), $params, $opts);
}

/**
* @param string $id
* @param null|array $params
* @param null|array|\Stripe\Util\RequestOptions $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Transfer
*/
public function cancel($id, $params = null, $opts = null)
{
return $this->request('post', $this->buildPath('/v1/transfers/%s/cancel', $id), $params, $opts);
}

/**
* To send funds from your Stripe account to a connected account, you create a new
* transfer object. Your <a href="#balance">Stripe balance</a> must be able to
Expand Down
11 changes: 11 additions & 0 deletions tests/Stripe/Service/Checkout/SessionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ protected function setUpService()
$this->service = new SessionService($this->client);
}

public function testAll()
{
$this->expectsRequest(
'get',
'/v1/checkout/sessions'
);
$resources = $this->service->all();
static::assertInternalType('array', $resources->data);
static::assertInstanceOf(\Stripe\Checkout\Session::class, $resources->data[0]);
}

public function testCreate()
{
$this->expectsRequest(
Expand Down
10 changes: 5 additions & 5 deletions tests/Stripe/Service/ExchangeRateServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ protected function setUpService()

public function testAll()
{
$listRates = $this->service->all();
static::assertInternalType('array', $listRates->data);
static::assertSame('exchange_rate', $listRates->data[0]->object);
$resources = $this->service->all();
static::assertInternalType('array', $resources->data);
static::assertInstanceOf(\Stripe\ExchangeRate::class, $resources->data[0]);
}

public function testRetrieve()
{
$rates = $this->service->retrieve('usd');
static::assertSame('exchange_rate', $rates->object);
$resource = $this->service->retrieve('usd');
static::assertInstanceOf(\Stripe\ExchangeRate::class, $resource);
}
}
24 changes: 12 additions & 12 deletions tests/Stripe/Service/PayoutServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public function testAll()
static::assertInstanceOf(\Stripe\Payout::class, $resources->data[0]);
}

public function testRetrieve()
public function testCancel()
{
$this->expectsRequest(
'get',
'/v1/payouts/' . self::TEST_RESOURCE_ID
'post',
'/v1/payouts/' . self::TEST_RESOURCE_ID . '/cancel'
);
$resource = $this->service->retrieve(self::TEST_RESOURCE_ID);
$resource = $this->service->cancel(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\Payout::class, $resource);
}

Expand All @@ -61,25 +61,25 @@ public function testCreate()
static::assertInstanceOf(\Stripe\Payout::class, $resource);
}

public function testUpdate()
public function testRetrieve()
{
$this->expectsRequest(
'post',
'get',
'/v1/payouts/' . self::TEST_RESOURCE_ID
);
$resource = $this->service->update(self::TEST_RESOURCE_ID, [
'metadata' => ['key' => 'value'],
]);
$resource = $this->service->retrieve(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\Payout::class, $resource);
}

public function testCancel()
public function testUpdate()
{
$this->expectsRequest(
'post',
'/v1/payouts/' . self::TEST_RESOURCE_ID . '/cancel'
'/v1/payouts/' . self::TEST_RESOURCE_ID
);
$resource = $this->service->cancel(self::TEST_RESOURCE_ID);
$resource = $this->service->update(self::TEST_RESOURCE_ID, [
'metadata' => ['key' => 'value'],
]);
static::assertInstanceOf(\Stripe\Payout::class, $resource);
}
}
22 changes: 11 additions & 11 deletions tests/Stripe/Service/SourceServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ protected function setUpService()
$this->service = new SourceService($this->client);
}

public function testAllTransactions()
{
$this->expectsRequest(
'get',
'/v1/sources/' . self::TEST_RESOURCE_ID . '/source_transactions'
);
$resources = $this->service->allTransactions(self::TEST_RESOURCE_ID);
static::assertInternalType('array', $resources->data);
static::assertInstanceOf(\Stripe\SourceTransaction::class, $resources->data[0]);
}

public function testCreate()
{
$this->expectsRequest(
Expand Down Expand Up @@ -59,17 +70,6 @@ public function testRetrieve()
static::assertInstanceOf(\Stripe\Source::class, $resource);
}

public function testSourceTransactions()
{
$this->expectsRequest(
'get',
'/v1/sources/' . self::TEST_RESOURCE_ID . '/source_transactions'
);
$resources = $this->service->sourceTransactions(self::TEST_RESOURCE_ID);
static::assertInternalType('array', $resources->data);
static::assertInstanceOf(\Stripe\SourceTransaction::class, $resources->data[0]);
}

public function testUpdate()
{
$this->expectsRequest(
Expand Down
13 changes: 8 additions & 5 deletions tests/Stripe/Service/TransferServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ public function testAllReversals()

public function testCancel()
{
$transfer = $this->service->retrieve(self::TEST_RESOURCE_ID);

// stripe-mock does not support this anymore so we stub it
$this->stubRequest(
'post',
'/v1/transfers/' . $transfer->id . '/cancel'
'/v1/transfers/' . self::TEST_RESOURCE_ID . '/cancel',
[],
null,
false,
[
'object' => 'transfer',
],
);
$resource = $transfer->cancel();
$resource = $this->service->cancel(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\Transfer::class, $resource);
static::assertSame($resource, $transfer);
}

public function testCreate()
Expand Down

0 comments on commit 5b8209d

Please sign in to comment.