payment_provider.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. # Original Copyright 2015 Eezee-It, modified and maintained by Odoo.
  3. from hashlib import sha256
  4. from odoo import api, fields, models
  5. from .const import SUPPORTED_CURRENCIES
  6. class PaymentProvider(models.Model):
  7. _inherit = 'payment.provider'
  8. code = fields.Selection(
  9. selection_add=[('sips', "Sips")], ondelete={'sips': 'set default'})
  10. sips_merchant_id = fields.Char(
  11. string="Merchant ID", help="The ID solely used to identify the merchant account with Sips",
  12. required_if_provider='sips')
  13. sips_secret = fields.Char(
  14. string="SIPS Secret Key", size=64, required_if_provider='sips', groups='base.group_system')
  15. sips_key_version = fields.Integer(
  16. string="Secret Key Version", required_if_provider='sips', default=2)
  17. sips_test_url = fields.Char(
  18. string="Test URL", required_if_provider='sips',
  19. default="https://payment-webinit.simu.sips-services.com/paymentInit")
  20. sips_prod_url = fields.Char(
  21. string="Production URL", required_if_provider='sips',
  22. default="https://payment-webinit.sips-services.com/paymentInit")
  23. sips_version = fields.Char(
  24. string="Interface Version", required_if_provider='sips', default="HP_2.31")
  25. @api.model
  26. def _get_compatible_providers(self, *args, currency_id=None, **kwargs):
  27. """ Override of payment to unlist Sips providers when the currency is not supported. """
  28. providers = super()._get_compatible_providers(*args, currency_id=currency_id, **kwargs)
  29. currency = self.env['res.currency'].browse(currency_id).exists()
  30. if currency and currency.name not in SUPPORTED_CURRENCIES:
  31. providers = providers.filtered(lambda p: p.code != 'sips')
  32. return providers
  33. def _sips_generate_shasign(self, data):
  34. """ Generate the shasign for incoming or outgoing communications.
  35. Note: self.ensure_one()
  36. :param str data: The data to use to generate the shasign
  37. :return: shasign
  38. :rtype: str
  39. """
  40. self.ensure_one()
  41. key = self.sips_secret
  42. shasign = sha256((data + key).encode('utf-8'))
  43. return shasign.hexdigest()