Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

GET/POST Requests in Odoo to External API

Subscriure's

Get notified when there's activity on this post

This question has been flagged
getpost
1 Respondre
20534 Vistes
Avatar
Y07CH

I'm having some issues trying to write a module for a payment gateway. The External API we need to use requires 3 things through a POST request:

1. ClientID: Token given by the API Issuer
2. Amount: Total amount to pay
3. TransactionID: Field provided by Odoo with the ID for the entire transaction

When I code it outside of Odoo everything works fine, I'm new to Odoo syntax so I don't know how to move all that to my module despite of mimicking 3 similar modules like "stripe", "payumoney" and "paytm".


External Code:

import requests

idcliente = '97bd8cf4-e894-4cb5-b8cc-3fc31f79c81a'
valor = 42.75
id_transaccioncomercio = 20354

base_url = 'https://test.serfinsacheckout.com:8080/'
query_tring = 'Pay/GateWay?token=' + idcliente + '&idTransaccion=2565'
params = 'api/PayApi/TokeyTran'

payload = {
'TokeyComercio': idcliente,
'Monto': valor,
'IdTransaccionCliente': id_transaccioncomercio
}

r = requests.post(base_url + params, data = payload)
print(r.json())

r = requests.get(base_url + query_tring)
# print("Status Code: {} [OK]".format(r.status_code))
print(r.content)


My Code in Odoo (Controller):

import logging
import pprint
import werkzeug
from odoo import http
from odoo.http import request

_logger = logging.getLogger(__name__)
class SerfinsaController(http.Controller):
_return_url = '/payment/serfinsa/return'

def _get_return_url(self, **post):
post = dict(post)
return_url = '/payment/serfinsa/validate'
return return_url

def serfinsa_validate_data(self, **post):
res = False
reference = post['idcliente']
if reference:
_logger.info('Serfinsa: validated data')
res = request.env['payment.transaction'].sudo().form_feedback(post, 'serfinsa_payment')
return res

@http.route('/payment/serfinsa/return', type='http',
auth='none', methods=['GET','POST'])
def serfinsa_return(self, **post):
# Receives POST data from Serfinsa after making the payment
_logger.info('Serfinsa: entering form_feedback with post data %s',
pprint.pformat(post))
return_url = self._get_return_url(**post)
self.serfinsa_validate_data(**post)
return werkzeug.utils.redirect(return_url)


My Code in Models > Payment:

import logging
from odoo import api, fields, models, _
from odoo.addons.payment.models.payment_acquirer import ValidationError

_logger = logging.getLogger(__name__)

class PaymentAcquirerSerfinsa(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('serfinsa_payment', 'Serfinsa')])
idcliente = fields.Char(string='Serfinsa Token', required_if_provider='serfinsa_payment')

def _get_serfinsa_urls(self, environment):
if environment == 'prod':
return {'base_url': 'https://test.serfinsacheckout.com:8080/'}
else:
return {'base_url': 'https://test.serfinsacheckout.com:8080/'}

@api.multi
def serfinsa_form_generate_values(self, values):
self.ensure_one()
base_url = self.get_base_url()
serfinsa_values = dict(values,
idcliente=self.idcliente,
valor=values['amount'],
id_transaccioncomercio=values['reference'],
#txnid=values['reference'],
#firstname=values.get('partner_name'),
#email=values.get('partner_email'),
#phone=values.get('partner_phone'),
service_provider='serfinsa',
)

serfinsa_values['udf1'] = serfinsa_values.pop('return_url', '/')
return serfinsa_values


Any Help is really appreciated...Thanks in advance.

0
Avatar
Descartar
Avatar
Kelvin Karatu Nduta
Best Answer

Did you have any success with this? I'm facing a similar problem

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
How to enable CORS in odoo
get post
Avatar
Avatar
2
de set. 22
23300
Disable GET parameters
get
Avatar
0
de març 15
4450
How to get current url in python odoo10?
url python2.7 get post odoo10.0
Avatar
Avatar
Avatar
4
d’ag. 25
23105
How to make a simple json POST and GET with a new module?
json get post jsonrpc odoo9
Avatar
0
de set. 17
9679
Create timesheet from another module
timesheet post
Avatar
Avatar
2
de febr. 24
2255
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now