Skip to content

Commit 61983b8

Browse files
committed
Add support for the SetupIntent resource and APIs
1 parent d6ef527 commit 61983b8

File tree

7 files changed

+113
-5
lines changed

7 files changed

+113
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cache:
2525
env:
2626
global:
2727
# If changing this number, please also change it in `tests/conftest.py`.
28-
- STRIPE_MOCK_VERSION=0.58.0
28+
- STRIPE_MOCK_VERSION=0.60.0
2929

3030
before_install:
3131
# Unpack and start stripe-mock so that the test suite can talk to it

stripe/api_resources/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from stripe.api_resources.refund import Refund
5858
from stripe.api_resources.reversal import Reversal
5959
from stripe.api_resources.review import Review
60+
from stripe.api_resources.setup_intent import SetupIntent
6061
from stripe.api_resources.sku import SKU
6162
from stripe.api_resources.source import Source
6263
from stripe.api_resources.source_transaction import SourceTransaction

stripe/api_resources/customer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
@custom_method("delete_discount", http_verb="delete", http_path="discount")
1313
@nested_resource_class_methods(
14-
"source", operations=["create", "retrieve", "update", "delete", "list"]
14+
"balance_transaction", operations=["create", "retrieve", "update", "list"]
1515
)
1616
@nested_resource_class_methods(
17-
"tax_id", operations=["create", "retrieve", "delete", "list"]
17+
"source", operations=["create", "retrieve", "update", "delete", "list"]
1818
)
1919
@nested_resource_class_methods(
20-
"balance_transaction", operations=["create", "retrieve", "update", "list"]
20+
"tax_id", operations=["create", "retrieve", "delete", "list"]
2121
)
2222
class Customer(
2323
CreateableAPIResource,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
from stripe import util
4+
from stripe.api_resources.abstract import CreateableAPIResource
5+
from stripe.api_resources.abstract import ListableAPIResource
6+
from stripe.api_resources.abstract import UpdateableAPIResource
7+
from stripe.api_resources.abstract import custom_method
8+
9+
10+
@custom_method("cancel", http_verb="post")
11+
@custom_method("confirm", http_verb="post")
12+
class SetupIntent(
13+
CreateableAPIResource, ListableAPIResource, UpdateableAPIResource
14+
):
15+
OBJECT_NAME = "setup_intent"
16+
17+
def cancel(self, idempotency_key=None, **params):
18+
url = self.instance_url() + "/cancel"
19+
headers = util.populate_headers(idempotency_key)
20+
self.refresh_from(self.request("post", url, params, headers))
21+
return self
22+
23+
def confirm(self, idempotency_key=None, **params):
24+
url = self.instance_url() + "/confirm"
25+
headers = util.populate_headers(idempotency_key)
26+
self.refresh_from(self.request("post", url, params, headers))
27+
return self

stripe/object_classes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
api_resources.reporting.ReportType.OBJECT_NAME: api_resources.reporting.ReportType,
6464
api_resources.Reversal.OBJECT_NAME: api_resources.Reversal,
6565
api_resources.Review.OBJECT_NAME: api_resources.Review,
66+
api_resources.SetupIntent.OBJECT_NAME: api_resources.SetupIntent,
6667
api_resources.sigma.ScheduledQueryRun.OBJECT_NAME: api_resources.sigma.ScheduledQueryRun,
6768
api_resources.SKU.OBJECT_NAME: api_resources.SKU,
6869
api_resources.Source.OBJECT_NAME: api_resources.Source,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
import stripe
4+
5+
6+
TEST_RESOURCE_ID = "seti_123"
7+
8+
9+
class TestSetupIntent(object):
10+
def test_is_listable(self, request_mock):
11+
resources = stripe.SetupIntent.list()
12+
request_mock.assert_requested("get", "/v1/setup_intents")
13+
assert isinstance(resources.data, list)
14+
assert isinstance(resources.data[0], stripe.SetupIntent)
15+
16+
def test_is_retrievable(self, request_mock):
17+
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID)
18+
request_mock.assert_requested(
19+
"get", "/v1/setup_intents/%s" % TEST_RESOURCE_ID
20+
)
21+
assert isinstance(resource, stripe.SetupIntent)
22+
23+
def test_is_creatable(self, request_mock):
24+
resource = stripe.SetupIntent.create(payment_method_types=["card"])
25+
request_mock.assert_requested("post", "/v1/setup_intents")
26+
assert isinstance(resource, stripe.SetupIntent)
27+
28+
def test_is_modifiable(self, request_mock):
29+
resource = stripe.SetupIntent.modify(
30+
TEST_RESOURCE_ID, metadata={"key": "value"}
31+
)
32+
request_mock.assert_requested(
33+
"post",
34+
"/v1/setup_intents/%s" % TEST_RESOURCE_ID,
35+
{"metadata": {"key": "value"}},
36+
)
37+
assert isinstance(resource, stripe.SetupIntent)
38+
39+
def test_is_saveable(self, request_mock):
40+
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID)
41+
42+
resource.metadata["key"] = "value"
43+
resource.save()
44+
request_mock.assert_requested(
45+
"post",
46+
"/v1/setup_intents/%s" % TEST_RESOURCE_ID,
47+
{"metadata": {"key": "value"}},
48+
)
49+
assert isinstance(resource, stripe.SetupIntent)
50+
51+
def test_can_cancel(self, request_mock):
52+
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID)
53+
resource.cancel()
54+
request_mock.assert_requested(
55+
"post", "/v1/setup_intents/%s/cancel" % TEST_RESOURCE_ID
56+
)
57+
assert isinstance(resource, stripe.SetupIntent)
58+
59+
def test_can_cancel_classmethod(self, request_mock):
60+
resource = stripe.SetupIntent.cancel(TEST_RESOURCE_ID)
61+
request_mock.assert_requested(
62+
"post", "/v1/setup_intents/%s/cancel" % TEST_RESOURCE_ID
63+
)
64+
assert isinstance(resource, stripe.SetupIntent)
65+
66+
def test_can_confirm(self, request_mock):
67+
resource = stripe.SetupIntent.retrieve(TEST_RESOURCE_ID)
68+
resource.confirm()
69+
request_mock.assert_requested(
70+
"post", "/v1/setup_intents/%s/confirm" % TEST_RESOURCE_ID
71+
)
72+
assert isinstance(resource, stripe.SetupIntent)
73+
74+
def test_can_confirm_classmethod(self, request_mock):
75+
resource = stripe.SetupIntent.confirm(TEST_RESOURCE_ID)
76+
request_mock.assert_requested(
77+
"post", "/v1/setup_intents/%s/confirm" % TEST_RESOURCE_ID
78+
)
79+
assert isinstance(resource, stripe.SetupIntent)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
# When changing this number, don't forget to change it in `.travis.yml` too.
19-
MOCK_MINIMUM_VERSION = "0.58.0"
19+
MOCK_MINIMUM_VERSION = "0.60.0"
2020

2121
# Starts stripe-mock if an OpenAPI spec override is found in `openapi/`, and
2222
# otherwise fall back to `STRIPE_MOCK_PORT` or 12111.

0 commit comments

Comments
 (0)