Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Issuing APIs/resources #455

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cache:

env:
global:
- STRIPE_MOCK_VERSION=0.19.0
- STRIPE_MOCK_VERSION=0.23.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/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# API resources
from stripe.api_resources import * # noqa
from stripe.api_resources import issuing # noqa

# OAuth
from stripe.oauth import OAuth # noqa
Expand Down
10 changes: 10 additions & 0 deletions stripe/api_resources/issuing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import absolute_import, division, print_function

# flake8: noqa

from stripe.api_resources.issuing.authorization import Authorization
from stripe.api_resources.issuing.card import Card
from stripe.api_resources.issuing.card_details import CardDetails
from stripe.api_resources.issuing.cardholder import Cardholder
from stripe.api_resources.issuing.dispute import Dispute
from stripe.api_resources.issuing.transaction import Transaction
21 changes: 21 additions & 0 deletions stripe/api_resources/issuing/authorization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import absolute_import, division, print_function

from stripe import util
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Authorization(ListableAPIResource, UpdateableAPIResource):
OBJECT_NAME = 'issuing.authorization'

def approve(self, idempotency_key=None, **params):
url = self.instance_url() + '/approve'
headers = util.populate_headers(idempotency_key)
self.refresh_from(self.request('post', url, params, headers))
return self

def decline(self, idempotency_key=None, **params):
url = self.instance_url() + '/decline'
headers = util.populate_headers(idempotency_key)
self.refresh_from(self.request('post', url, params, headers))
return self
14 changes: 14 additions & 0 deletions stripe/api_resources/issuing/card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Card(CreateableAPIResource, ListableAPIResource,
UpdateableAPIResource):
OBJECT_NAME = 'issuing.card'

def details(self, idempotency_key=None, **params):
return self.request(
'get', self.instance_url() + '/details', params)
7 changes: 7 additions & 0 deletions stripe/api_resources/issuing/card_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import absolute_import, division, print_function

from stripe.stripe_object import StripeObject


class CardDetails(StripeObject):
OBJECT_NAME = 'issuing.card_details'
10 changes: 10 additions & 0 deletions stripe/api_resources/issuing/cardholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Cardholder(CreateableAPIResource, ListableAPIResource,
UpdateableAPIResource):
OBJECT_NAME = 'issuing.cardholder'
10 changes: 10 additions & 0 deletions stripe/api_resources/issuing/dispute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Dispute(CreateableAPIResource, ListableAPIResource,
UpdateableAPIResource):
OBJECT_NAME = 'issuing.dispute'
8 changes: 8 additions & 0 deletions stripe/api_resources/issuing/transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource


class Transaction(ListableAPIResource, UpdateableAPIResource):
OBJECT_NAME = 'issuing.transaction'
11 changes: 11 additions & 0 deletions stripe/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ def load_object_classes():
api_resources.InvoiceLineItem,
api_resources.IssuerFraudRecord.OBJECT_NAME:
api_resources.IssuerFraudRecord,
api_resources.issuing.Authorization.OBJECT_NAME:
api_resources.issuing.Authorization,
api_resources.issuing.Card.OBJECT_NAME: api_resources.issuing.Card,
api_resources.issuing.CardDetails.OBJECT_NAME:
api_resources.issuing.CardDetails,
api_resources.issuing.Cardholder.OBJECT_NAME:
api_resources.issuing.Cardholder,
api_resources.issuing.Dispute.OBJECT_NAME:
api_resources.issuing.Dispute,
api_resources.issuing.Transaction.OBJECT_NAME:
api_resources.issuing.Transaction,
api_resources.LoginLink.OBJECT_NAME: api_resources.LoginLink,
api_resources.Order.OBJECT_NAME: api_resources.Order,
api_resources.OrderReturn.OBJECT_NAME: api_resources.OrderReturn,
Expand Down
67 changes: 67 additions & 0 deletions tests/api_resources/issuing/test_authorization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'iauth_123'


class TestAuthorization(object):
def test_is_listable(self, request_mock):
resources = stripe.issuing.Authorization.list()
request_mock.assert_requested(
'get',
'/v1/issuing/authorizations'
)
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.issuing.Authorization)

