You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
7.3 KiB

  1. # -*- coding: utf-8 -*-
  2. #from urllib.parse import urlparse, urljoin
  3. from odoo import http
  4. from odoo.http import request
  5. from odoo import fields, http, tools, _
  6. from odoo.http import request
  7. import logging
  8. _logger = logging.getLogger(__name__)
  9. import payplug
  10. payplug.set_api_version("2019-08-06")
  11. import pprint
  12. from odoo.addons.sale.controllers.portal import CustomerPortal
  13. from odoo.exceptions import AccessError, UserError, ValidationError
  14. class CustomerPortal(CustomerPortal):
  15. # FOR PAYMENT BY LINK
  16. @http.route(
  17. '/payment/pay', type='http', methods=['GET'], auth='public', website=True, sitemap=False,
  18. )
  19. def payment_pay(
  20. self, reference=None, amount=None, currency_id=None, partner_id=None, company_id=None,
  21. provider_id=None, access_token=None, **kwargs):
  22. res = super(CustomerPortal,self).payment_pay(
  23. reference=reference, amount=amount, currency_id=currency_id, partner_id=partner_id, company_id=company_id,
  24. provider_id=provider_id, access_token=access_token, **kwargs)
  25. # IF PAYMENT ACQUIRER IS ONEY UPDATE VALUES
  26. payment_acquirer=request.env['payment.provider'].sudo().search([('code','=','payplug')], limit=1)
  27. partner = request.env['res.partner'].sudo().search([('id', '=', res.__dict__['qcontext']['partner_id'])])
  28. country = partner.country_id
  29. if payment_acquirer.state != 'disabled':
  30. if payment_acquirer.payment_type_oney == True:
  31. amount = res.__dict__['qcontext']['amount']
  32. currency_symbol = res.__dict__['qcontext']['currency'].symbol
  33. result_simulation=request.env['payment.provider'].sudo()._oney_payment_simulation(amount, 'FR')
  34. res.__dict__['qcontext'].update(result_simulation)
  35. # ONEY PAYMENT CONTROL BETWEEN €100 AND €3000
  36. if amount >= 100.00 and amount <= 3000.00:
  37. authorized_by_oney = True
  38. else:
  39. authorized_by_oney = False
  40. # AUTHORIZED COUNTRY FOR ONEY
  41. authorized_country_oney=True
  42. if country not in payment_acquirer.available_oney_country_ids:
  43. authorized_country_oney=False
  44. res.__dict__['qcontext'].update({
  45. 'InformationMessage': payment_acquirer.oney_information_message,
  46. 'FooterMessage': payment_acquirer.oney_footer_message,
  47. 'amount_total_oney': amount,
  48. 'authorized_by_oney': authorized_by_oney,
  49. 'acquirer': payment_acquirer,
  50. 'currency_symbol': currency_symbol,
  51. 'authorized_country_oney': authorized_country_oney,
  52. })
  53. # AUTHORIZED COUNTRY FOR PAYPLUG
  54. if payment_acquirer.payment_type_payplug == True:
  55. authorized_country_payplug=True
  56. if country not in payment_acquirer.available_payplug_country_ids:
  57. authorized_country_payplug=False
  58. res.__dict__['qcontext'].update({'authorized_country_payplug': authorized_country_payplug})
  59. # AUTHORIZED COUNTRY FOR AMEX
  60. if payment_acquirer.payment_type_amex == True:
  61. authorized_country_amex=True
  62. if country not in payment_acquirer.available_amex_country_ids:
  63. authorized_country_amex=False
  64. res.__dict__['qcontext'].update({'authorized_country_amex': authorized_country_amex})
  65. # AUTHORIZED COUNTRY FOR BANCONTACT
  66. if payment_acquirer.payment_type_bancontact == True:
  67. authorized_country_bancontact=True
  68. if country not in payment_acquirer.available_bancontact_country_ids:
  69. authorized_country_bancontact=False
  70. res.__dict__['qcontext'].update({'authorized_country_bancontact': authorized_country_bancontact})
  71. return res
  72. @http.route(['/my/orders/<int:order_id>'], type='http', auth="public", website=True)
  73. def portal_order_page(self, order_id, report_type=None, access_token=None, message=False, download=False, **kw):
  74. res = super(CustomerPortal,self).portal_order_page(order_id, report_type, access_token, message, download, **kw)
  75. if res.__dict__['qcontext'].get('sale_order'):
  76. # IF PAYMENT ACQUIRER IS ONEY UPDATE VALUES
  77. payment_provider=request.env['payment.provider'].sudo().search([('code','=','payplug')], limit=1)
  78. country = res.__dict__['qcontext']['sale_order'].partner_invoice_id.country_id
  79. if payment_provider.state != 'disabled':
  80. if payment_provider.payment_type_oney == True:
  81. amount = res.__dict__['qcontext']['sale_order'].amount_total
  82. currency_symbol = res.__dict__['qcontext']['sale_order'].currency_id.symbol
  83. result_simulation=request.env['payment.provider'].sudo()._oney_payment_simulation(amount, 'FR')
  84. res.__dict__['qcontext'].update(result_simulation)
  85. # ONEY PAYMENT CONTROL BETWEEN €100 AND €3000
  86. if amount >= 100.00 and amount <= 3000.00:
  87. authorized_by_oney = True
  88. else:
  89. authorized_by_oney = False
  90. # AUTHORIZED COUNTRY FOR ONEY
  91. authorized_country_oney=True
  92. if country not in payment_provider.available_oney_country_ids:
  93. authorized_country_oney=False
  94. res.__dict__['qcontext'].update({
  95. 'InformationMessage': payment_provider.oney_information_message,
  96. 'FooterMessage': payment_provider.oney_footer_message,
  97. 'amount_total_oney': amount,
  98. 'authorized_by_oney': authorized_by_oney,
  99. 'acquirer': payment_provider,
  100. 'currency_symbol': currency_symbol,
  101. 'authorized_country_oney': authorized_country_oney,
  102. })
  103. # AUTHORIZED COUNTRY FOR PAYPLUG
  104. if payment_provider.payment_type_payplug == True:
  105. authorized_country_payplug=True
  106. if country not in payment_provider.available_payplug_country_ids:
  107. authorized_country_payplug=False
  108. res.__dict__['qcontext'].update({'authorized_country_payplug': authorized_country_payplug})
  109. # AUTHORIZED COUNTRY FOR AMEX
  110. if payment_provider.payment_type_amex == True:
  111. authorized_country_amex=True
  112. if country not in payment_provider.available_amex_country_ids:
  113. authorized_country_amex=False
  114. res.__dict__['qcontext'].update({'authorized_country_amex': authorized_country_amex})
  115. # AUTHORIZED COUNTRY FOR BANCONTACT
  116. if payment_provider.payment_type_bancontact == True:
  117. authorized_country_bancontact=True
  118. if country not in payment_provider.available_bancontact_country_ids:
  119. authorized_country_bancontact=False
  120. res.__dict__['qcontext'].update({'authorized_country_bancontact': authorized_country_bancontact})
  121. return res