Skip to content

Commit

Permalink
[Imp #6] 3DSv2 Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo DRAPPIER committed Dec 7, 2021
1 parent 11a230e commit fed220c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
47 changes: 46 additions & 1 deletion payment_paybox/models/inherited_payment_acquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import hmac
import binascii
import pycountry

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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 '''
<?xml version="1.0" encoding="utf-8"?>
<shoppingcart>
<total>
<totalQuantity>%d</totalQuantity>
</total>
</shoppingcart>
''' % qty

@api.model
def paybox_generate_billing_xml(self, partner):
code_iso_num = pycountry.countries.get(alpha_2=partner.country_id.code)
return '''
<?xml version="1.0" encoding="utf-8"?>
<Billing>
<Address>
<FirstName>%s</FirstName>
<LastName>%s</LastName>
<Address1>%s</Address1>
<Address2>%s</Address2>
<ZipCode>%s</ZipCode>
<City>%s</City>
<CountryCode>%s</CountryCode>
</Address>
</Billing>
''' % (
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):
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pycryptodome
pycountry

0 comments on commit fed220c

Please sign in to comment.