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

I cant't pass form to Paytrail Payment gateway ?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
integrationgatewaypaymentpaytrail
5364 Vistes
Avatar
navctns@gmail.com

I am integrating Paytrail Payment gateway, i have inherited the acquirer model to access to the gateway. And created a template for passing fields to gateway. But still no response. I can't find the problem. I can't find find how the value is passed..


Code:


models/models.py


import base64
import string
import random
import hashlib


from Crypto.Cipher import AES
from odoo.exceptions import ValidationError
from odoo import api, fields, models
from datetime import datetime
from werkzeug import urls
import hashlib
import json
import logging
import requests
from paytrail import common

from odoo import api, fields, models, _
from odoo.tools.float_utils import float_compare, float_repr, float_round
from odoo.addons.payment.models.payment_acquirer import ValidationError
from datetime import datetime

_logger = logging.getLogger(__name__)


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

provider = fields.Selection(selection_add=[('paytrail', 'Paytrail')])
paytrail_key_id = fields.Char(string='Merchant ID', required_if_provider='paytrail', groups='base.group_user')
# paytrail_merchant_id = fields.Char(string='Merchant ID', required_if_provider='paytrail', groups='base.group_user')

paytrail_key_secret = fields.Char(string='Merchant Key', required_if_provider='paytrail', groups='base.group_user')

@api.model
def _get_paytrail_urls(self):
""" Atom URLS """
return {
'paytrail_form_url': 'https://payment.paytrail.com/e2'
}

def paytrail_get_form_action_url(self):
return self._get_paytrail_urls()['paytrail_form_url']

def _dial(self, method, location, body):
'''Make the authorization HTTP headers and call the API URL.

Returns the standard HTTPResponse object.'''

headers = common.makeHeaders(self.APINAME, common.makeTimestamp(), self.apiKey, self.secret, method, location,
body)
conn = self.connectionMethod(self.apiLocation)
conn.request(method, location, body, headers)

return conn.getresponse()


def paytrail_form_generate_values(self, values):
self.ensure_one()
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
now = datetime.now()
MID = int(self.paytrail_key_id)
url_success = 'http://www.example.com/success'
url_cancel = 'http://www.example.com/cancel'
# order_number = values.get('reference')
order_number = 12345
merchant_key = self.paytrail_key_secret

payment_id = ''
timestamp = ''
status = ''
locale = "en_US"

paytm_values = dict(
# paytrail_values = dict(

MID = int(self.paytrail_key_id),
# url_success = 'url/payment/success',
# url_cancel = 'url/payment/cancel',
url_success = 'http://www.example.com/success',
url_cancel = 'http://www.example.com/cancel',
# order_number = values.get('reference'),
order_number = 12345,
order_number1 = str(values['reference']),
# params_in = [MID, url_success, url_cancel, order_number, params_in, params_out ],
params_in=[MID, url_success, url_cancel, order_number, locale],
locale = "en_US",
params_out = [payment_id, timestamp, status],
amount = '350',

)

# paytm_values['reqHashKey'] = self.generate_checksum(paytm_values,merchant_key)
# paytm_values['reqHashKey'] = '6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ'
paytm_values['reqHashKey'] = 'BBDF8997A56F97DC0A46C99C88C2EEF9D541AAD59CFF2695D0DD9AF474086D71'

r = requests.post(url=self.paytrail_get_form_action_url(), data=paytm_values)
print("rrrrrrrrrr :", r)

paytm_values_json = json.dumps(paytm_values, indent = 2)
return paytm_values

# r = requests.post(url=paytrail_get_form_action_url(self), data=paytm_values)
# print("rrrrrrrrrr :", r)

def __encode__(self, to_encode, iv, key):
__pad__ = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16)
# Pad
to_encode = __pad__(to_encode)
# Encrypt
c = AES.new(key, AES.MODE_CBC, iv)
to_encode = c.encrypt(to_encode)
# Encode
to_encode = base64.b64encode(to_encode)
return to_encode.decode("UTF-8")

