-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e33fc85
commit e924dee
Showing
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from stripe import util | ||
from stripe.api_resources.abstract import CreateableAPIResource | ||
from stripe.api_resources.abstract import UpdateableAPIResource | ||
from stripe.api_resources.abstract import ListableAPIResource | ||
from stripe.api_resources.abstract import custom_method | ||
|
||
|
||
@custom_method("void_credit_note", http_verb="post", http_path="void") | ||
class CreditNote( | ||
CreateableAPIResource, UpdateableAPIResource, ListableAPIResource | ||
): | ||
OBJECT_NAME = "credit_note" | ||
|
||
def void_credit_note(self, idempotency_key=None, **params): | ||
url = self.instance_url() + "/void" | ||
headers = util.populate_headers(idempotency_key) | ||
self.refresh_from(self.request("post", url, params, headers)) | ||
return self |
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,60 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import stripe | ||
|
||
|
||
TEST_RESOURCE_ID = "cn_123" | ||
|
||
|
||
class TestCreditNote(object): | ||
def test_is_listable(self, request_mock): | ||
resources = stripe.CreditNote.list() | ||
request_mock.assert_requested("get", "/v1/credit_notes") | ||
assert isinstance(resources.data, list) | ||
assert isinstance(resources.data[0], stripe.CreditNote) | ||
|
||
def test_is_retrievable(self, request_mock): | ||
resource = stripe.CreditNote.retrieve(TEST_RESOURCE_ID) | ||
request_mock.assert_requested( | ||
"get", "/v1/credit_notes/%s" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.CreditNote) | ||
|
||
def test_is_creatable(self, request_mock): | ||
resource = stripe.CreditNote.create( | ||
amount=100, invoice="in_123", reason="duplicate" | ||
) | ||
request_mock.assert_requested("post", "/v1/credit_notes") | ||
assert isinstance(resource, stripe.CreditNote) | ||
|
||
def test_is_saveable(self, request_mock): | ||
resource = stripe.CreditNote.retrieve(TEST_RESOURCE_ID) | ||
resource.metadata["key"] = "value" | ||
resource.save() | ||
request_mock.assert_requested( | ||
"post", "/v1/credit_notes/%s" % TEST_RESOURCE_ID | ||
) | ||
|
||
def test_is_modifiable(self, request_mock): | ||
resource = stripe.CreditNote.modify( | ||
TEST_RESOURCE_ID, metadata={"key": "value"} | ||
) | ||
request_mock.assert_requested( | ||
"post", "/v1/credit_notes/%s" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.CreditNote) | ||
|
||
def test_can_void_credit_note(self, request_mock): | ||
resource = stripe.CreditNote.retrieve(TEST_RESOURCE_ID) | ||
resource = resource.void_credit_note() | ||
request_mock.assert_requested( | ||
"post", "/v1/credit_notes/%s/void" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.CreditNote) | ||
|
||
def test_can_void_credit_note_classmethod(self, request_mock): | ||
resource = stripe.CreditNote.void_credit_note(TEST_RESOURCE_ID) | ||
request_mock.assert_requested( | ||
"post", "/v1/credit_notes/%s/void" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.CreditNote) |