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

Add Source::allSourceTransactions and SubscriptionItem::allUsageRecordSummaries #805

Merged
merged 3 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
17 changes: 17 additions & 0 deletions lib/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Source extends ApiResource
const OBJECT_NAME = 'source';

use ApiOperations\Create;
use ApiOperations\NestedResource;
use ApiOperations\Retrieve;
use ApiOperations\Update;

Expand Down Expand Up @@ -118,6 +119,8 @@ public function detach($params = null, $opts = null)
}

/**
* @deprecated sourceTransactions is deprecated. Please use Source::allSourceTransactions instead.
*
* @param array|null $params
* @param array|string|null $opts
*
Expand All @@ -134,6 +137,20 @@ public function sourceTransactions($params = null, $opts = null)
return $obj;
}

/**
* @param string $id
* @param array|null $params
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return Collection The list of source transactions.
*/
public static function allSourceTransactions($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, '/source_transactions', $params, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
Expand Down
16 changes: 16 additions & 0 deletions lib/SubscriptionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static function createUsageRecord($id, $params = null, $opts = null)
}

/**
* @deprecated usageRecordSummaries is deprecated. Please use SubscriptionItem::allUsageRecordSummaries instead.
*
* @param array|null $params
* @param array|string|null $opts
*
Expand All @@ -60,4 +62,18 @@ public function usageRecordSummaries($params = null, $opts = null)
$obj->setLastResponse($response);
return $obj;
}

/**
* @param string $id
* @param array|null $params
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return Collection The list of usage record summaries.
*/
public static function allUsageRecordSummaries($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, '/usage_record_summaries', $params, $opts);
}
}
14 changes: 13 additions & 1 deletion tests/Stripe/SourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testIsNotDetachableWhenUnattached()
$resource->detach();
}

public function testCanListSourceTransactions()
public function testCanListSourceTransactionsDeprecated()
{
$source = Source::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
Expand All @@ -121,6 +121,18 @@ public function testCanListSourceTransactions()
$this->assertInstanceOf(\Stripe\SourceTransaction::class, $resources->data[0]);
}

public function testCanListSourceTransactions()
{
$source_id = self::TEST_RESOURCE_ID;
rattrayalex-stripe marked this conversation as resolved.
Show resolved Hide resolved
$this->expectsRequest(
'get',
'/v1/sources/' . $source_id . "/source_transactions"
);
$resources = Source::allSourceTransactions($source_id);
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf(\Stripe\SourceTransaction::class, $resources->data[0]);
}

public function testCanVerify()
{
$resource = Source::retrieve(self::TEST_RESOURCE_ID);
Expand Down
13 changes: 12 additions & 1 deletion tests/Stripe/SubscriptionItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testCanCreateUsageRecord()
]);
}

public function testCanListUsageRecordSummaries()
public function testCanListUsageRecordSummariesDeprecated()
{
$resource = SubscriptionItem::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
Expand All @@ -104,4 +104,15 @@ public function testCanListUsageRecordSummaries()
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf(\Stripe\UsageRecordSummary::class, $resources->data[0]);
}

public function testCanListUsageRecordSummaries()
{
$this->expectsRequest(
'get',
'/v1/subscription_items/' . self::TEST_RESOURCE_ID . "/usage_record_summaries"
);
$resources =SubscriptionItem::allUsageRecordSummaries(self::TEST_RESOURCE_ID);
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf(\Stripe\UsageRecordSummary::class, $resources->data[0]);
}
}