Skip to content

Commit

Permalink
Merge pull request #590 from stripe/remi-setupintents
Browse files Browse the repository at this point in the history
Add support for the `SetupIntent` resource and APIs
  • Loading branch information
remi-stripe authored Jun 27, 2019
2 parents d6ef527 + 61983b8 commit 0f9f2ae
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cache:
env:
global:
# If changing this number, please also change it in `tests/conftest.py`.
- STRIPE_MOCK_VERSION=0.58.0
- STRIPE_MOCK_VERSION=0.60.0

before_install:
# Unpack and start stripe-mock so that the test suite can talk to it
Expand Down
1 change: 1 addition & 0 deletions stripe/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from stripe.api_resources.refund import Refund
from stripe.api_resources.reversal import Reversal
from stripe.api_resources.review import Review
from stripe.api_resources.setup_intent import SetupIntent
from stripe.api_resources.sku import SKU
from stripe.api_resources.source import Source
from stripe.api_resources.source_transaction import SourceTransaction
Expand Down
6 changes: 3 additions & 3 deletions stripe/api_resources/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

@custom_method("delete_discount", http_verb="delete", http_path="discount")
@nested_resource_class_methods(
"source", operations=["create", "retrieve", "update", "delete", "list"]
"balance_transaction", operations=["create", "retrieve", "update", "list"]
)
@nested_resource_class_methods(
"tax_id", operations=["create", "retrieve", "delete", "list"]
"source", operations=["create", "retrieve", "update", "delete", "list"]
)
@nested_resource_class_methods(
"balance_transaction", operations=["create", "retrieve", "update", "list"]
"tax_id", operations=["create", "retrieve", "delete", "list"]
)
class Customer(
CreateableAPIResource,
Expand Down
27 changes: 27 additions & 0 deletions stripe/api_resources/setup_intent.py
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
1 change: 1 addition & 0 deletions stripe/object_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
api_resources.reporting.ReportType.OBJECT_NAME: api_resources.reporting.ReportType,
api_resources.Reversal.OBJECT_NAME: api_resources.Reversal,
api_resources.Review.OBJECT_NAME: api_resources.Review,
api_resources.SetupIntent.OBJECT_NAME: api_resources.SetupIntent,
api_resources.sigma.ScheduledQueryRun.OBJECT_NAME: api_resources.sigma.ScheduledQueryRun,
api_resources.SKU.OBJECT_NAME: api_resources.SKU,
api_resources.Source.OBJECT_NAME: api_resources.Source,
Expand Down
79 changes: 79 additions & 0 deletions tests/api_resources/test_setup_intent.py
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)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


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

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

0 comments on commit 0f9f2ae

Please sign in to comment.