-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for flexible billing and usage records
- Loading branch information
1 parent
49860ea
commit bf9457c
Showing
4 changed files
with
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from stripe.api_resources.abstract.api_resource import APIResource | ||
from stripe import api_requestor, util | ||
|
||
|
||
class UsageRecord(APIResource): | ||
OBJECT_NAME = 'usage_record' | ||
|
||
@classmethod | ||
def create(cls, subscription_item, api_key=None, idempotency_key=None, | ||
stripe_version=None, stripe_account=None,**params): | ||
requestor = api_requestor.APIRequestor(api_key, | ||
api_version=stripe_version, | ||
account=stripe_account) | ||
url = "/v1/subscription_items/%s/usage_records" % subscription_item | ||
headers = util.populate_headers(idempotency_key) | ||
response, api_key = requestor.request('post', url, params, headers) | ||
|
||
return util.convert_to_stripe_object(response, api_key, stripe_version, | ||
stripe_account) |
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,22 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import stripe | ||
from tests.helper import StripeTestCase | ||
|
||
|
||
TEST_SUBSCRIPTION_ITEM_ID = 'si_123' | ||
|
||
|
||
class UsageRecordTest(StripeTestCase): | ||
def test_is_creatable(self): | ||
resource = stripe.UsageRecord.create( | ||
subscription_item=TEST_SUBSCRIPTION_ITEM_ID, | ||
quantity=123, | ||
timestamp=123123, | ||
action='increment', | ||
) | ||
self.assert_requested( | ||
'post', | ||
'/v1/subscription_items/%s/usage_records' % TEST_SUBSCRIPTION_ITEM_ID | ||
) | ||
self.assertIsInstance(resource, stripe.UsageRecord) |