2014-09-05 14:27:30 +00:00
|
|
|
from dateutil import relativedelta
|
2014-07-30 12:55:33 +00:00
|
|
|
from django import forms
|
2014-11-09 10:16:07 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2014-07-30 12:55:33 +00:00
|
|
|
|
2014-11-24 14:39:41 +00:00
|
|
|
from orchestra import plugins
|
2014-09-16 15:01:02 +00:00
|
|
|
from orchestra.utils.functional import cached
|
|
|
|
from orchestra.utils.python import import_class
|
|
|
|
|
|
|
|
from .. import settings
|
2014-07-30 12:55:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PaymentMethod(plugins.Plugin):
|
|
|
|
label_field = 'label'
|
|
|
|
number_field = 'number'
|
|
|
|
process_credit = False
|
|
|
|
form = None
|
|
|
|
serializer = None
|
2014-09-05 14:27:30 +00:00
|
|
|
due_delta = relativedelta.relativedelta(months=1)
|
2014-07-30 12:55:33 +00:00
|
|
|
|
2014-09-16 15:01:02 +00:00
|
|
|
@classmethod
|
|
|
|
@cached
|
|
|
|
def get_plugins(cls):
|
|
|
|
plugins = []
|
|
|
|
for cls in settings.PAYMENTS_ENABLED_METHODS:
|
|
|
|
plugins.append(import_class(cls))
|
|
|
|
return plugins
|
2014-07-30 12:55:33 +00:00
|
|
|
|
2014-10-30 16:34:02 +00:00
|
|
|
@classmethod
|
2015-03-11 16:32:33 +00:00
|
|
|
def clean_data(cls):
|
2014-11-09 10:16:07 +00:00
|
|
|
""" model clean, uses cls.serializer by default """
|
2015-03-11 16:32:33 +00:00
|
|
|
serializer = cls.serializer(data=self.instance.data)
|
2014-11-09 10:16:07 +00:00
|
|
|
if not serializer.is_valid():
|
|
|
|
serializer.errors.pop('non_field_errors', None)
|
|
|
|
raise ValidationError(serializer.errors)
|
|
|
|
return serializer.data
|
2014-10-30 16:34:02 +00:00
|
|
|
|
2014-07-30 12:55:33 +00:00
|
|
|
def get_form(self):
|
|
|
|
self.form.plugin = self
|
2014-09-26 21:24:23 +00:00
|
|
|
self.form.plugin_field = 'method'
|
2014-07-30 12:55:33 +00:00
|
|
|
return self.form
|
|
|
|
|
|
|
|
def get_serializer(self):
|
|
|
|
self.serializer.plugin = self
|
|
|
|
return self.serializer
|
|
|
|
|
2015-03-11 16:32:33 +00:00
|
|
|
def get_label(self):
|
|
|
|
return self.instance.data[self.label_field]
|
2014-07-30 12:55:33 +00:00
|
|
|
|
2015-03-11 16:32:33 +00:00
|
|
|
def get_number(self):
|
|
|
|
return self.instance.data[self.number_field]
|
2014-09-05 14:27:30 +00:00
|
|
|
|
2015-03-11 16:32:33 +00:00
|
|
|
def get_bill_message(self):
|
2014-09-10 16:53:09 +00:00
|
|
|
return ''
|