From 9d4a36b2ecde5b8872f4d449950f3fe113b2646c Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Wed, 27 Jun 2018 17:26:53 -0400 Subject: [PATCH] Add support for the PaymentIntent resource This is gated so for now the tests are stubbed. --- stripe/api_resources/__init__.py | 1 + stripe/api_resources/payment_intent.py | 34 ++++++++++++ tests/api_resources/test_payment_intent.py | 64 ++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 stripe/api_resources/payment_intent.py create mode 100644 tests/api_resources/test_payment_intent.py diff --git a/stripe/api_resources/__init__.py b/stripe/api_resources/__init__.py index d6bbc090a..58354ab82 100644 --- a/stripe/api_resources/__init__.py +++ b/stripe/api_resources/__init__.py @@ -30,6 +30,7 @@ from stripe.api_resources.login_link import LoginLink from stripe.api_resources.order import Order from stripe.api_resources.order_return import OrderReturn +from stripe.api_resources.payment_intent import PaymentIntent from stripe.api_resources.payout import Payout from stripe.api_resources.plan import Plan from stripe.api_resources.product import Product diff --git a/stripe/api_resources/payment_intent.py b/stripe/api_resources/payment_intent.py new file mode 100644 index 000000000..ab6d82686 --- /dev/null +++ b/stripe/api_resources/payment_intent.py @@ -0,0 +1,34 @@ +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 DeletableAPIResource +from stripe.api_resources.abstract import UpdateableAPIResource +from stripe.api_resources.abstract import ListableAPIResource + + +class PaymentIntent(CreateableAPIResource, DeletableAPIResource, + UpdateableAPIResource, ListableAPIResource): + OBJECT_NAME = 'payment_intent' + + @classmethod + def class_name(cls): + return 'payment_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 capture(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() + '/cancel' + headers = util.populate_headers(idempotency_key) + self.refresh_from(self.request('post', url, params, headers)) + return self diff --git a/tests/api_resources/test_payment_intent.py b/tests/api_resources/test_payment_intent.py new file mode 100644 index 000000000..d17664141 --- /dev/null +++ b/tests/api_resources/test_payment_intent.py @@ -0,0 +1,64 @@ +from __future__ import absolute_import, division, print_function + +import stripe +from tests.helper import StripeTestCase + + +TEST_RESOURCE_ID = 'pi_123' + + +class PaymentIntentTest(StripeTestCase): + FIXTURE = { + 'id': TEST_RESOURCE_ID, + 'object': 'payment_intent' + } + + def test_is_listable(self): + self.stub_request( + 'get', + '/v1/payment_intents', + { + 'object': 'list', + 'data': [self.FIXTURE], + } + ) + + resources = stripe.PaymentIntent.list() + self.assert_requested( + 'get', + '/v1/payment_intents' + ) + self.assertIsInstance(resources.data, list) + self.assertIsInstance(resources.data[0], stripe.PaymentIntent) + + def test_is_retrievable(self): + self.stub_request( + 'get', + '/v1/payment_intents/%s' % TEST_RESOURCE_ID, + self.FIXTURE + ) + + resource = stripe.PaymentIntent.retrieve(TEST_RESOURCE_ID) + self.assert_requested( + 'get', + '/v1/payment_intents/%s' % TEST_RESOURCE_ID + ) + self.assertIsInstance(resource, stripe.PaymentIntent) + + def test_is_creatable(self): + self.stub_request( + 'post', + '/v1/payment_intents', + self.FIXTURE + ) + + resource = stripe.PaymentIntent.create( + allowed_source_types=['card'], + amount='1234', + currency='amount' + ) + self.assert_requested( + 'post', + '/v1/payment_intents', + ) + self.assertIsInstance(resource, stripe.PaymentIntent)