Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

I cant't pass form to Paytrail Payment gateway ?

Subscribe

Get notified when there's activity on this post

This question has been flagged
integrationgatewaypayment
6593 Views
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
How integrate a third party payment gateway with dotoo?
development integration gateway payment guide
Avatar
Avatar
Avatar
2
Jan 21
6203
Sage Pay Integration RedirectURL error code : 5006
integration gateway payment ecommerce post
Avatar
Avatar
Avatar
2
Jun 18
7666
Payment Gateway integration Solved
community integration gateway payment odoo9
Avatar
Avatar
Avatar
Avatar
3
May 18
17599
pax s300 terminal integration with odoo 12
integration payment odoo
Avatar
0
Nov 25
5041
New payment integration for yookassa payment aggregator
integration payment payment provider
Avatar
Avatar
1
Jun 25
3581
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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