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 57534ae
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
44 changes: 43 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,45 @@ 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 +163,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
2 changes: 2 additions & 0 deletions payment_paybox/views/payment_paybox_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<input type="hidden" name="PBX_ANNULE" t-att-value="PBX_ANNULE"/>
<input type="hidden" name="PBX_ATTENTE" t-att-value="PBX_ATTENTE"/>
<input type="hidden" name="PBX_REPONDRE_A" t-att-value="PBX_REPONDRE_A"/>
<input type="hidden" name="PBX_SHOPPINGCART" t-att-value="PBX_SHOPPINGCART"/>
<input type="hidden" name="PBX_BILLING" t-att-value="PBX_BILLING"/>
<input type="hidden" name="PBX_HMAC" t-att-value="PBX_HMAC"/>
</div>
</template>
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 57534ae

Please sign in to comment.