-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the PaymentIntent resource
This is gated so for now the tests are stubbed.
- Loading branch information
1 parent
735511c
commit 9d4a36b
Showing
3 changed files
with
99 additions
and
0 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
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 = '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 |
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,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) |