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

# -*- coding: utf-8 -*-
#from urllib.parse import urlparse, urljoin
from odoo import http
from odoo.http import request
from odoo import fields, http, tools, _
from odoo.http import request
import logging
_logger = logging.getLogger(__name__)
import payplug
payplug.set_api_version("2019-08-06")
import pprint
from odoo.addons.sale.controllers.portal import CustomerPortal
from odoo.exceptions import AccessError, UserError, ValidationError
class CustomerPortal(CustomerPortal):
# FOR PAYMENT BY LINK
@http.route(
'/payment/pay', type='http', methods=['GET'], auth='public', website=True, sitemap=False,
)
def payment_pay(
self, reference=None, amount=None, currency_id=None, partner_id=None, company_id=None,
provider_id=None, access_token=None, **kwargs):
res = super(CustomerPortal,self).payment_pay(
reference=reference, amount=amount, currency_id=currency_id, partner_id=partner_id, company_id=company_id,
provider_id=provider_id, access_token=access_token, **kwargs)
# IF PAYMENT ACQUIRER IS ONEY UPDATE VALUES
payment_acquirer=request.env['payment.provider'].sudo().search([('code','=','payplug')], limit=1)
partner = request.env['res.partner'].sudo().search([('id', '=', res.__dict__['qcontext']['partner_id'])])
country = partner.country_id
if payment_acquirer.state != 'disabled':
if payment_acquirer.payment_type_oney == True:
amount = res.__dict__['qcontext']['amount']
currency_symbol = res.__dict__['qcontext']['currency'].symbol
result_simulation=request.env['payment.provider'].sudo()._oney_payment_simulation(amount, 'FR')
res.__dict__['qcontext'].update(result_simulation)
# ONEY PAYMENT CONTROL BETWEEN €100 AND €3000
if amount >= 100.00 and amount <= 3000.00:
authorized_by_oney = True
else:
authorized_by_oney = False
# AUTHORIZED COUNTRY FOR ONEY
authorized_country_oney=True
if country not in payment_acquirer.available_oney_country_ids:
authorized_country_oney=False
res.__dict__['qcontext'].update({
'InformationMessage': payment_acquirer.oney_information_message,
'FooterMessage': payment_acquirer.oney_footer_message,
'amount_total_oney': amount,
'authorized_by_oney': authorized_by_oney,
'acquirer': payment_acquirer,
'currency_symbol': currency_symbol,
'authorized_country_oney': authorized_country_oney,
})
# AUTHORIZED COUNTRY FOR PAYPLUG
if payment_acquirer.payment_type_payplug == True:
authorized_country_payplug=True
if country not in payment_acquirer.available_payplug_country_ids:
authorized_country_payplug=False
res.__dict__['qcontext'].update({'authorized_country_payplug': authorized_country_payplug})
# AUTHORIZED COUNTRY FOR AMEX
if payment_acquirer.payment_type_amex == True:
authorized_country_amex=True
if country not in payment_acquirer.available_amex_country_ids:
authorized_country_amex=False
res.__dict__['qcontext'].update({'authorized_country_amex': authorized_country_amex})
# AUTHORIZED COUNTRY FOR BANCONTACT
if payment_acquirer.payment_type_bancontact == True:
authorized_country_bancontact=True
if country not in payment_acquirer.available_bancontact_country_ids:
authorized_country_bancontact=False
res.__dict__['qcontext'].update({'authorized_country_bancontact': authorized_country_bancontact})
return res
@http.route(['/my/orders/<int:order_id>'], type='http', auth="public", website=True)
def portal_order_page(self, order_id, report_type=None, access_token=None, message=False, download=False, **kw):
res = super(CustomerPortal,self).portal_order_page(order_id, report_type, access_token, message, download, **kw)
if res.__dict__['qcontext'].get('sale_order'):
# IF PAYMENT ACQUIRER IS ONEY UPDATE VALUES
payment_provider=request.env['payment.provider'].sudo().search([('code','=','payplug')], limit=1)
country = res.__dict__['qcontext']['sale_order'].partner_invoice_id.country_id
if payment_provider.state != 'disabled':
if payment_provider.payment_type_oney == True:
amount = res.__dict__['qcontext']['sale_order'].amount_total
currency_symbol = res.__dict__['qcontext']['sale_order'].currency_id.symbol
result_simulation=request.env['payment.provider'].sudo()._oney_payment_simulation(amount, 'FR')
res.__dict__['qcontext'].update(result_simulation)
# ONEY PAYMENT CONTROL BETWEEN €100 AND €3000
if amount >= 100.00 and amount <= 3000.00:
authorized_by_oney = True
else:
authorized_by_oney = False
# AUTHORIZED COUNTRY FOR ONEY
authorized_country_oney=True
if country not in payment_provider.available_oney_country_ids:
authorized_country_oney=False
res.__dict__['qcontext'].update({
'InformationMessage': payment_provider.oney_information_message,
'FooterMessage': payment_provider.oney_footer_message,
'amount_total_oney': amount,
'authorized_by_oney': authorized_by_oney,
'acquirer': payment_provider,
'currency_symbol': currency_symbol,
'authorized_country_oney': authorized_country_oney,
})
# AUTHORIZED COUNTRY FOR PAYPLUG
if payment_provider.payment_type_payplug == True:
authorized_country_payplug=True
if country not in payment_provider.available_payplug_country_ids:
authorized_country_payplug=False
res.__dict__['qcontext'].update({'authorized_country_payplug': authorized_country_payplug})
# AUTHORIZED COUNTRY FOR AMEX
if payment_provider.payment_type_amex == True:
authorized_country_amex=True
if country not in payment_provider.available_amex_country_ids:
authorized_country_amex=False
res.__dict__['qcontext'].update({'authorized_country_amex': authorized_country_amex})
# AUTHORIZED COUNTRY FOR BANCONTACT
if payment_provider.payment_type_bancontact == True:
authorized_country_bancontact=True
if country not in payment_provider.available_bancontact_country_ids:
authorized_country_bancontact=False
res.__dict__['qcontext'].update({'authorized_country_bancontact': authorized_country_bancontact})
return res