def test_is_modifiable(self, request_mock):
resource = stripe.issuing.Authorization.modify(
TEST_RESOURCE_ID,
metadata={'key': 'value'}
)
request_mock.assert_requested(
'post',
'/v1/issuing/authorizations/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Authorization)

def test_is_retrievable(self, request_mock):
resource = stripe.issuing.Authorization.retrieve(TEST_RESOURCE_ID)
request_mock.assert_requested(
'get',
'/v1/issuing/authorizations/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Authorization)

def test_is_saveable(self, request_mock):
resource = stripe.issuing.Authorization.retrieve(TEST_RESOURCE_ID)
resource.metadata['key'] = 'value'
authorization = resource.save()
request_mock.assert_requested(
'post',
'/v1/issuing/authorizations/%s' % resource.id
)
assert isinstance(resource, stripe.issuing.Authorization)
assert resource is authorization

def test_is_approveable(self, request_mock):
resource = stripe.issuing.Authorization.retrieve(TEST_RESOURCE_ID)
authorization = resource.approve()
request_mock.assert_requested(
'post',
'/v1/issuing/authorizations/%s/approve' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Authorization)
assert resource is authorization

def test_is_declineable(self, request_mock):
resource = stripe.issuing.Authorization.retrieve(TEST_RESOURCE_ID)
authorization = resource.decline()
request_mock.assert_requested(
'post',
'/v1/issuing/authorizations/%s/decline' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Authorization)
assert resource is authorization
67 changes: 67 additions & 0 deletions tests/api_resources/issuing/test_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'ic_123'


class TestCard(object):
def test_is_creatable(self, request_mock):
resource = stripe.issuing.Card.create(
currency='usd',
type='physical'
)
request_mock.assert_requested(
'post',
'/v1/issuing/cards'
)
assert isinstance(resource, stripe.issuing.Card)

def test_is_listable(self, request_mock):
resources = stripe.issuing.Card.list()
request_mock.assert_requested(
'get',
'/v1/issuing/cards'
)
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.issuing.Card)

def test_is_modifiable(self, request_mock):
resource = stripe.issuing.Card.modify(
TEST_RESOURCE_ID,
metadata={'key': 'value'}
)
request_mock.assert_requested(
'post',
'/v1/issuing/cards/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Card)

def test_is_retrievable(self, request_mock):
resource = stripe.issuing.Card.retrieve(TEST_RESOURCE_ID)
request_mock.assert_requested(
'get',
'/v1/issuing/cards/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Card)

def test_is_saveable(self, request_mock):
resource = stripe.issuing.Card.retrieve(TEST_RESOURCE_ID)
resource.metadata['key'] = 'value'
card = resource.save()
request_mock.assert_requested(
'post',
'/v1/issuing/cards/%s' % resource.id
)
assert isinstance(resource, stripe.issuing.Card)
assert resource is card

def test_can_retrieve_details(self, request_mock):
resource = stripe.issuing.Card.retrieve(TEST_RESOURCE_ID)
card_details = resource.details()
request_mock.assert_requested(
'get',
'/v1/issuing/cards/%s/details' % resource.id
)
assert isinstance(card_details, stripe.issuing.CardDetails)
66 changes: 66 additions & 0 deletions tests/api_resources/issuing/test_cardholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'ich_123'


class TestCardholder(object):
def test_is_creatable(self, request_mock):
resource = stripe.issuing.Cardholder.create(
billing={
'address': {
'city': 'city',
'country': 'US',
'line1': 'line1',
'postal_code': 'postal_code',
},
},
name='Jenny Rosen',
type='individual'
)
request_mock.assert_requested(
'post',
'/v1/issuing/cardholders'
)
assert isinstance(resource, stripe.issuing.Cardholder)

def test_is_listable(self, request_mock):
resources = stripe.issuing.Cardholder.list()
request_mock.assert_requested(
'get',
'/v1/issuing/cardholders'
)
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.issuing.Cardholder)

def test_is_modifiable(self, request_mock):
resource = stripe.issuing.Cardholder.modify(
TEST_RESOURCE_ID,
metadata={'key': 'value'}
)
request_mock.assert_requested(
'post',
'/v1/issuing/cardholders/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Cardholder)

def test_is_retrievable(self, request_mock):
resource = stripe.issuing.Cardholder.retrieve(TEST_RESOURCE_ID)
request_mock.assert_requested(
'get',
'/v1/issuing/cardholders/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Cardholder)

def test_is_saveable(self, request_mock):
resource = stripe.issuing.Cardholder.retrieve(TEST_RESOURCE_ID)
resource.metadata['key'] = 'value'
cardholder = resource.save()
request_mock.assert_requested(
'post',
'/v1/issuing/cardholders/%s' % resource.id
)
assert isinstance(resource, stripe.issuing.Cardholder)
assert resource is cardholder
58 changes: 58 additions & 0 deletions tests/api_resources/issuing/test_dispute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import absolute_import, division, print_function

import stripe


TEST_RESOURCE_ID = 'idp_123'


class TestDispute(object):
def test_is_creatable(self, request_mock):
resource = stripe.issuing.Dispute.create(
reason='fraudulent',
transaction='ipi_123'
)
request_mock.assert_requested(
'post',
'/v1/issuing/disputes'
)
assert isinstance(resource, stripe.issuing.Dispute)

def test_is_listable(self, request_mock):
resources = stripe.issuing.Dispute.list()
request_mock.assert_requested(
'get',
'/v1/issuing/disputes'
)
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.issuing.Dispute)

def test_is_modifiable(self, request_mock):
resource = stripe.issuing.Dispute.modify(
TEST_RESOURCE_ID,
metadata={'key': 'value'}
)
request_mock.assert_requested(
'post',
'/v1/issuing/disputes/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Dispute)

def test_is_retrievable(self, request_mock):
resource = stripe.issuing.Dispute.retrieve(TEST_RESOURCE_ID)
request_mock.assert_requested(
'get',
'/v1/issuing/disputes/%s' % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.issuing.Dispute)

def test_is_saveable(self, request_mock):
resource = stripe.issuing.Dispute.retrieve(TEST_RESOURCE_ID)
resource.metadata['key'] = 'value'
dispute = resource.save()
request_mock.assert_requested(
'post',
'/v1/issuing/disputes/%s' % resource.id
)
assert isinstance(resource, stripe.issuing.Dispute)
assert resource is dispute
Loading