Skip to content

Commit

Permalink
add additional fields to the registration XML
Browse files Browse the repository at this point in the history
  • Loading branch information
erral committed Apr 25, 2018
1 parent ae897a6 commit ea3d3f7
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 4 deletions.
68 changes: 65 additions & 3 deletions pymipago/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
from .constants import INITIALIZATION_XML
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 PRESENTATION_XML
from .constants import PROTOCOL_DATA_XML
from .exceptions import InvalidCPRValue
Expand All @@ -14,8 +19,8 @@


def make_payment_request(
cpr, sender, format, suffix, reference_number, payment_limit_date,
quantity, language, return_url, payment_modes=['01', '02'], test_environment=False):
cpr, sender, format, suffix, reference_number, payment_limit_date, quantity,
language, return_url, payment_modes=['01', '02'], test_environment=False, extra={}):

"""This method creates an XML file and creates a payment request on the
Government platform in order to have the basis to be shown to the end
Expand Down Expand Up @@ -63,6 +68,45 @@ def make_payment_request(
payment_code = _build_payment_code_notebook_60(
sender, reference_number, payment_identification, quantity)



# Message overrides

message_1 = ''
if 'message_1' in extra:
message_1 = MESSAGE_1_TEMPLATE.format(
es=extra.get('message_1').get('es'),
eu=extra.get('message_1').get('eu'),
)

message_2 = ''
if 'message_2' in extra:
message_2 = MESSAGE_2_TEMPLATE.format(
es=extra.get('message_2').get('es'),
eu=extra.get('message_2').get('eu'),
)

message_3 = ''
if 'message_3' in extra:
message_3 = MESSAGE_3_TEMPLATE.format(
es=extra.get('message_3').get('es'),
eu=extra.get('message_3').get('eu'),
)

message_4 = ''
if 'message_4' in extra:
message_4 = MESSAGE_4_TEMPLATE.format(
es=extra.get('message_4').get('es'),
eu=extra.get('message_4').get('eu'),
)

message_payment_title = ''
if 'message_payment_title' in extra:
message_payment_title = MESSAGE_PAYMENT_TITLE.format(
es=extra.get('message_payment_title').get('es'),
eu=extra.get('message_payment_title').get('eu'),
)

initialization_xml = INITIALIZATION_XML.format(
code=payment_code,
cpr=cpr,
Expand All @@ -72,7 +116,25 @@ def make_payment_request(
end_date=payment_limit_date.strftime('%d%m%y'),
format=format,
sender=sender,
reference=reference_number_with_control_digits,
reference_with_control=reference_number_with_control_digits,
reference=reference_number,
message_1=message_1,
message_2=message_2,
message_3=message_3,
message_4=message_4,
message_payment_title=message_payment_title,
citizen_name=extra.get('citizen_name', ''),
citizen_surname_1=extra.get('citizen_surname_1', ''),
citizen_surname_2=extra.get('citizen_surname_2', ''),
citizen_nif=extra.get('citizen_nif', ''),
citizen_address=extra.get('citizen_address', ''),
citizen_postal_code=extra.get('citizen_postal_code', ''),
citizen_territory=extra.get('citizen_territory', ''),
citizen_country=extra.get('citizen_country', ''),
citizen_phone=extra.get('citizen_phone', ''),
citizen_email=extra.get('citizen_email', ''),
mipago_payment_description_es=extra.get('mipago_payment_description_es', ''),
mipago_payment_description_eu=extra.get('mipago_payment_description_eu', ''),
)

response = requests.post(
Expand Down
93 changes: 92 additions & 1 deletion pymipago/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,65 @@
<paymentRequestData>
<peticionesPago>
<peticionPago id='0'>
<liquidacion>
<mensajes>
{message_1}
{message_2}
{message_3}
{message_4}
</mensajes>
</liquidacion>
{message_payment_title}
<expediente>
<codigo>{reference}</codigo>
<tercero>
<primerApellido>{citizen_surname_1}</primerApellido>
<segundoApellido>{citizen_surname_2}</segundoApellido>
<razonSocial>{citizen_name}</razonSocial>
<dniNif>{citizen_name}</dniNif>
<calle>{citizen_nif}</calle>
<municipio>{citizen_address}</municipio>
<codigoPostal>{citizen_postal_code}</codigoPostal>
<territorio>{citizen_territory}</territorio>
<pais>{citizen_country}</pais>
<datosAdicionales>
<datoAdicional id="telefono">
<valor>{citizen_phone}</valor>
</datoAdicional>
<datoAdicional id="email">
<valor>{citizen_email}</valor>
</datoAdicional>
</datosAdicionales>
</tercero>
</expediente>
<conceptos>
<conceptoPeticion>
<numeroLinea>1</numeroLinea>
<baseImponible>0</baseImponible>
<descripcion>
<eu>{mipago_payment_description_eu}</eu>
<es>{mipago_payment_description_es}</es>
</descripcion>
<unidades>1</unidades>
<tieneIVARepercutido>false</tieneIVARepercutido>
<IVARepercutido>false</IVARepercutido>
<tipoIVA>0</tipoIVA>
<importe>{quantity}</importe>
<importeIVA>0</importeIVA>
</conceptoPeticion>
</conceptos>
<datosPago>
<codigo>{code}</codigo>
Expand All @@ -34,7 +93,7 @@
<formato>{format}</formato>
<emisor>{sender}</emisor>
<validar>1</validar>
<referencia>{reference}</referencia>
<referencia>{reference_with_control}</referencia>
</datosPago>
</peticionPago>
Expand All @@ -59,3 +118,35 @@
</urls>
</protocolData>
'''
MESSAGE_PAYMENT_TITLE = '''<descripcion>
<eu>{eu}</eu>
<es>{es}</es>
</descripcion>'''

MESSAGE_1_TEMPLATE = """<mensaje id="1">
<texto>
<eu>{eu}</eu>
<es>{es}</es>
</texto>
</mensaje>"""

MESSAGE_2_TEMPLATE = """<mensaje id="2">
<texto>
<eu>{eu}</eu>
<es>{es}</es>
</texto>
</mensaje>"""

MESSAGE_3_TEMPLATE = """<mensaje id="3">
<texto>
<eu>{eu}</eu>
<es>{es}</es>
</texto>
</mensaje>"""

MESSAGE_4_TEMPLATE = """<mensaje id="4">
<texto>
<eu>{eu}</eu>
<es>{es}</es>
</texto>
</mensaje>"""

0 comments on commit ea3d3f7

Please sign in to comment.