From d49d9ea948b6a6a14350d22fd0d7cc7fb8d75429 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Mon, 21 Jan 2019 10:22:37 +0100 Subject: [PATCH] new: "DOCDATA_CSS_ID" to fix Attribute 'id' must appear on element 'ns0:css' #16 https://github.com/django-oscar/django-oscar-docdata/issues/16 --- oscar_docdata/appsettings.py | 3 +++ oscar_docdata/gateway.py | 49 ++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/oscar_docdata/appsettings.py b/oscar_docdata/appsettings.py index cc198cb..ee22f1f 100644 --- a/oscar_docdata/appsettings.py +++ b/oscar_docdata/appsettings.py @@ -67,3 +67,6 @@ '0091': 'Friesland Bank', '0161': 'van Lanschot Bankiers' }) + +# CSS file selection in the payment menu +DOCDATA_CSS_ID = getattr(settings, 'DOCDATA_CSS_ID', 1) diff --git a/oscar_docdata/gateway.py b/oscar_docdata/gateway.py index e89ef6d..08b07cc 100644 --- a/oscar_docdata/gateway.py +++ b/oscar_docdata/gateway.py @@ -309,7 +309,8 @@ def create(self, # paymentPreferences.exhortation.period2 ? # Menu preferences are empty. They are used for CSS file selection in the payment menu. - menuPreferences = self.client.factory.create('ns0:menuPreferences') + css = StyleSheetID(id=css_id) + menuPreferences = MenuPreferences(css) # Execute create payment order request. # @@ -329,7 +330,7 @@ def create(self, merchant=self.merchant, merchantOrderReference=order_id, paymentPreferences=paymentPreferences, - menuPreferences=menuPreferences, + menuPreferences=menuPreferences.to_xml(factory), shopper=shopper.to_xml(factory), totalGrossAmount=total_gross_amount.to_xml(factory), billTo=bill_to.to_xml(factory), @@ -851,6 +852,50 @@ def to_xml(self, factory): return element +class StyleSheetID: + """ + The id of the CSS file that should be used in the payment menu. + + + + + + + The id of the CSS file that should be used in + the payment menu. + + + + + + + + + """ + + def __init__(self, id): + self.id = int(id) + + def to_xml(self, factory): + node = factory.create("ns0:css") + node.id = id + return node + +class MenuPreferences: + """ + CSS file selection in the payment menu + """ + + def __init__(self, css): + assert isinstance(css, StyleSheetID) + self.css = css + + def to_xml(self, factory): + node = factory.create("ns0:menuPreferences") + node.css = self.css.to_xml(factory) + return node + + class Quantity(object): """ An quantity for Docdata