-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #590 from stripe/remi-setupintents
Add support for the `SetupIntent` resource and APIs
- Loading branch information
Showing
7 changed files
with
113 additions
and
5 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,27 @@ | ||
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 ListableAPIResource | ||
from stripe.api_resources.abstract import UpdateableAPIResource | ||
from stripe.api_resources.abstract import custom_method | ||
|
||
|
||
@custom_method("cancel", http_verb="post") | ||
@custom_method("confirm", http_verb="post") | ||
class SetupIntent( | ||
CreateableAPIResource, ListableAPIResource, UpdateableAPIResource | ||
): | ||
OBJECT_NAME = "setup_intent" | ||
|
||
def cancel(self, idempotency_key=None, **params): | ||
url = self.instance_url() + "/cancel" | ||
headers = util.populate_headers(idempotency_key) | ||
self.refresh_from(self.request("post", url, params, headers)) | ||
return self | ||
|
||
def confirm(self, idempotency_key=None, **params): | ||
url = self.instance_url() + "/confirm" | ||
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,79 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import stripe | ||
|
||
|
||
TEST_RESOURCE_ID = "seti_123" | ||
|
||
|
||
class TestSetupIntent(object): | ||
def test_is_listable(self, request_mock): | ||
resources = stripe.SetupIntent.list() | ||
request_mock.assert_requested("get", "/v1/setup_intents") | ||
assert isinstance(resources.data, list) | ||
assert isinstance(resources.data[0], stripe.SetupIntent) | ||
|
||
def test_is_retrievable(self, request_mock): | ||
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID) | ||
request_mock.assert_requested( | ||
"get", "/v1/setup_intents/%s" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.SetupIntent) | ||
|
||
def test_is_creatable(self, request_mock): | ||
resource = stripe.SetupIntent.create(payment_method_types=["card"]) | ||
request_mock.assert_requested("post", "/v1/setup_intents") | ||
assert isinstance(resource, stripe.SetupIntent) | ||
|
||
def test_is_modifiable(self, request_mock): | ||
resource = stripe.SetupIntent.modify( | ||
TEST_RESOURCE_ID, metadata={"key": "value"} | ||
) | ||
request_mock.assert_requested( | ||
"post", | ||
"/v1/setup_intents/%s" % TEST_RESOURCE_ID, | ||
{"metadata": {"key": "value"}}, | ||
) | ||
assert isinstance(resource, stripe.SetupIntent) | ||
|
||
def test_is_saveable(self, request_mock): | ||
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID) | ||
|
||
resource.metadata["key"] = "value" | ||
resource.save() | ||
request_mock.assert_requested( | ||
"post", | ||
"/v1/setup_intents/%s" % TEST_RESOURCE_ID, | ||
{"metadata": {"key": "value"}}, | ||
) | ||
assert isinstance(resource, stripe.SetupIntent) | ||
|
||
def test_can_cancel(self, request_mock): | ||
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID) | ||
resource.cancel() | ||
request_mock.assert_requested( | ||
"post", "/v1/setup_intents/%s/cancel" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.SetupIntent) | ||
|
||
def test_can_cancel_classmethod(self, request_mock): | ||
resource = stripe.SetupIntent.cancel(TEST_RESOURCE_ID) | ||
request_mock.assert_requested( | ||
"post", "/v1/setup_intents/%s/cancel" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.SetupIntent) | ||
|
||
def test_can_confirm(self, request_mock): | ||
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID) | ||
resource.confirm() | ||
request_mock.assert_requested( | ||
"post", "/v1/setup_intents/%s/confirm" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.SetupIntent) | ||
|
||
def test_can_confirm_classmethod(self, request_mock): | ||
resource = stripe.SetupIntent.confirm(TEST_RESOURCE_ID) | ||
request_mock.assert_requested( | ||
"post", "/v1/setup_intents/%s/confirm" % TEST_RESOURCE_ID | ||
) | ||
assert isinstance(resource, stripe.SetupIntent) |
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