-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Customer Balance Transaction resource and APIs
- Loading branch information
1 parent
578937e
commit 9580696
Showing
7 changed files
with
93 additions
and
2 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
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,25 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from stripe import util | ||
from stripe.api_resources.customer import Customer | ||
from stripe.api_resources.abstract import APIResource | ||
from stripe.six.moves.urllib.parse import quote_plus | ||
|
||
|
||
class CustomerBalanceTransaction(APIResource): | ||
OBJECT_NAME = "customer_balance_transaction" | ||
|
||
def instance_url(self): | ||
token = util.utf8(self.id) | ||
customer = util.utf8(self.customer) | ||
base = Customer.class_url() | ||
cust_extn = quote_plus(customer) | ||
extn = quote_plus(token) | ||
return "%s/%s/balance_transactions/%s" % (base, cust_extn, extn) | ||
|
||
@classmethod | ||
def retrieve(cls, id, api_key=None, **params): | ||
raise NotImplementedError( | ||
"Can't retrieve a Customer Balance Transaction without a Customer ID. " | ||
"Use Customer.retrieve_customer_balance_transaction('cus_123', 'cbtxn_123')" | ||
) |
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,32 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import pytest | ||
|
||
import stripe | ||
|
||
|
||
TEST_RESOURCE_ID = "cbtxn_123" | ||
|
||
|
||
class TestCustomerBalanceTransaction(object): | ||
def construct_resource(self): | ||
tax_id_dict = { | ||
"id": TEST_RESOURCE_ID, | ||
"object": "customer_balance_transaction", | ||
"customer": "cus_123", | ||
} | ||
return stripe.CustomerBalanceTransaction.construct_from( | ||
tax_id_dict, stripe.api_key | ||
) | ||
|
||
def test_has_instance_url(self, request_mock): | ||
resource = self.construct_resource() | ||
assert ( | ||
resource.instance_url() | ||
== "/v1/customers/cus_123/balance_transactions/%s" | ||
% TEST_RESOURCE_ID | ||
) | ||
|
||
def test_is_not_retrievable(self, request_mock): | ||
with pytest.raises(NotImplementedError): | ||
stripe.CustomerBalanceTransaction.retrieve(TEST_RESOURCE_ID) |
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