Render payment method details.

This commit is contained in:
Santiago Lamora 2019-12-17 13:50:53 +01:00
parent ff481b6317
commit 37c9183c1e
2 changed files with 22 additions and 7 deletions

View file

@ -1,7 +1,13 @@
import ast
import logging
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
logger = logging.getLogger(__name__)
class OrchestraModel:
""" Base class from which all orchestra models will inherit. """
api_name = None
@ -16,9 +22,6 @@ class OrchestraModel:
for (param, default) in self.param_defaults.items():
setattr(self, param, kwargs.get(param, default))
# def get(self, key):
# # retrieve attr of the object and if undefined get raw data
# return getattr(self, key, self.data.get(key))
@classmethod
def new_from_json(cls, data, **kwargs):
@ -35,8 +38,7 @@ class OrchestraModel:
c = cls(**json_data)
c._json = data
# TODO(@slamora) remove/replace by private variable to ovoid name collisions
c.data = data
return c
def __repr__(self):
@ -65,6 +67,15 @@ class PaymentSource(OrchestraModel):
"is_active": False,
}
def __init__(self, **kwargs):
super().__init__(**kwargs)
# payment details are passed as a plain string
# try to convert to a python structure
try:
self.data = ast.literal_eval(self.data)
except (ValueError, SyntaxError) as e:
logger.error(e)
class UserAccount(OrchestraModel):
api_name = 'accounts'

View file

@ -48,8 +48,12 @@
payment method: {{ payment.method }}
</div>
<div class="form-group">
{# TODO(@slamora) format payment method details #}
{{ payment.data.data }}
{% if payment.method == 'SEPADirectDebit' %}
IBAN {{ payment.data.iban }}
{% else %}
{# <!-- "TODO handle Credit Card" --> #}
Details: {{ payment.data }}
{% endif %}
</div>
</div>