Skip to content

Commit

Permalink
Add new Mandate Imports API
Browse files Browse the repository at this point in the history
  • Loading branch information
Crankshaft Robot authored and Nick Campbell committed Apr 26, 2018
1 parent a1f3075 commit 715d657
Show file tree
Hide file tree
Showing 24 changed files with 762 additions and 39 deletions.
31 changes: 31 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,37 @@ Mandates
# Reinstate a mandate
client.mandates.reinstate('MD123', params={...})
Mandate imports
''''''''''''''''''''''''''''''''''''''''''

.. code:: python
# Create a new mandate import
client.mandate_imports.create(params={...})
# Get a mandate import
client.mandate_imports.get('IM000010790WX1', params={...})
# Submit a mandate import
client.mandate_imports.submit('IM000010790WX1', params={...})
# Cancel a mandate import
client.mandate_imports.cancel('IM000010790WX1', params={...})
Mandate import entries
''''''''''''''''''''''''''''''''''''''''''

.. code:: python
# Add a mandate import entry
client.mandate_import_entries.create(params={...})
# List all mandate import entries
client.mandate_import_entries.list(params={...})
# Iterate through all mandate_import_entries
client.mandate_import_entries.all(params={...})
Mandate pdfs
''''''''''''''''''''''''''''''''''''''''''

Expand Down
8 changes: 8 additions & 0 deletions gocardless_pro/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def events(self):
def mandates(self):
return services.MandatesService(self._api_client, 3, 0.5)

@property
def mandate_imports(self):
return services.MandateImportsService(self._api_client, 3, 0.5)

@property
def mandate_import_entries(self):
return services.MandateImportEntriesService(self._api_client, 3, 0.5)

@property
def mandate_pdfs(self):
return services.MandatePdfsService(self._api_client, 3, 0.5)
Expand Down
4 changes: 4 additions & 0 deletions gocardless_pro/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

from .mandate import Mandate

from .mandate_import import MandateImport

from .mandate_import_entry import MandateImportEntry

from .mandate_pdf import MandatePdf

from .payment import Payment
Expand Down
47 changes: 47 additions & 0 deletions gocardless_pro/resources/mandate_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# WARNING: Do not edit by hand, this file was generated by Crank:
#
# https://github.com/gocardless/crank
#

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

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

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


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


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


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











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

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

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

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


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


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






class Links(object):
"""Wrapper for the response's 'links' attribute."""

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

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

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

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

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





2 changes: 2 additions & 0 deletions gocardless_pro/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from .customer_bank_accounts_service import CustomerBankAccountsService
from .events_service import EventsService
from .mandates_service import MandatesService
from .mandate_imports_service import MandateImportsService
from .mandate_import_entries_service import MandateImportEntriesService
from .mandate_pdfs_service import MandatePdfsService
from .payments_service import PaymentsService
from .payouts_service import PayoutsService
Expand Down
78 changes: 78 additions & 0 deletions gocardless_pro/services/mandate_import_entries_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 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 MandateImportEntriesService(base_service.BaseService):
"""Service class that provides access to the mandate_import_entries
endpoints of the GoCardless Pro API.
"""

RESOURCE_CLASS = resources.MandateImportEntry
RESOURCE_NAME = 'mandate_import_entries'


def create(self,params=None, headers=None):
"""Add a mandate import entry.
For an existing [mandate import](#core-endpoints-mandate-imports), this
endpoint can
be used to add individual mandates to be imported into GoCardless.
You can add no more than 30,000 rows to a single mandate import.
If you attempt to go over this limit, the API will return a
`record_limit_exceeded` error.
Args:
params (dict, optional): Request body.
Returns:
ListResponse of MandateImportEntry instances
"""
path = '/mandate_import_entries'

if params is not None:
params = {self._envelope_key(): params}

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


def list(self,params=None, headers=None):
"""List all mandate import entries.
For an existing mandate import, this endpoint lists all of the entries
attached.
After a mandate import has been submitted, you can use this endpoint to
associate records
in your system (using the `record_identifier` that you provided when
creating the
mandate import).
Args:
params (dict, optional): Query string parameters.
Returns:
MandateImportEntry
"""
path = '/mandate_import_entries'


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)


130 changes: 130 additions & 0 deletions gocardless_pro/services/mandate_imports_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# 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 MandateImportsService(base_service.BaseService):
"""Service class that provides access to the mandate_imports
endpoints of the GoCardless Pro API.
"""

RESOURCE_CLASS = resources.MandateImport
RESOURCE_NAME = 'mandate_imports'


def create(self,params=None, headers=None):
"""Create a new mandate import.
Mandate imports are first created, before mandates are added
one-at-a-time, so
this endpoint merely signals the start of the import process. Once
you've finished
adding entries to an import, you should
[submit](#mandate-imports-submit-a-mandate-import) it.
Args:
params (dict, optional): Request body.
Returns:
ListResponse of MandateImport instances
"""
path = '/mandate_imports'

if params is not None:
params = {self._envelope_key(): params}

try:
response = self._perform_request('POST', path, params, headers,
retry_failures=True)
except errors.IdempotentCreationConflictError as err:
return self.get(identity=err.conflicting_resource_id,
params=params,
headers=headers)
return self._resource_for(response)


def get(self,identity,params=None, headers=None):
"""Get a mandate import.
Returns a single mandate import.
Args:
identity (string): Unique identifier, beginning with "IM".
params (dict, optional): Query string parameters.
Returns:
ListResponse of MandateImport instances
"""
path = self._sub_url_params('/mandate_imports/:identity', {

'identity': identity,
})


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


def submit(self,identity,params=None, headers=None):
"""Submit a mandate import.
Submits the mandate import, which allows it to be processed by a member
of the
GoCardless team. Once the import has been submitted, it can no longer
have entries
added to it.
Args:
identity (string): Unique identifier, beginning with "IM".
params (dict, optional): Request body.
Returns:
ListResponse of MandateImport instances
"""
path = self._sub_url_params('/mandate_imports/:identity/actions/submit', {

'identity': identity,
})

if params is not None:
params = {'data': params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)


def cancel(self,identity,params=None, headers=None):
"""Cancel a mandate import.
Cancels the mandate import, which aborts the import process and stops
the mandates
being set up in GoCardless. Once the import has been cancelled, it can
no longer have
entries added to it. Mandate imports which have already been submitted
cannot be
cancelled.
Args:
identity (string): Unique identifier, beginning with "IM".
params (dict, optional): Request body.
Returns:
ListResponse of MandateImport instances
"""
path = self._sub_url_params('/mandate_imports/:identity/actions/cancel', {

'identity': identity,
})

if params is not None:
params = {'data': params}
response = self._perform_request('POST', path, params, headers,
retry_failures=False)
return self._resource_for(response)

Loading

0 comments on commit 715d657

Please sign in to comment.