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 support for usage record summary #509

Merged
merged 1 commit into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ php:

env:
global:
- STRIPE_MOCK_VERSION=0.25.0
- STRIPE_MOCK_VERSION=0.26.0
matrix:
- AUTOLOAD=1
- AUTOLOAD=0
Expand Down
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
require(dirname(__FILE__) . '/lib/Transfer.php');
require(dirname(__FILE__) . '/lib/TransferReversal.php');
require(dirname(__FILE__) . '/lib/UsageRecord.php');
require(dirname(__FILE__) . '/lib/UsageRecordSummary.php');

// OAuth
require(dirname(__FILE__) . '/lib/OAuth.php');
Expand Down
15 changes: 15 additions & 0 deletions lib/SubscriptionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,19 @@ class SubscriptionItem extends ApiResource
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Collection The list of source transactions.
*/
public function usageRecordSummaries($params = null, $options = null)
{
$url = $this->instanceUrl() . '/usage_record_summaries';
list($response, $opts) = $this->_request('get', $url, $params, $options);
$obj = Util\Util::convertToStripeObject($response, $opts);
$obj->setLastResponse($response);
return $obj;
}
}
22 changes: 22 additions & 0 deletions lib/UsageRecordSummary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Stripe;

/**
* Class UsageRecord
*
* @package Stripe
*
* @property string $id
* @property string $object
* @property string $invoice
* @property bool $livemode
* @property mixed $period
* @property string $subscription_item
* @property int $total_usage
*/
class UsageRecordSummary extends ApiResource
{

const OBJECT_NAME = "usage_record_summary";
}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static function convertToStripeObject($resp, $opts)
\Stripe\Transfer::OBJECT_NAME => 'Stripe\\Transfer',
\Stripe\TransferReversal::OBJECT_NAME => 'Stripe\\TransferReversal',
\Stripe\UsageRecord::OBJECT_NAME => 'Stripe\\UsageRecord',
\Stripe\UsageRecordSummary::OBJECT_NAME => 'Stripe\\UsageRecordSummary',
];
if (self::isList($resp)) {
$mapped = [];
Expand Down
12 changes: 12 additions & 0 deletions tests/Stripe/SubscriptionItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ public function testIsDeletable()
$resource->delete();
$this->assertInstanceOf("Stripe\\SubscriptionItem", $resource);
}

public function testCanListUsageRecordSummaries()
{
$resource = SubscriptionItem::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'get',
'/v1/subscription_items/' . $resource->id . "/usage_record_summaries"
);
$resources = $resource->usageRecordSummaries();
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf("Stripe\\UsageRecordSummary", $resources->data[0]);
}
}
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define("MOCK_MINIMUM_VERSION", "0.25.0");
define("MOCK_MINIMUM_VERSION", "0.26.0");
define("MOCK_PORT", getenv("STRIPE_MOCK_PORT") ?: 12111);

// Send a request to stripe-mock
Expand Down