Skip to content

Commit

Permalink
shopinvader_api_payment_provider_monetico: fix return url and fix web…
Browse files Browse the repository at this point in the history
…hook
  • Loading branch information
sebastienbeau committed Jul 31, 2024
1 parent 307dd77 commit e827f71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
from odoo import models


class PaymentTransactionMonetico(models.Model):
_inherit = "payment.transaction"
class PaymentAcquirer(models.Model):
_inherit = "payment.acquirer"

def _monetico_form_presign_hook(self, values):
"""Insert shopinvader return url in the form values"""
shopinvader_api_payment = self.env.context.get("shopinvader_api_payment")
values = super()._monetico_form_presign_hook(values)

if not shopinvader_api_payment:
return values

shopinvader_api_payment_base_url = self.env.context.get(
"shopinvader_api_payment_base_url"
)
values["url_return_ok"] = values["url_return_err"] = urljoin(
values["url_retour_ok"] = values["url_retour_err"] = urljoin(
shopinvader_api_payment_base_url, "monetico/return"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from urllib.parse import quote_plus

from fastapi import Depends, Request
from fastapi.responses import RedirectResponse
from fastapi.responses import PlainTextResponse, RedirectResponse

from odoo import api

Expand Down Expand Up @@ -62,11 +62,13 @@ def monetico_return(
)


@payment_router.post("/payment/providers/monetico/webhook")
@payment_router.post(
"/payment/providers/monetico/webhook", response_class=PlainTextResponse
)
def monetico_webhook(
request: Request,
odoo_env: Annotated[api.Environment, Depends(odoo_env)],
):
) -> str:
"""Handle Monetico webhook."""
# data = await request.form() # This is broken, data has already been parsed
data = request.scope["wsgi_environ"]["werkzeug.request"].values
Expand All @@ -76,7 +78,7 @@ def monetico_webhook(
)
try:
odoo_env["payment.transaction"].sudo().form_feedback(data, "monetico")

return "version=2\ncdr=0\n"
except Exception:
_logger.exception("unable to handle monetico notification data", exc_info=True)
return ""
return "version=2\ncdr=1\n"

0 comments on commit e827f71

Please sign in to comment.