Skip to content

Commit

Permalink
Add support for the PaymentIntent resource
Browse files Browse the repository at this point in the history
This is gated so for now the tests are stubbed.
  • Loading branch information
remi-stripe committed Jun 27, 2018
1 parent 735511c commit e06c0c7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions stripe/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions stripe/api_resources/payment_intent.py
Original file line number Diff line number Diff line change
@@ -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 = 'subscription_item'

@classmethod
def class_name(cls):
return 'subscription_item'

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
64 changes: 64 additions & 0 deletions tests/api_resources/test_payment_intent.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e06c0c7

Please sign in to comment.