2014-07-23 16:24:56 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2014-07-28 17:28:00 +00:00
|
|
|
from django_iban.validators import IBANValidator, IBAN_COUNTRY_CODE_LENGTH
|
|
|
|
from rest_framework import serializers
|
2014-07-23 16:24:56 +00:00
|
|
|
|
|
|
|
from orchestra.utils import plugins
|
|
|
|
|
2014-07-28 17:28:00 +00:00
|
|
|
from .forms import BankTransferForm, CreditCardForm
|
|
|
|
|
2014-07-23 16:24:56 +00:00
|
|
|
|
|
|
|
class PaymentMethod(plugins.Plugin):
|
2014-07-28 17:28:00 +00:00
|
|
|
label_field = 'label'
|
|
|
|
number_field = 'number'
|
|
|
|
|
2014-07-23 16:24:56 +00:00
|
|
|
__metaclass__ = plugins.PluginMount
|
2014-07-28 17:28:00 +00:00
|
|
|
|
|
|
|
def get_form(self):
|
|
|
|
self.form.plugin = self
|
|
|
|
return self.form
|
|
|
|
|
|
|
|
def get_serializer(self):
|
|
|
|
self.serializer.plugin = self
|
|
|
|
return self.serializer
|
|
|
|
|
|
|
|
def get_label(self, data):
|
|
|
|
return data[self.label_field]
|
|
|
|
|
|
|
|
def get_number(self, data):
|
|
|
|
return data[self.number_field]
|
|
|
|
|
|
|
|
|
|
|
|
class BankTransferSerializer(serializers.Serializer):
|
|
|
|
iban = serializers.CharField(label='IBAN', validators=[IBANValidator()],
|
|
|
|
min_length=min(IBAN_COUNTRY_CODE_LENGTH.values()), max_length=34)
|
|
|
|
name = serializers.CharField(label=_("Name"), max_length=128)
|
|
|
|
|
|
|
|
|
|
|
|
class CreditCardSerializer(serializers.Serializer):
|
|
|
|
pass
|
2014-07-23 16:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BankTransfer(PaymentMethod):
|
|
|
|
verbose_name = _("Bank transfer")
|
2014-07-28 17:28:00 +00:00
|
|
|
label_field = 'name'
|
|
|
|
number_field = 'iban'
|
|
|
|
form = BankTransferForm
|
|
|
|
serializer = BankTransferSerializer
|
2014-07-23 16:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CreditCard(PaymentMethod):
|
|
|
|
verbose_name = _("Credit card")
|
2014-07-28 17:28:00 +00:00
|
|
|
form = CreditCardForm
|
|
|
|
serializer = CreditCardSerializer
|