def __decode__(self, to_decode, iv, key):
# Decode
to_decode = base64.b64decode(to_decode)
# Decrypt
c = AES.new(key, AES.MODE_CBC, iv)
to_decode = c.decrypt(to_decode)
if type(to_decode) == bytes:
# convert bytes array to str.
to_decode = to_decode.decode()
# remove pad
return self.__unpad__(to_decode)

def generate_checksum(self,param_dict ,merchant_key ,salt=None):
params_string=self.__get_param_string__ (param_dict)
return self.generate_checksum_by_str (params_string ,merchant_key ,salt)

def generate_checksum_by_str(self, param_str, merchant_key, salt=None):
IV = "@@@@&&&&####$$$$"
params_string = param_str
salt = salt if salt else self.__id_generator__(4)
final_string = '%s|%s' % (params_string, salt)

hasher = hashlib.sha256(final_string.encode())
hash_string = hasher.hexdigest()

hash_string += salt

return self.__encode__(hash_string, IV, merchant_key)




class PaymentTransaction(models.Model):
_inherit = 'payment.transaction'

@api.model
def _create_paytrail_capture(self, data):
payment_acquirer = self.env['payment.acquirer'].search([('provider', '=', 'paytrail')], limit=1)
payment_url = "https://payment.paytrail.com/e2" % (payment_acquirer.paytrail_key_id, payment_acquirer.paytrail_key_secret, data.get('payment_id'))
try:
payment_response = requests.get(payment_url)
payment_response = payment_response.json()
except Exception as e:
raise e
# reference = payment_response.get('notes', {}).get('order_id', False)
# if reference:
# transaction = self.search([('reference', '=', reference)])
# capture_url = "https://%s:%s@api.razorpay.com/v1/payments/%s/capture" % (payment_acquirer.razorpay_key_id, payment_acquirer.razorpay_key_secret, data.get('payment_id'))
# charge_data = {'amount': int(transaction.amount * 100)}
# try:
# payment_response = requests.post(capture_url, data=charge_data)
# payment_response = payment_response.json()
# except Exception as e:
# raise e
return payment_response


views/payment_paytrail_template.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="paytrail_form">
<div>
<input type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
<input type="hidden" name="MID" t-att-value='MID'/>
<input type="hidden" name="URL_SUCCESS" t-att-value='url_success'/><input type="hidden" name="URL_CANCEL" t-att-value='url_cancel'/>
<input type="hidden" name="order_number" t-att-value='order_number'/>
<input type="hidden" name="params_in" t-att-value='params_in'/>
<input type="hidden" name="params_out" t-att-value='params_out'/>
<input type="hidden" name="amount" t-att-value='amount'/>
<input type="hidden" name="locale" t-att-value='locale'/>
<script type="text/javascript" src="/payment_gateway/static/src/js/paytrail.js"></script>
</div>
</template>
</odoo>

controllers/controllers.py

import logging
import pprint
import werkzeug
from werkzeug.utils import redirect
from odoo import http
from odoo.http import request
_logger = logging.getLogger(__name__)


class AtomController(http.Controller):
@http.route(['/payment/paytrail/return/', '/payment/paytrail/cancel/', '/payment/paytrail/error/'],
type='http', auth='public', csrf=False)
def paytm_return(self, **post):
""" Paytm."""

_logger.info(
'Paytrail: entering form_feedback with post data %s', pprint.pformat(post))
if post:
request.env['payment.transaction'].sudo().form_feedback(post, 'paytrail')
return werkzeug.utils.redirect('/payment/process')
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 integrate a third party payment gateway with dotoo?
development integration gateway payment guide
Avatar
Avatar
Avatar
2
de gen. 21
5142
Sage Pay Integration RedirectURL error code : 5006
integration gateway payment ecommerce post
Avatar
Avatar
Avatar
2
de juny 18
6605
Payment Gateway integration Solved
community integration gateway payment odoo9
Avatar
Avatar
Avatar
Avatar
3
de maig 18
16009
pax s300 terminal integration with odoo 12
integration payment odoo
Avatar
0
de nov. 25
3893
New payment integration for yookassa payment aggregator
integration payment payment provider
Avatar
Avatar
1
de juny 25
2291
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