From fed220cb222e6679ae8f8789bdbf035423fa20cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DRAPPIER?= Date: Tue, 7 Dec 2021 11:34:05 +0100 Subject: [PATCH] [Imp #6] 3DSv2 Integration --- .../models/inherited_payment_acquirer.py | 47 ++++++++++++++++++- requirements.txt | 1 + 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/payment_paybox/models/inherited_payment_acquirer.py b/payment_paybox/models/inherited_payment_acquirer.py index 1d55f6b..690c81c 100644 --- a/payment_paybox/models/inherited_payment_acquirer.py +++ b/payment_paybox/models/inherited_payment_acquirer.py @@ -7,6 +7,7 @@ import logging import hmac import binascii +import pycountry _logger = logging.getLogger(__name__) @@ -89,6 +90,48 @@ def paybox_get_authentication_key(self): else: return self.paybox_test_authentication_key + @api.model + def paybox_generate_shopping_cart_xml(self, reference): + tx = self.env['payment.transaction'].search([('reference', '=', reference)]) + qty = 1 + if tx.sale_order_id: + qty = tx.sale_order_id.cart_quantity + elif tx.account_invoice_id: + qty = int(sum(tx.account_invoice_id.mapped('invoice_line_ids.quantity'))) + return ''' + + + + %d + + + ''' % qty + + @api.model + def paybox_generate_billing_xml(self, partner): + code_iso_num = pycountry.countries.get(alpha_2=partner.country_id.code) + return ''' + + +
+ %s + %s + %s + %s + %s + %s + %s +
+
+ ''' % ( + partner.firstname, + partner.lastname, + partner.street, + partner.street2, + partner.zip_id.name, + partner.city_id.name, + code_iso_num.numeric + ) @api.multi def paybox_form_generate_values(self, values): @@ -123,7 +166,9 @@ def paybox_form_generate_values(self, values): ('PBX_REFUSE', urllib.parse.urljoin(base_url, '/payment/paybox/dpn?return_url=%s' % values.get('return_url'))), ('PBX_ANNULE', urllib.parse.urljoin(base_url, '/payment/paybox/dpn?return_url=%s' % values.get('return_url'))), ('PBX_ATTENTE', urllib.parse.urljoin(base_url, '/payment/paybox/dpn?return_url=%s' % values.get('return_url'))), - ('PBX_REPONDRE_A', urllib.parse.urljoin(base_url, '/payment/paybox/ipn')) + ('PBX_REPONDRE_A', urllib.parse.urljoin(base_url, '/payment/paybox/ipn')), + ('PBX_SHOPPINGCART', self.paybox_generate_shopping_cart_xml(values.get('reference'))), + ('PBX_BILLING', self.paybox_generate_billing_xml(values.get('partner'))) ] signature = self.paybox_generate_message_hmac(vals) diff --git a/requirements.txt b/requirements.txt index acdfd20..a770b24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ pycryptodome +pycountry \ No newline at end of file