-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from stripe/alexander/flexible-billing
Flexible/Metered Billing API support
- Loading branch information
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class UsageRecord | ||
* | ||
* @package Stripe | ||
* | ||
* @property string $id | ||
* @property string $object | ||
* @property bool $livemode | ||
* @property int $quantity | ||
* @property string $subscription_item | ||
* @property int $timestamp | ||
*/ | ||
class UsageRecord extends ApiResource | ||
{ | ||
/** | ||
* @param array|null $params | ||
* @param array|string|null $options | ||
* | ||
* @return \Stripe\ApiResource The created resource. | ||
*/ | ||
public static function create($params = null, $options = null) | ||
{ | ||
self::_validateParams($params); | ||
if (!array_key_exists('subscription_item', $params)) { | ||
throw new Error\InvalidRequest("Missing subscription_item param in request", null); | ||
} | ||
$subscription_item = $params['subscription_item']; | ||
$url = "/v1/subscription_items/$subscription_item/usage_records"; | ||
$request_params = $params; | ||
unset($request_params['subscription_item']); | ||
|
||
list($response, $opts) = static::_staticRequest('post', $url, $request_params, $options); | ||
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts); | ||
$obj->setLastResponse($response); | ||
return $obj; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class UsageRecordTest extends TestCase | ||
{ | ||
const TEST_RESOURCE_ID = 'usage_record'; | ||
|
||
public function testIsCreatable() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/subscription_items/si_123/usage_records' | ||
); | ||
$resource = UsageRecord::create([ | ||
'subscription_item' => 'si_123', | ||
'quantity' => 100, | ||
'timestamp' => 12341234, | ||
'action' => 'set' | ||
]); | ||
$this->assertInstanceOf("Stripe\\UsageRecord", $resource); | ||
} | ||
|
||
/** | ||
* @expectedException \Stripe\Error\InvalidRequest | ||
*/ | ||
public function testThrowsIfSubscriptionItemIsMissing() | ||
{ | ||
UsageRecord::create([ | ||
'quantity' => 100, | ||
'timestamp' => 12341234, | ||
'action' => 'set' | ||
]); | ||
} | ||
} |