-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from bisurance/recurring
Updated API for recurring interface (Customer, Mandate, Subscription)
- Loading branch information
Showing
14 changed files
with
233 additions
and
53 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Error(Exception): | ||
def __init__(self, message=None, field=None): | ||
self.message = message | ||
self.field = field | ||
Exception.__init__(self, message) | ||
self.field = field |
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,5 @@ | ||
from .Base import * | ||
|
||
|
||
class Customer(Base): | ||
pass |
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,16 @@ | ||
from .Base import * | ||
|
||
|
||
class Mandate(Base): | ||
STATUS_PENDING = 'pending' | ||
STATUS_VALID = 'valid' | ||
STATUS_INVALID = 'invalid' | ||
|
||
def isPending(self): | ||
return self['status'] == self.STATUS_PENDING | ||
|
||
def isValid(self): | ||
return self['status'] == self.STATUS_VALID | ||
|
||
def isInvalid(self): | ||
return self['status'] == self.STATUS_INVALID |
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,24 @@ | ||
from .Base import * | ||
|
||
|
||
class Subscription(Base): | ||
STATUS_ACTIVE = 'active' | ||
STATUS_PENDING = 'pending' # Waiting for a valid mandate. | ||
STATUS_CANCELLED = 'cancelled' | ||
STATUS_SUSPENDED = 'suspended' # Active, but mandate became invalid. | ||
STATUS_COMPLETED = 'completed' | ||
|
||
def isActive(self): | ||
return self['status'] == self.STATUS_ACTIVE | ||
|
||
def isPending(self): | ||
return self['status'] == self.STATUS_PENDING | ||
|
||
def isCancelled(self): | ||
return self['status'] == self.STATUS_CANCELLED | ||
|
||
def isSuspended(self): | ||
return self['status'] == self.STATUS_SUSPENDED | ||
|
||
def isCompleted(self): | ||
return self['status'] == self.STATUS_COMPLETED |
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
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,15 @@ | ||
from Mollie.API.Resource import Payments | ||
|
||
|
||
class CustomerPayments(Payments): | ||
customer_id = None | ||
|
||
def getResourceName(self): | ||
return 'customers/%s/payments' % self.customer_id | ||
|
||
def withParentId(self, customer_id): | ||
self.customer_id = customer_id | ||
return self | ||
|
||
def on(self, customer): | ||
return self.withParentId(customer['id']) |
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,26 @@ | ||
from .Base import * | ||
from Mollie.API.Error import * | ||
from Mollie.API.Object import Customer | ||
|
||
|
||
class Customers(Base): | ||
RESOURCE_ID_PREFIX = 'cst_' | ||
|
||
def getResourceObject(self, result): | ||
return Customer(result) | ||
|
||
def get(self, customer_id): | ||
if not customer_id or not customer_id.startswith(self.RESOURCE_ID_PREFIX): | ||
raise Error( | ||
'Invalid customer ID: "%s". A customer ID should start with "%s".' % (customer_id, self.RESOURCE_ID_PREFIX) | ||
) | ||
return super(Customers, self).get(customer_id) | ||
|
||
def mandates(self, customer): | ||
return self.client.customer_mandates.on(customer) | ||
|
||
def subscriptions(self, customer): | ||
return self.client.customer_subscriptions.on(customer) | ||
|
||
def payments(self, customer): | ||
return self.client.customer_payments.on(customer) |
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,28 @@ | ||
from .Base import * | ||
from Mollie.API.Error import * | ||
from Mollie.API.Object import Mandate | ||
|
||
|
||
class Mandates(Base): | ||
RESOURCE_ID_PREFIX = 'mdt_' | ||
customer_id = None | ||
|
||
def getResourceObject(self, result): | ||
return Mandate(result) | ||
|
||
def get(self, mandate_id): | ||
if not mandate_id or not mandate_id.startswith(self.RESOURCE_ID_PREFIX): | ||
raise Error( | ||
'Invalid mandate ID: "%s". A mandate ID should start with "%s".' % (mandate_id, self.RESOURCE_ID_PREFIX) | ||
) | ||
return super(Mandates, self).get(mandate_id) | ||
|
||
def getResourceName(self): | ||
return 'customers/%s/mandates' % self.customer_id | ||
|
||
def withParentId(self, customer_id): | ||
self.customer_id = customer_id | ||
return self | ||
|
||
def on(self, customer): | ||
return self.withParentId(customer['id']) |
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,28 @@ | ||
from .Base import * | ||
from Mollie.API.Error import * | ||
from Mollie.API.Object import Subscription | ||
|
||
|
||
class Subscriptions(Base): | ||
RESOURCE_ID_PREFIX = 'sub_' | ||
customer_id = None | ||
|
||
def getResourceObject(self, result): | ||
return Subscription(result) | ||
|
||
def get(self, subscription_id): | ||
if not subscription_id or not subscription_id.startswith(self.RESOURCE_ID_PREFIX): | ||
raise Error( | ||
'Invalid subscription ID: "%s". A subscription ID should start with "%s".' % (subscription_id, self.RESOURCE_ID_PREFIX) | ||
) | ||
return super(Subscriptions, self).get(subscription_id) | ||
|
||
def getResourceName(self): | ||
return 'customers/%s/subscriptions' % self.customer_id | ||
|
||
def withParentId(self, customer_id): | ||
self.customer_id = customer_id | ||
return self | ||
|
||
def on(self, customer): | ||
return self.withParentId(customer['id']) |
Oops, something went wrong.