Skip to content

Commit

Permalink
Merge pull request #11 from codesyntax/image-and-pdf-urls
Browse files Browse the repository at this point in the history
Image and pdf urls
  • Loading branch information
erral committed Apr 27, 2018
2 parents 8ecbffd + 4be8244 commit cf20c2f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 3 deletions.
7 changes: 6 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ History
1.0b5 (unreleased)
------------------

- Nothing changed yet.
- Add extra parameters to send logo urls
[erral]


- Add an extra parameter to send the XSLT template
[erral]


1.0b4 (2018-04-25)
Expand Down
33 changes: 32 additions & 1 deletion pymipago/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# -*- coding: utf-8 -*-
from .constants import INITIALIZATION_XML
from .constants import LOGO_1_TEMPLATE
from .constants import LOGO_2_TEMPLATE
from .constants import LOGO_WRAPPER_TEMPLATE
from .constants import MESSAGE_1_TEMPLATE
from .constants import MESSAGE_2_TEMPLATE
from .constants import MESSAGE_3_TEMPLATE
from .constants import MESSAGE_4_TEMPLATE
from .constants import MESSAGE_PAYMENT_TITLE
from .constants import MESSAGE_PAYMENT_DESCRIPTION
from .constants import MESSAGE_PAYMENT_TITLE
from .constants import PDF_XSLT_TEMPLATE
from .constants import PRESENTATION_XML
from .constants import PROTOCOL_DATA_XML
from .exceptions import InvalidCPRValue
Expand Down Expand Up @@ -114,6 +118,28 @@ def make_payment_request(
eu=extra.get('mipago_payment_description').get('eu', ''),
)

logo_urls = ''
if 'logo_1_url' in extra:
logo_urls += LOGO_1_TEMPLATE.format(
url=extra.get('logo_1_url', '')
)

if 'logo_2_url' in extra:
logo_urls += LOGO_2_TEMPLATE.format(
url=extra.get('logo_2_url', '')
)

if logo_urls:
logo_urls = LOGO_WRAPPER_TEMPLATE.format(
data=logo_urls,
)

pdf_xslt_url = ''
if 'pdf_xslt_url' in extra:
pdf_xslt_url = PDF_XSLT_TEMPLATE.format(
url=extra.get('pdf_xslt_url', '')
)

initialization_xml = INITIALIZATION_XML.format(
code=payment_code,
cpr=cpr,
Expand Down Expand Up @@ -142,8 +168,13 @@ def make_payment_request(
citizen_country=extra.get('citizen_country', ''),
citizen_phone=extra.get('citizen_phone', ''),
citizen_email=extra.get('citizen_email', ''),
logo_urls=logo_urls,
pdf_xslt_url=pdf_xslt_url,
)

with open('/tmp/send.xml', 'w') as fp:
fp.write(initialization_xml)

response = requests.post(
INITIALIZATION_URL,
data={'xmlRPC': initialization_xml}
Expand Down
22 changes: 22 additions & 0 deletions pymipago/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
</mensajes>
{logo_urls}
{pdf_xslt_url}
<paymentGatewayVersion>3</paymentGatewayVersion>
</liquidacion>
{message_payment_title}
Expand Down Expand Up @@ -154,3 +159,20 @@
<es>{es}</es>
</texto>
</mensaje>"""

LOGO_1_TEMPLATE = """<imagen id="logo1">
<url><![CDATA[{url}]]></url>
</imagen>"""


LOGO_2_TEMPLATE = """<imagen id="logo2">
<url><![CDATA[{url}]]></url>
</imagen>"""

LOGO_WRAPPER_TEMPLATE = """<imagenes>
{data}
</imagenes>"""

PDF_XSLT_TEMPLATE = """<urlPlantilla>
<![CDATA[{url}]]>
</urlPlantilla>"""
61 changes: 60 additions & 1 deletion tests/test_pymipago.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_invalid_formated_reference_number_raises_exception(self):
payment_modes,
test_environment=True)

def test_correct_payment_request(self):
def test_correct_payment_request_with_minimal_options(self):
cpr = '9052180'
sender = '481166'
format = '521'
Expand All @@ -121,3 +121,62 @@ def test_correct_payment_request(self):

self.assertTrue(html.find(payment_code) != -1)
self.assertTrue(payment_code.isdigit())

def test_correct_payment_request_with_full_options(self):
cpr = '9052180'
sender = '481166'
format = '521'
suffix = '002'
reference_number = '8123456789'
payment_limit_date = datetime.datetime.now()
quantity = '1100'
language = 'eu'
return_url = 'http://localhost:8000'
payment_modes = ['01']

extra = {
'message_1': {
'eu': 'Message: message_1 in Basque (eu)',
'es': 'Message: message_1 in Spanish (es)'
},
'message_2': {
'eu': 'Message: message_2 in Basque (eu)',
'es': 'Message: message_2 in Spanish (es)'
},
'message_3': {
'eu': 'Message: message_3 in Basque (eu)',
'es': 'Message: message_3 in Spanish (es)'
},
'message_4': {
'eu': 'Message: message_4 in Basque (eu)',
'es': 'Message: message_4 in Spanish (es)'
},
'message_payment_title': {
'eu': 'Message: message_payment_title in Basque (eu)',
'es': 'Message: message_payment_title in Spanish (es)'
},
'mipago_payment_description': {
'eu': 'Message: mipago_payment_description in Basque (eu)',
'es': 'Message: mipago_payment_description in Spanish (es)'
},
'logo_1_url': '/data/this-is-a-demo-url-of-logo_1_url.gif',
'logo_2_url': '/data/this-is-a-demo-url-of-logo_2_url.gif',
'pdf_xslt_url': '/data/this-is-a-demo-url-of-pdf_xslt_url.xsl',
}

html, payment_code = make_payment_request(
cpr,
sender,
format,
suffix,
reference_number,
payment_limit_date,
quantity,
language,
return_url,
payment_modes,
extra=extra,
test_environment=True)

self.assertTrue(html.find(payment_code) != -1)
self.assertTrue(payment_code.isdigit())

0 comments on commit cf20c2f

Please sign in to comment.