From fe36d083f0a4e9f7916320aded9b66d501ae971c Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Sun, 25 Feb 2018 14:34:24 +0100 Subject: [PATCH] Remove deprecated code --- bin/stripe | 344 ------------------ setup.py | 1 - stripe/__init__.py | 43 +-- stripe/api_requestor.py | 131 ------- .../abstract/listable_api_resource.py | 10 - stripe/api_resources/customer.py | 61 +--- stripe/api_resources/ephemeral_key.py | 17 +- stripe/api_resources/list_object.py | 9 - stripe/api_resources/recipient.py | 6 - stripe/api_resources/source.py | 9 - stripe/api_resources/subscription.py | 3 +- stripe/api_resources/topup.py | 2 + stripe/resource.py | 38 -- stripe/stripe_object.py | 7 - tests/api_resources/test_customer.py | 90 ----- tests/api_resources/test_ephemeral_key.py | 21 -- tests/api_resources/test_recipient.py | 11 - tests/api_resources/test_source.py | 16 - tests/test_error.py | 8 +- 19 files changed, 14 insertions(+), 813 deletions(-) delete mode 100755 bin/stripe delete mode 100644 stripe/resource.py diff --git a/bin/stripe b/bin/stripe deleted file mode 100755 index b85a83e5c..000000000 --- a/bin/stripe +++ /dev/null @@ -1,344 +0,0 @@ -#!/usr/bin/env python - -# WARNING: This client is now deprecated and will be removed in version 2.0 - -import logging -import optparse -import os -import re -import subprocess -import sys -import warnings - -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) -import stripe - -logger = logging.getLogger('') -logger.addHandler(logging.StreamHandler(sys.stderr)) -logger.setLevel(logging.INFO) - -class APIResourceClient(object): - def __init__(self, id=None): - self.id = id - - def to_dict(self, params): - dict = {} - for k, v in params: - dict[k] = v - return dict - - def logged_curl(self, method, url, params): - dict_params = self.to_dict(params) - self.log_request(method, url, params, dict_params) - rbody, rcode, _ = stripe.APIRequestor().request_raw(method, url, dict_params) - self.log_result(rbody, rcode) - return rbody, rcode - - def log_request(self, method, url, ordered_params, dict_params): - if method.lower() == 'get': - requestor = stripe.APIRequestor() - if dict_params: - url = '%s?%s' % (url, stripe.APIRequestor().encode(dict_params)) - ordered_params = [] - elif not ordered_params: - ordered_params = ' -X %s' % (method.upper(), ) - - logger.info('Running the equivalent of:') - logger.info('--') - if len(ordered_params): - term = ' \\' - else: - term = '' - curl = ['curl %s%s -H "Authorization: Bearer %s"%s' % (stripe.api_base, url, stripe.api_key, term)] - if isinstance(ordered_params, list): - for i, (k, v) in enumerate(ordered_params): - if i == len(ordered_params) - 1: - term = '' - else: - term = ' \\' - curl.append(' -d %s=%s%s' % (k, v, term)) - else: - curl.append(ordered_params) - logger.info('\n'.join(curl)) - logger.info('--') - - def log_result(self, rbody, rcode): - logger.info('Result (HTTP status code %d):' % (rcode, )) - logger.info('--') - logger.info(rbody.rstrip()) - logger.info('--') - - def class_url(self): - return self.client_for.class_url() - - def instance_url(self): - if not self.id: - raise ValueError('ID required. (HINT: provide the script a -i ID)') - return self.client_for(self.id).instance_url() - - def retrieve(self, params): - url = self.instance_url() - self.logged_curl('get', url, []) - -class ListableAPIResourceClient(APIResourceClient): - def all(self, params): - url = self.class_url() - self.logged_curl('get', url, params) - -class CreateableAPIResourceClient(APIResourceClient): - def create(self, params): - url = self.class_url() - self.logged_curl('post', url, params) - -class UpdateableAPIResourceClient(APIResourceClient): - def update(self, params): - url = self.instance_url() - self.logged_curl('post', url, params) - -class DeletableAPIResourceClient(APIResourceClient): - def delete(self, params): - url = self.instance_url() - self.logged_curl('delete', url, params) - -# API objects -class AccountClient(APIResourceClient): - client_for = stripe.Account - -class CardClient(UpdateableAPIResourceClient, DeletableAPIResourceClient): - client_for = stripe.Card - -class ChargeClient(CreateableAPIResourceClient, ListableAPIResourceClient): - client_for = stripe.Charge - - def refund(self, params): - url = self.instance_url() + '/refund' - self.logged_curl('post', url, params) - - def capture(self, params): - url = self.instance_url() + '/capture' - self.logged_curl('post', url, params) - - def update_dispute(self, params): - url = self.instance_url() + '/dispute' - self.logged_curl('post', url, params) - - def close_dispute(self): - url = self.instance_url() + '/dispute/close' - self.logged_curl('post', url, {}) - - -class CustomerClient(CreateableAPIResourceClient, UpdateableAPIResourceClient, - ListableAPIResourceClient, DeletableAPIResourceClient): - client_for = stripe.Customer - - def add_invoice_item(self, params): - params = params.copy() - params.append(['customer', self.id]) - InvoiceItemClient.create(params) - - def invoices(self, params): - params = params.copy() - params.append(['customer', self.id]) - InvoiceClient.all(params) - - def invoice_items(self, params): - params = params.copy() - params.append(['customer', self.id]) - InvoiceItem.all(params) - - def charges(self, params): - params = params.copy() - params.append(['customer', self.id]) - ChargeClient.all(params) - - def update_subscription(self, params): - url = self.instance_url() + '/subscription' - self.logged_curl('post', url, params) - - def cancel_subscription(self, params): - url = self.instance_url() + '/subscription' - self.logged_curl('delete', url, params) - -class InvoiceClient(CreateableAPIResourceClient, ListableAPIResourceClient, UpdateableAPIResourceClient): - client_for = stripe.Invoice - - def pay(self): - url = self.instance_url() + '/pay' - self.logged_curl('post', url, {}) - - @classmethod - def upcoming(cls, params): - url = cls.client_for.class_url() + '/upcoming' - cls().logged_curl('get', url, params) - -class InvoiceItemClient(CreateableAPIResourceClient, UpdateableAPIResourceClient, - ListableAPIResourceClient, DeletableAPIResourceClient): - client_for = stripe.InvoiceItem - -class PlanClient(CreateableAPIResourceClient, DeletableAPIResourceClient, ListableAPIResourceClient, UpdateableAPIResourceClient): - client_for = stripe.Plan - -class SubscriptionClient(UpdateableAPIResourceClient, DeletableAPIResourceClient): - client_for = stripe.Subscription - -class TokenClient(CreateableAPIResourceClient): - client_for = stripe.Token - -class CouponClient(CreateableAPIResourceClient, UpdateableAPIResourceClient, DeletableAPIResourceClient, ListableAPIResourceClient): - client_for = stripe.Coupon - -class ApplicationFeeClient(ListableAPIResourceClient): - client_for = stripe.ApplicationFee - -def main(): - # DeprecationWarning - sys.stderr.write( - 'The Python client binary is deprecated and will be removed in \n' - 'version 2.0 of the bindings. You may want to use: \n' - 'https://github.com/stripe-contrib/stripe-cli\n\n') - - klasses = { - 'account' : AccountClient, - 'card' : CardClient, - 'charge' : ChargeClient, - 'charges' : ChargeClient, - 'customer' : CustomerClient, - 'customers' : CustomerClient, - 'invoice' : InvoiceClient, - 'invoices' : InvoiceClient, - 'invoiceitem' : InvoiceItemClient, - 'invoiceitems' : InvoiceItemClient, - 'plan' : PlanClient, - 'plans' : PlanClient, - 'token' : TokenClient, - 'tokens' : TokenClient, - 'coupon' : CouponClient, - 'coupons' : CouponClient, - 'subscription' : SubscriptionClient, - 'subscriptions' : SubscriptionClient, - 'application_fee' : ApplicationFeeClient, - 'application_fees' : ApplicationFeeClient - } - parser = optparse.OptionParser("""%prog [options] class method [key=value|key ...] - -Valid methods: - -account - retrieve - -card - update - delete - -charge - all - create - retrieve - refund - capture - -customer - all - create - retrieve - update - delete - add_invoice_item - invoices - invoice_items - charges - update_subscription - cancel_subscription - -invoice - all - retrieve - upcoming - update - pay - -invoiceitem - all - create - retrieve - update - delete - -plan - create - retrieve - update - -subscription - update - delete - -coupon - all - create - retrieve - update - delete - -application_fee - all - retrieve - -token - create - retrieve""") - parser.add_option('-v', '--verbosity', help='Verbosity of debugging output.', - dest='verbosity', action='count', default=0) - parser.add_option('-k', '--api-key', help="API key. Defaults to value of environment variable STRIPE_API_KEY", dest='api_key') - parser.add_option('-b', '--api-base', help='API base URL', dest='api_base') - parser.add_option('-i', '--id', help="Object ID", dest='id') - opts, args = parser.parse_args() - if opts.verbosity == 1: - logger.setLevel(logging.INFO) - elif opts.verbosity >= 2: - logger.setLevel(logging.DEBUG) - if len(args) < 2: - parser.print_help() - return 1 - - klass_name = args[0] - method_name = args[1] - - stripe.api_key = opts.api_key or os.environ.get('STRIPE_API_KEY') - if not stripe.api_key: - parser.error('No API key provided (use -k option or set the STRIPE_API_KEY environment variable') - return 1 - - if opts.api_base: - stripe.api_base = opts.api_base - - params = [] - for arg in args[2:]: - try: - key = arg[:arg.index('=')] - value = arg[arg.index('=') + 1:] - except ValueError: - key = arg - value = None - if not value: - value = raw_input('%s= ' % (key, )) - params.append([key, value]) - - try: - klass = klasses[klass_name] - except KeyError: - parser.error('Invalid class %s' % (klass_name, )) - return 1 - else: - dispatch = klass(opts.id) - - try: - method = getattr(dispatch, method_name) - except AttributeError: - parser.error('Invalid method %s of %s' % (method_name, klass_name)) - return 1 - - return method(params) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/setup.py b/setup.py index 9cd262693..06f5d2c6a 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ import os import sys -import warnings try: from setuptools import setup diff --git a/stripe/__init__.py b/stripe/__init__.py index 6920c630d..d98a7b61c 100644 --- a/stripe/__init__.py +++ b/stripe/__init__.py @@ -23,7 +23,7 @@ # Set to either 'debug' or 'info', controls console logging log = None -# Resource +# API resources from stripe.api_resources import * # noqa # OAuth @@ -32,47 +32,6 @@ # Webhooks from stripe.webhook import Webhook, WebhookSignature # noqa -# Error imports. Note that we may want to move these out of the root -# namespace in the future and you should prefer to access them via -# the fully qualified `stripe.error` module. - -from stripe.error import ( # noqa - APIConnectionError, - APIError, - AuthenticationError, - PermissionError, - RateLimitError, - CardError, - IdempotencyError, - InvalidRequestError, - SignatureVerificationError, - StripeError) - -# OAuth error classes are not imported into the root namespace and must be -# accessed via stripe.oauth_error. -from stripe import oauth_error # noqa - -# DEPRECATED: These imports will be moved out of the root stripe namespace -# in version 2.0 - -from stripe.version import VERSION # noqa -from stripe.api_requestor import APIRequestor # noqa - -from stripe.stripe_object import StripeObject # noqa -from stripe.api_resources.abstract import ( # noqa - APIResource, - CreateableAPIResource, - DeletableAPIResource, - ListableAPIResource, - SingletonAPIResource, - UpdateableAPIResource) - -from stripe.resource import StripeObjectEncoder # noqa -from stripe.util import ( # noqa - convert_to_stripe_object, - json, - logger) - # Sets some basic information about the running application that's sent along # with API requests. Useful for plugin authors to identify their plugin when diff --git a/stripe/api_requestor.py b/stripe/api_requestor.py index 4b127a8db..5088ec779 100644 --- a/stripe/api_requestor.py +++ b/stripe/api_requestor.py @@ -4,7 +4,6 @@ import datetime import platform import time -import warnings import stripe from stripe import error, oauth_error, http_client, version, util, six @@ -79,65 +78,6 @@ def __init__(self, key=None, client=None, api_base=None, api_version=None, http_client.new_default_http_client( verify_ssl_certs=verify, proxy=proxy) - @classmethod - def api_url(cls, url=''): - warnings.warn( - 'The `api_url` class method of APIRequestor is ' - 'deprecated and will be removed in version 2.0.' - 'If you need public access to this function, please email us ' - 'at support@stripe.com.', - DeprecationWarning) - return '%s%s' % (stripe.api_base, url) - - @classmethod - def _deprecated_encode(cls, stk, key, value): - warnings.warn( - 'The encode_* class methods of APIRequestor are deprecated and ' - 'will be removed in version 2.0. ' - 'If you need public access to this function, please email us ' - 'at support@stripe.com.', - DeprecationWarning, stacklevel=2) - stk.extend(_api_encode({key: value})) - - @classmethod - def encode_dict(cls, stk, key, value): - cls._deprecated_encode(stk, key, value) - - @classmethod - def encode_list(cls, stk, key, value): - cls._deprecated_encode(stk, key, value) - - @classmethod - def encode_datetime(cls, stk, key, value): - cls._deprecated_encode(stk, key, value) - - @classmethod - def encode_none(cls, stk, key, value): - cls._deprecated_encode(stk, key, value) - - @classmethod - def encode(cls, d): - """ - Internal: encode a string for url representation - """ - warnings.warn( - 'The `encode` class method of APIRequestor is deprecated and ' - 'will be removed in version 2.0.' - 'If you need public access to this function, please email us ' - 'at support@stripe.com.', - DeprecationWarning) - return urlencode(list(_api_encode(d))) - - @classmethod - def build_url(cls, url, params): - warnings.warn( - 'The `build_url` class method of APIRequestor is deprecated and ' - 'will be removed in version 2.0.' - 'If you need public access to this function, please email us ' - 'at support@stripe.com.', - DeprecationWarning) - return _build_api_url(url, cls.encode(params)) - @classmethod def format_app_info(cls, info): str = info['name'] @@ -365,74 +305,3 @@ def interpret_response(self, rbody, rcode, rheaders): self.handle_error_response(rbody, rcode, resp.data, rheaders) return resp - - # Deprecated request handling. Will all be removed in 2.0 - def _deprecated_request(self, impl, method, url, headers, params): - warnings.warn( - 'The *_request functions of APIRequestor are deprecated and ' - 'will be removed in version 2.0. Please use the client classes ' - ' in `stripe.http_client` instead', - DeprecationWarning, stacklevel=2) - - method = method.lower() - - if method == 'get' or method == 'delete': - if params: - url = self.build_url(url, params) - post_data = None - elif method == 'post': - post_data = self.encode(params) - else: - raise error.APIConnectionError( - 'Unrecognized HTTP method %r. This may indicate a bug in the ' - 'Stripe bindings. Please contact support@stripe.com for ' - 'assistance.' % (method,)) - - client = impl(verify_ssl_certs=self._client._verify_ssl_certs) - return client.request(method, url, headers, post_data) - - def _deprecated_handle_error(self, impl, *args): - warnings.warn( - 'The handle_*_error functions of APIRequestor are deprecated and ' - 'will be removed in version 2.0. Please use the client classes ' - ' in `stripe.http_client` instead', - DeprecationWarning, stacklevel=2) - - client = impl(verify_ssl_certs=self._client._verify_ssl_certs) - return client._handle_request_error(*args) - - def requests_request(self, meth, abs_url, headers, params): - from stripe.http_client import RequestsClient - return self._deprecated_request(RequestsClient, meth, abs_url, - headers, params) - - def handle_requests_error(self, err): - from stripe.http_client import RequestsClient - return self._deprecated_handle_error(RequestsClient, err) - - def pycurl_request(self, meth, abs_url, headers, params): - from stripe.http_client import PycurlClient - return self._deprecated_request(PycurlClient, meth, abs_url, - headers, params) - - def handle_pycurl_error(self, err): - from stripe.http_client import PycurlClient - return self._deprecated_handle_error(PycurlClient, err) - - def urlfetch_request(self, meth, abs_url, headers, params): - from stripe.http_client import UrlFetchClient - return self._deprecated_request(UrlFetchClient, meth, abs_url, - headers, params) - - def handle_urlfetch_error(self, err, abs_url): - from stripe.http_client import UrlFetchClient - return self._deprecated_handle_error(UrlFetchClient, err, abs_url) - - def urllib2_request(self, meth, abs_url, headers, params): - from stripe.http_client import Urllib2Client - return self._deprecated_request(Urllib2Client, meth, abs_url, - headers, params) - - def handle_urllib2_error(self, err, abs_url): - from stripe.http_client import Urllib2Client - return self._deprecated_handle_error(Urllib2Client, err, abs_url) diff --git a/stripe/api_resources/abstract/listable_api_resource.py b/stripe/api_resources/abstract/listable_api_resource.py index 0189520fa..52dc68b33 100644 --- a/stripe/api_resources/abstract/listable_api_resource.py +++ b/stripe/api_resources/abstract/listable_api_resource.py @@ -1,21 +1,11 @@ from __future__ import absolute_import, division, print_function -import warnings - from stripe import api_requestor, util from stripe.api_resources.abstract.api_resource import APIResource class ListableAPIResource(APIResource): - @classmethod - def all(cls, *args, **params): - warnings.warn("The `all` class method is deprecated and will" - "be removed in future versions. Please use the " - "`list` class method instead", - DeprecationWarning) - return cls.list(*args, **params) - @classmethod def auto_paging_iter(cls, *args, **params): return cls.list(*args, **params).auto_paging_iter() diff --git a/stripe/api_resources/customer.py b/stripe/api_resources/customer.py index 449021614..a5cb4ba4f 100644 --- a/stripe/api_resources/customer.py +++ b/stripe/api_resources/customer.py @@ -1,11 +1,6 @@ from __future__ import absolute_import, division, print_function -import warnings - -from stripe import api_requestor, util -from stripe.api_resources.charge import Charge -from stripe.api_resources.invoice import Invoice -from stripe.api_resources.invoice_item import InvoiceItem +from stripe import api_requestor from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource @@ -21,62 +16,10 @@ class Customer(CreateableAPIResource, UpdateableAPIResource, ListableAPIResource, DeletableAPIResource): OBJECT_NAME = 'customer' - def add_invoice_item(self, idempotency_key=None, **params): - params['customer'] = self.id - ii = InvoiceItem.create(self.api_key, - idempotency_key=idempotency_key, **params) - return ii - - def invoices(self, **params): - params['customer'] = self.id - invoices = Invoice.list(self.api_key, **params) - return invoices - - def invoice_items(self, **params): - params['customer'] = self.id - iis = InvoiceItem.list(self.api_key, **params) - return iis - - def charges(self, **params): - params['customer'] = self.id - charges = Charge.list(self.api_key, **params) - return charges - - def update_subscription(self, idempotency_key=None, **params): - warnings.warn( - 'The `update_subscription` method is deprecated. Instead, use the ' - '`subscriptions` resource on the customer object to update a ' - 'subscription', - DeprecationWarning) - requestor = api_requestor.APIRequestor(self.api_key, - api_version=self.stripe_version, - account=self.stripe_account) - url = self.instance_url() + '/subscription' - headers = util.populate_headers(idempotency_key) - response, api_key = requestor.request('post', url, params, headers) - self.refresh_from({'subscription': response}, api_key, True) - return self.subscription - - def cancel_subscription(self, idempotency_key=None, **params): - warnings.warn( - 'The `cancel_subscription` method is deprecated. Instead, use the ' - '`subscriptions` resource on the customer object to cancel a ' - 'subscription', - DeprecationWarning) - requestor = api_requestor.APIRequestor(self.api_key, - api_version=self.stripe_version, - account=self.stripe_account) - url = self.instance_url() + '/subscription' - headers = util.populate_headers(idempotency_key) - response, api_key = requestor.request('delete', url, params, headers) - self.refresh_from({'subscription': response}, api_key, True) - return self.subscription - - # TODO: Remove arg in next major release. def delete_discount(self, **params): requestor = api_requestor.APIRequestor(self.api_key, api_version=self.stripe_version, account=self.stripe_account) url = self.instance_url() + '/discount' - _, api_key = requestor.request('delete', url) + _, api_key = requestor.request('delete', url, params) self.refresh_from({'discount': None}, api_key, True) diff --git a/stripe/api_resources/ephemeral_key.py b/stripe/api_resources/ephemeral_key.py index ce7d0c0c6..9ee0b29d1 100644 --- a/stripe/api_resources/ephemeral_key.py +++ b/stripe/api_resources/ephemeral_key.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, division, print_function -import warnings - from stripe import api_requestor, util from stripe.api_resources.abstract import DeletableAPIResource @@ -16,18 +14,11 @@ def class_name(cls): @classmethod def create(cls, api_key=None, idempotency_key=None, stripe_version=None, stripe_account=None, - api_version=None, **params): + **params): if stripe_version is None: - if api_version is not None: - stripe_version = api_version - warnings.warn( - "The `api_version` parameter when creating an ephemeral " - "key is deprecated. Please use `stripe_version` instead.", - DeprecationWarning) - else: - raise ValueError( - "stripe_version must be specified to create an ephemeral " - "key") + raise ValueError( + "stripe_version must be specified to create an ephemeral " + "key") requestor = api_requestor.APIRequestor( api_key, diff --git a/stripe/api_resources/list_object.py b/stripe/api_resources/list_object.py index a956238bb..f1acbe626 100644 --- a/stripe/api_resources/list_object.py +++ b/stripe/api_resources/list_object.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, division, print_function -import warnings - from stripe import util from stripe.stripe_object import StripeObject @@ -14,13 +12,6 @@ class ListObject(StripeObject): def list(self, **params): return self.request('get', self['url'], params) - def all(self, **params): - warnings.warn("The `all` method is deprecated and will" - "be removed in future versions. Please use the " - "`list` method instead", - DeprecationWarning) - return self.list(**params) - def auto_paging_iter(self): page = self params = dict(self._retrieve_params) diff --git a/stripe/api_resources/recipient.py b/stripe/api_resources/recipient.py index ebd4dba2b..f4eb8efec 100644 --- a/stripe/api_resources/recipient.py +++ b/stripe/api_resources/recipient.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, division, print_function -from stripe.api_resources.transfer import Transfer from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource @@ -10,8 +9,3 @@ class Recipient(CreateableAPIResource, UpdateableAPIResource, ListableAPIResource, DeletableAPIResource): OBJECT_NAME = 'recipient' - - def transfers(self, **params): - params['recipient'] = self.id - transfers = Transfer.list(self.api_key, **params) - return transfers diff --git a/stripe/api_resources/source.py b/stripe/api_resources/source.py index 8f3862257..53803e907 100644 --- a/stripe/api_resources/source.py +++ b/stripe/api_resources/source.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, division, print_function -import warnings - from stripe import util from stripe.api_resources import Customer from stripe.api_resources.abstract import CreateableAPIResource @@ -30,13 +28,6 @@ def detach(self, idempotency_key=None, **params): "This source object does not appear to be currently attached " "to a customer object.") - def delete(self, **params): - warnings.warn("The `Source.delete` method is deprecated and will " - "be removed in future versions. Please use the " - "`Source.detach` method instead", - DeprecationWarning) - self.detach(**params) - def source_transactions(self, **params): return self.request( 'get', self.instance_url() + '/source_transactions', params) diff --git a/stripe/api_resources/subscription.py b/stripe/api_resources/subscription.py index e0e7a0f1c..2a9ca8662 100644 --- a/stripe/api_resources/subscription.py +++ b/stripe/api_resources/subscription.py @@ -11,13 +11,12 @@ class Subscription(CreateableAPIResource, DeletableAPIResource, UpdateableAPIResource, ListableAPIResource): OBJECT_NAME = 'subscription' - # TODO: Remove arg in next major release. def delete_discount(self, **params): requestor = api_requestor.APIRequestor(self.api_key, api_version=self.stripe_version, account=self.stripe_account) url = self.instance_url() + '/discount' - _, api_key = requestor.request('delete', url) + _, api_key = requestor.request('delete', url, params) self.refresh_from({'discount': None}, api_key, True) @classmethod diff --git a/stripe/api_resources/topup.py b/stripe/api_resources/topup.py index 51fda2c83..72f55b737 100644 --- a/stripe/api_resources/topup.py +++ b/stripe/api_resources/topup.py @@ -1,3 +1,5 @@ +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 diff --git a/stripe/resource.py b/stripe/resource.py deleted file mode 100644 index 3f19537c1..000000000 --- a/stripe/resource.py +++ /dev/null @@ -1,38 +0,0 @@ -from __future__ import absolute_import, division, print_function - -# -# This module doesn't serve much purpose anymore. It's only here to maintain -# backwards compatibility. -# -# TODO: get rid of this module in the next major version. -# - -import warnings - -from stripe import util -from stripe.util import ( # noqa - convert_array_to_dict, - convert_to_stripe_object, -) -from stripe.stripe_object import StripeObject # noqa -from stripe.api_resources.abstract import ( # noqa - APIResource, - CreateableAPIResource, - DeletableAPIResource, - ListableAPIResource, - SingletonAPIResource, - UpdateableAPIResource, -) -from stripe.api_resources import * # noqa - - -class StripeObjectEncoder(util.json.JSONEncoder): - - def __init__(self, *args, **kwargs): - warnings.warn( - '`StripeObjectEncoder` is deprecated and will be removed in ' - 'version 2.0 of the Stripe bindings. StripeObject is now a ' - 'subclass of `dict` and is handled natively by the built-in ' - 'json library.', - DeprecationWarning) - super(StripeObjectEncoder, self).__init__(*args, **kwargs) diff --git a/stripe/stripe_object.py b/stripe/stripe_object.py index cf7f3d2d5..111215616 100644 --- a/stripe/stripe_object.py +++ b/stripe/stripe_object.py @@ -1,7 +1,6 @@ from __future__ import absolute_import, division, print_function import datetime -import warnings from copy import deepcopy import stripe @@ -232,12 +231,6 @@ def __str__(self): cls=self.ReprJSONEncoder) def to_dict(self): - warnings.warn( - 'The `to_dict` method is deprecated and will be removed in ' - 'version 2.0 of the Stripe bindings. The StripeObject is ' - 'itself now a subclass of `dict`.', - DeprecationWarning) - return dict(self) @property diff --git a/tests/api_resources/test_customer.py b/tests/api_resources/test_customer.py index 2ab35930b..0f3cf9f43 100644 --- a/tests/api_resources/test_customer.py +++ b/tests/api_resources/test_customer.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, division, print_function -import warnings - import stripe @@ -65,55 +63,6 @@ def test_is_deletable(self, request_mock): ) assert isinstance(resource, stripe.Customer) - def test_can_add_invoice_item(self, request_mock): - resource = stripe.Customer.retrieve(TEST_RESOURCE_ID) - resource.add_invoice_item( - amount=100, - currency='usd' - ) - request_mock.assert_requested( - 'post', - '/v1/invoiceitems', - { - 'amount': 100, - 'currency': 'usd', - 'customer': '%s' % resource.id - } - ) - - def test_can_invoices(self, request_mock): - resource = stripe.Customer.retrieve(TEST_RESOURCE_ID) - resource.invoices() - request_mock.assert_requested( - 'get', - '/v1/invoices', - { - 'customer': '%s' % resource.id - } - ) - - def test_can_invoice_items(self, request_mock): - resource = stripe.Customer.retrieve(TEST_RESOURCE_ID) - resource.invoice_items() - request_mock.assert_requested( - 'get', - '/v1/invoiceitems', - { - 'customer': '%s' % resource.id - } - ) - - def test_can_list_charges(self, request_mock): - resource = stripe.Customer.retrieve(TEST_RESOURCE_ID) - resource.charges() - request_mock.assert_requested( - 'get', - '/v1/charges', - { - 'customer': '%s' % resource.id - } - ) - def test_can_delete_discount(self, request_mock): resource = stripe.Customer.retrieve(TEST_RESOURCE_ID) resource.delete_discount() @@ -123,45 +72,6 @@ def test_can_delete_discount(self, request_mock): ) -# stripe-mock does not handle the legacy subscription endpoint so we stub -class TestCustomerLegacySubscription(object): - def construct_resource(self): - res_dict = { - 'id': TEST_RESOURCE_ID, - 'object': 'customer', - 'metadata': {}, - } - return stripe.Customer.construct_from(res_dict, stripe.api_key) - - def test_can_update_legacy_subscription(self, request_mock): - request_mock.stub_request( - 'post', - '/v1/customers/%s/subscription' % TEST_RESOURCE_ID, - ) - resource = self.construct_resource() - with warnings.catch_warnings(): - warnings.simplefilter('ignore') - resource.update_subscription(plan='plan') - request_mock.assert_requested( - 'post', - '/v1/customers/%s/subscription' % TEST_RESOURCE_ID - ) - - def test_can_delete_legacy_subscription(self, request_mock): - request_mock.stub_request( - 'delete', - '/v1/customers/%s/subscription' % TEST_RESOURCE_ID - ) - resource = self.construct_resource() - with warnings.catch_warnings(): - warnings.simplefilter('ignore') - resource.cancel_subscription() - request_mock.assert_requested( - 'delete', - '/v1/customers/%s/subscription' % TEST_RESOURCE_ID - ) - - class TestCustomerSources(object): def test_is_creatable(self, request_mock): stripe.Customer.create_source( diff --git a/tests/api_resources/test_ephemeral_key.py b/tests/api_resources/test_ephemeral_key.py index 2652dc673..69e46cb07 100644 --- a/tests/api_resources/test_ephemeral_key.py +++ b/tests/api_resources/test_ephemeral_key.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, division, print_function -import warnings - import pytest import stripe @@ -21,25 +19,6 @@ def test_is_creatable(self, request_mock): ) assert isinstance(resource, stripe.EphemeralKey) - def test_raises_a_warning_when_using_api_version_arg(self, request_mock): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - - resource = stripe.EphemeralKey.create( - customer='cus_123', - api_version='2017-05-25' - ) - request_mock.assert_api_version('2017-05-25') - request_mock.assert_requested( - 'post', - '/v1/ephemeral_keys', - {'customer': 'cus_123'} - ) - assert isinstance(resource, stripe.EphemeralKey) - - assert len(w) == 1 - assert w[0].category == DeprecationWarning - def test_is_not_creatable_without_an_explicit_api_version(self): with pytest.raises(ValueError, message='stripe_version must be specified'): diff --git a/tests/api_resources/test_recipient.py b/tests/api_resources/test_recipient.py index c8630c144..98f9e288a 100644 --- a/tests/api_resources/test_recipient.py +++ b/tests/api_resources/test_recipient.py @@ -63,14 +63,3 @@ def test_is_deletable(self, request_mock): '/v1/recipients/%s' % resource.id ) assert isinstance(resource, stripe.Recipient) - - def test_can_list_transfers(self, request_mock): - recipient = stripe.Recipient.retrieve(TEST_RESOURCE_ID) - resources = recipient.transfers() - request_mock.assert_requested( - 'get', - '/v1/transfers', - {'recipient': recipient.id} - ) - assert isinstance(resources.data, list) - assert isinstance(resources.data[0], stripe.Transfer) diff --git a/tests/api_resources/test_source.py b/tests/api_resources/test_source.py index a3c7abbc6..496332d80 100644 --- a/tests/api_resources/test_source.py +++ b/tests/api_resources/test_source.py @@ -1,7 +1,5 @@ from __future__ import absolute_import, division, print_function -import warnings - import pytest import stripe @@ -68,20 +66,6 @@ def test_is_not_detachable_when_unattached(self): with pytest.raises(NotImplementedError): resource.detach() - def test_raises_a_warning_when_calling_delete(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - - resource = stripe.Source.construct_from({ - 'id': TEST_RESOURCE_ID, - 'object': 'source', - 'customer': 'cus_123' - }, stripe.api_key) - resource.delete() - - assert len(w) == 1 - assert w[0].category == DeprecationWarning - def test_is_verifiable(self, request_mock): resource = stripe.Source.retrieve(TEST_RESOURCE_ID) source = resource.verify(values=[1, 2]) diff --git a/tests/test_error.py b/tests/test_error.py index 24a1795d0..48645af39 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -2,12 +2,12 @@ from __future__ import absolute_import, division, print_function -from stripe import six, StripeError +from stripe import six, error class TestError(object): def test_formatting(self): - err = StripeError(u'öre') + err = error.StripeError(u'öre') if six.PY3: assert str(err) == u'öre' else: @@ -15,7 +15,7 @@ def test_formatting(self): assert unicode(err) == u'öre' def test_formatting_with_request_id(self): - err = StripeError(u'öre', headers={'request-id': '123'}) + err = error.StripeError(u'öre', headers={'request-id': '123'}) if six.PY3: assert str(err) == u'Request 123: öre' else: @@ -23,7 +23,7 @@ def test_formatting_with_request_id(self): assert unicode(err) == u'Request 123: öre' def test_formatting_with_none(self): - err = StripeError(None, headers={'request-id': '123'}) + err = error.StripeError(None, headers={'request-id': '123'}) if six.PY3: assert str(err) == u'Request 123: ' else: