mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: added pay button in folio portal
This commit is contained in:
@@ -4,6 +4,7 @@ from odoo import _, fields, http, tools
|
||||
from odoo.exceptions import AccessError, MissingError
|
||||
from odoo.http import request
|
||||
|
||||
from odoo.addons.payment.controllers.portal import PaymentProcessing
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
|
||||
|
||||
|
||||
@@ -26,10 +27,128 @@ class PortalFolio(CustomerPortal):
|
||||
|
||||
def _folio_get_page_view_values(self, folio, access_token, **kwargs):
|
||||
values = {"folio": folio, "token": access_token}
|
||||
payment_inputs = request.env["payment.acquirer"]._get_available_payment_input(
|
||||
partner=folio.partner_id, company=folio.company_id
|
||||
)
|
||||
is_public_user = request.env.user._is_public()
|
||||
if is_public_user:
|
||||
payment_inputs.pop("pms", None)
|
||||
token_count = (
|
||||
request.env["payment.token"]
|
||||
.sudo()
|
||||
.search_count(
|
||||
[
|
||||
("acquirer_id.company_id", "=", folio.company_id.id),
|
||||
("partner_id", "=", folio.partner_id.id),
|
||||
]
|
||||
)
|
||||
)
|
||||
values["existing_token"] = token_count > 0
|
||||
values.update(payment_inputs)
|
||||
values["partner_id"] = (
|
||||
folio.partner_id if is_public_user else request.env.user.partner_id,
|
||||
)
|
||||
return self._get_page_view_values(
|
||||
folio, access_token, values, "my_folios_history", False, **kwargs
|
||||
)
|
||||
|
||||
@http.route(
|
||||
"/folio/pay/<int:folio_id>/form_tx", type="json", auth="public", website=True
|
||||
)
|
||||
def folio_pay_form(
|
||||
self, acquirer_id, folio_id, save_token=False, access_token=None, **kwargs
|
||||
):
|
||||
folio_sudo = request.env["pms.folio"].sudo().browse(folio_id)
|
||||
if not folio_sudo:
|
||||
return False
|
||||
|
||||
try:
|
||||
acquirer_id = int(acquirer_id)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
if request.env.user._is_public():
|
||||
save_token = False # we avoid to create a token for the public user
|
||||
|
||||
success_url = kwargs.get(
|
||||
"success_url",
|
||||
"%s?%s" % (folio_sudo.access_url, access_token if access_token else ""),
|
||||
)
|
||||
vals = {
|
||||
"acquirer_id": acquirer_id,
|
||||
"return_url": success_url,
|
||||
}
|
||||
|
||||
if save_token:
|
||||
vals["type"] = "form_save"
|
||||
transaction = folio_sudo._create_payment_transaction(vals)
|
||||
PaymentProcessing.add_payment_transaction(transaction)
|
||||
if not transaction:
|
||||
return False
|
||||
tx_ids_list = set(request.session.get("__payment_tx_ids__", [])) | set(
|
||||
transaction.ids
|
||||
)
|
||||
request.session["__payment_tx_ids__"] = list(tx_ids_list)
|
||||
|
||||
return transaction.render_invoice_button(
|
||||
folio_sudo,
|
||||
submit_txt=_("Pay & Confirm"),
|
||||
render_values={
|
||||
"type": "form_save" if save_token else "form",
|
||||
"alias_usage": _(
|
||||
"If we store your payment information on our server, "
|
||||
"subscription payments will be made automatically."
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
# @http.route(
|
||||
# '/invoice/pay/<int:invoice_id>/s2s_token_tx',
|
||||
# type='http',
|
||||
# auth='public',
|
||||
# website=True
|
||||
# )
|
||||
# def invoice_pay_token(self, invoice_id, pm_id=None, **kwargs):
|
||||
# """ Use a token to perform a s2s transaction """
|
||||
# error_url = kwargs.get('error_url', '/my')
|
||||
# access_token = kwargs.get('access_token')
|
||||
# params = {}
|
||||
# if access_token:
|
||||
# params['access_token'] = access_token
|
||||
#
|
||||
# invoice_sudo = request.env['account.move'].sudo().browse(invoice_id).exists()
|
||||
# if not invoice_sudo:
|
||||
# params['error'] = 'pay_invoice_invalid_doc'
|
||||
# return request.redirect(_build_url_w_params(error_url, params))
|
||||
#
|
||||
# success_url = kwargs.get(
|
||||
# 'success_url',
|
||||
# "%s?%s" % (
|
||||
# invoice_sudo.access_url,
|
||||
# url_encode({'access_token': access_token}) if access_token else '')
|
||||
# )
|
||||
# try:
|
||||
# token = request.env['payment.token'].sudo().browse(int(pm_id))
|
||||
# except (ValueError, TypeError):
|
||||
# token = False
|
||||
# token_owner = invoice_sudo.partner_id if \
|
||||
# request.env.user._is_public() else request.env.user.partner_id
|
||||
# if not token or token.partner_id != token_owner:
|
||||
# params['error'] = 'pay_invoice_invalid_token'
|
||||
# return request.redirect(_build_url_w_params(error_url, params))
|
||||
#
|
||||
# vals = {
|
||||
# 'payment_token_id': token.id,
|
||||
# 'type': 'server2server',
|
||||
# 'return_url': _build_url_w_params(success_url, params),
|
||||
# }
|
||||
#
|
||||
# tx = invoice_sudo._create_payment_transaction(vals)
|
||||
# PaymentProcessing.add_payment_transaction(tx)
|
||||
#
|
||||
# params['success'] = 'pay_invoice'
|
||||
# return request.redirect('/payment/process')
|
||||
|
||||
@http.route(
|
||||
["/my/folios", "/my/folios/page/<int:page>"],
|
||||
type="http",
|
||||
|
||||
Reference in New Issue
Block a user