Skip to content

Commit

Permalink
Merge pull request #46 from gocardless/template-changes
Browse files Browse the repository at this point in the history
v1.20.0 - Add support for tax on GoCardless fees
  • Loading branch information
jasonlafferty authored Jul 14, 2020
2 parents ceea8de + a5480e1 commit 6ebb486
Show file tree
Hide file tree
Showing 26 changed files with 366 additions and 19 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<!-- @format -->

# 1.20.0

- Added support for applying tax to transaction and surcharge fees.
- Added `taxes` to payout_items.
- Added `tax_currency` to payout.
- Added `tax_rates` endpoint.
- Added a payout `tax_exchange_rates_confirmed` webhook to know when the exchange rate has been finalised for all fees in the payout.

# 1.19.0

- adds `not_retried_reason` to payment failed event

# 1.18.0

* support new update instalment schedules route
Expand Down
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ Subscriptions
# Cancel a subscription
client.subscriptions.cancel('SB123', params={...})
Tax rates
''''''''''''''''''''''''''''''''''''''''''

.. code:: python
# List tax rates
client.tax_rates.list(params={...})
# Iterate through all tax_rates
client.tax_rates.all(params={...})
# Get a single tax rate
client.tax_rates.get('GB_VAT_1', params={...})
Running tests
Expand Down
2 changes: 1 addition & 1 deletion gocardless_pro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from .client import Client

__version__ = '1.19.0'
__version__ = '1.20.0'

4 changes: 2 additions & 2 deletions gocardless_pro/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _default_headers(self):
'Authorization': 'Bearer {0}'.format(self.access_token),
'Content-Type': 'application/json',
'GoCardless-Client-Library': 'gocardless-pro-python',
'GoCardless-Client-Version': '1.19.0',
'GoCardless-Client-Version': '1.20.0',
'User-Agent': self._user_agent(),
'GoCardless-Version': '2015-07-06',
}
Expand All @@ -150,7 +150,7 @@ def _user_agent(self):
python_version = '.'.join(platform.python_version_tuple()[0:2])
vm_version = '{}.{}.{}-{}{}'.format(*sys.version_info)
return ' '.join([
'gocardless-pro-python/1.19.0',
'gocardless-pro-python/1.20.0',
'python/{0}'.format(python_version),
'{0}/{1}'.format(platform.python_implementation(), vm_version),
'{0}/{1}'.format(platform.system(), platform.release()),
Expand Down
4 changes: 4 additions & 0 deletions gocardless_pro/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def refunds(self):
def subscriptions(self):
return services.SubscriptionsService(self._api_client, 3, 0.5, self._raise_on_idempotency_conflict)

@property
def tax_rates(self):
return services.TaxRatesService(self._api_client, 3, 0.5, self._raise_on_idempotency_conflict)

def _environment_url(self, environment):
environment_urls = {
'live': 'https://api.gocardless.com',
Expand Down
2 changes: 2 additions & 0 deletions gocardless_pro/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@

from .subscription import Subscription

from .tax_rate import TaxRate

7 changes: 7 additions & 0 deletions gocardless_pro/resources/payout.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def status(self):
return self.attributes.get('status')


@property
def tax_currency(self):
return self.attributes.get('tax_currency')





Expand Down Expand Up @@ -139,3 +144,5 @@ def creditor_bank_account(self):





7 changes: 7 additions & 0 deletions gocardless_pro/resources/payout_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def links(self):
return self.Links(self.attributes.get('links'))


@property
def taxes(self):
return self.attributes.get('taxes')


@property
def type(self):
return self.attributes.get('type')
Expand Down Expand Up @@ -53,3 +58,5 @@ def payment(self):





61 changes: 61 additions & 0 deletions gocardless_pro/resources/tax_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# WARNING: Do not edit by hand, this file was generated by Crank:
#
# https://github.com/gocardless/crank
#

class TaxRate(object):
"""A thin wrapper around a tax_rate, providing easy access to its
attributes.
Example:
tax_rate = client.tax_rates.get()
tax_rate.id
"""

def __init__(self, attributes, api_response):
self.attributes = attributes
self.api_response = api_response

@property
def end_date(self):
return self.attributes.get('end_date')


@property
def id(self):
return self.attributes.get('id')


@property
def jurisdiction(self):
return self.attributes.get('jurisdiction')


@property
def percentage(self):
return self.attributes.get('percentage')


@property
def start_date(self):
return self.attributes.get('start_date')


@property
def type(self):
return self.attributes.get('type')















1 change: 1 addition & 0 deletions gocardless_pro/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
from .redirect_flows_service import RedirectFlowsService
from .refunds_service import RefundsService
from .subscriptions_service import SubscriptionsService
from .tax_rates_service import TaxRatesService
7 changes: 6 additions & 1 deletion gocardless_pro/services/refunds_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def create(self,params=None, headers=None):
Creates a new refund object.
This fails with:<a name="total_amount_confirmation_invalid"></a><a
name="number_of_refunds_exceeded"></a>
name="number_of_refunds_exceeded"></a><a
name="available_refund_amount_insufficient"></a>
- `total_amount_confirmation_invalid` if the confirmation amount
doesn't match the total amount refunded for the payment. This safeguard
Expand All @@ -33,6 +34,10 @@ def create(self,params=None, headers=None):
- `number_of_refunds_exceeded` if five or more refunds have already
been created against the payment.
- `available_refund_amount_insufficient` if the creditor does not have
sufficient balance for refunds available to cover the cost of the
requested refund.
Args:
params (dict, optional): Request body.
Expand Down
67 changes: 67 additions & 0 deletions gocardless_pro/services/tax_rates_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# WARNING: Do not edit by hand, this file was generated by Crank:
#
# https://github.com/gocardless/crank
#

from . import base_service
from .. import resources
from ..paginator import Paginator
from .. import errors

class TaxRatesService(base_service.BaseService):
"""Service class that provides access to the tax_rates
endpoints of the GoCardless Pro API.
"""

RESOURCE_CLASS = resources.TaxRate
RESOURCE_NAME = 'tax_rates'


def list(self,params=None, headers=None):
"""List tax rates.
Returns a [cursor-paginated](#api-usage-cursor-pagination) list of all
tax rates.
Args:
params (dict, optional): Query string parameters.
Returns:
TaxRate
"""
path = '/tax_rates'


response = self._perform_request('GET', path, params, headers,
retry_failures=True)
return self._resource_for(response)

def all(self, params=None):
if params is None:
params = {}
return Paginator(self, params)



def get(self,identity,params=None, headers=None):
"""Get a single tax rate.
Retrieves the details of a tax rate.
Args:
identity (string): The unique identifier created by the jurisdiction, tax type and version
params (dict, optional): Query string parameters.
Returns:
ListResponse of TaxRate instances
"""
path = self._sub_url_params('/tax_rates/:identity', {

'identity': identity,
})


response = self._perform_request('GET', path, params, headers,
retry_failures=True)
return self._resource_for(response)

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name = 'gocardless_pro',
version = '1.19.0',
version = '1.20.0',
packages = find_packages(exclude=['tests']),
install_requires = ['requests>=2.6', 'six'],
author = 'GoCardless',
Expand Down
3 changes: 3 additions & 0 deletions tests/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ def test_refunds_returns_service():
def test_subscriptions_returns_service():
assert_is_instance(client.subscriptions, services.SubscriptionsService)

def test_tax_rates_returns_service():
assert_is_instance(client.tax_rates, services.TaxRatesService)

Loading

0 comments on commit 6ebb486

Please sign in to comment.