Skip to content

Commit

Permalink
Add support for /v1/topups endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkakar-stripe committed Feb 16, 2018
1 parent 689baae commit 912f505
Show file tree
Hide file tree
Showing 4 changed files with 67 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 @@ -43,4 +43,5 @@
from stripe.api_resources.subscription_item import SubscriptionItem
from stripe.api_resources.three_d_secure import ThreeDSecure
from stripe.api_resources.token import Token
from stripe.api_resources.topup import Topup
from stripe.api_resources.transfer import Transfer
7 changes: 7 additions & 0 deletions stripe/api_resources/topup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Topup(CreateableAPIResource, ListableAPIResource, UpdateableAPIResource):
OBJECT_NAME = 'topup'
1 change: 1 addition & 0 deletions stripe/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def load_object_classes():
api_resources.SubscriptionItem,
api_resources.ThreeDSecure.OBJECT_NAME: api_resources.ThreeDSecure,
api_resources.Token.OBJECT_NAME: api_resources.Token,
api_resources.Topup.OBJECT_NAME: api_resources.Topup,
api_resources.Transfer.OBJECT_NAME: api_resources.Transfer,
}

Expand Down
58 changes: 58 additions & 0 deletions tests/api_resources/test_topup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import stripe
from tests.helper import StripeTestCase


TEST_RESOURCE_ID = 'tu_123'


class TopupTest(StripeTestCase):
def test_is_listable(self):
resources = stripe.Topup.list()
self.assert_requested(
'get',
'/v1/topups'
)
self.assertIsInstance(resources.data, list)
self.assertIsInstance(resources.data[0], stripe.Topup)

def test_is_retrievable(self):
resource = stripe.Topup.retrieve(TEST_RESOURCE_ID)
self.assert_requested(
'get',
'/v1/topups/%s' % TEST_RESOURCE_ID
)
self.assertIsInstance(resource, stripe.Topup)

def test_is_creatable(self):
resource = stripe.Topup.create(
amount=100,
currency='usd',
source='src_123',
description='description',
statement_descriptor='statement descriptor'
)
self.assert_requested(
'post',
'/v1/topups'
)
self.assertIsInstance(resource, stripe.Topup)

def test_is_saveable(self):
resource = stripe.Topup.retrieve(TEST_RESOURCE_ID)
resource.metadata['key'] = 'value'
resource.save()
self.assert_requested(
'post',
'/v1/topups/%s' % resource.id
)

def test_is_modifiable(self):
resource = stripe.Topup.modify(
TEST_RESOURCE_ID,
metadata={'key': 'value'}
)
self.assert_requested(
'post',
'/v1/topups/%s' % TEST_RESOURCE_ID
)
self.assertIsInstance(resource, stripe.Topup)

0 comments on commit 912f505

Please sign in to comment.