Skip to content

Commit

Permalink
support for flexible billing and usage records
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-stripe authored and ob-stripe committed Apr 14, 2018
1 parent 49860ea commit bf9457c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions stripe/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@
from stripe.api_resources.token import Token
from stripe.api_resources.topup import Topup
from stripe.api_resources.transfer import Transfer
from stripe.api_resources.usage_record import UsageRecord
21 changes: 21 additions & 0 deletions stripe/api_resources/usage_record.py
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)
1 change: 1 addition & 0 deletions stripe/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def load_object_classes():
api_resources.Token.OBJECT_NAME: api_resources.Token,
api_resources.Topup.OBJECT_NAME: api_resources.Topup,
api_resources.Transfer.OBJECT_NAME: api_resources.Transfer,
api_resources.UsageRecord.OBJECT_NAME: api_resources.UsageRecord,
}


Expand Down
22 changes: 22 additions & 0 deletions tests/api_resources/test_usage_record.py
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)

0 comments on commit bf9457c

Please sign in to comment.