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
    • Approvals
    • 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

How to Create Custom Payment Acquirer External Java Script

Subscribe

Get notified when there's activity on this post

This question has been flagged
payment automationodoo13.0payment-acquirers
1 Reply
5834 Views
Avatar
Michael Byrne

Hi there,

I need to add a custom Payment Acquirer called PayToday. They only exist in Namibia as we cannot use any international ones. The script was intended to just serve on HTML websites.


They only have a Java script which is executed by a PayToday button, passing parameters on CDATA.:

Code in HTML:

<!DOCTYPE html>

<html>

<head>

    <title>TEST PAYTODAY SCRIPT</title>

</head>

<body>

 

<div id="paytodaybtn"></div>

<script type="text/javascript" src="\https\:\/\/paytoday\.com\.na\/js\/pay\-with\-paytoday\.js\"\"\&gt\;\&lt\;\/script\\&gt\;\\\\\

\\&lt\;script\ type\=\"text\/javascript\"\&gt\;\\\\\

\\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\\\\

\\/\/\&lt\;\!\[CDATA\[\\\\\

\document\.addEventListener\(\'DOMContentLoaded\'\,\ function\(\)\ \{\\\\\

\createButton\(\'Business_ID\'\,\ \'My_Business_name\'\,\ \'Amount\'\,\ \'Thank_you_URL\'\,\ \'Reference_Number\'\)\;\ \}\)\;\ \/\/\]\]\&gt\;\\&nbsp\;\\\\\\

\\&lt\;\/script\&gt\;\\\\\

\\\&nbsp\;\\\\

\\&lt\;\/body\&gt\;\\\\\

\\&lt\;\/html\&gt\;\\\\\

\When\ the\ webpage\ opens\ I\ need\ to\ press\ the\ \"button\"\ as\ Below\,\\&nbsp\;\\\\\\

\\\&nbsp\;\\\\

\\\&nbsp\;\\\\

\\\&nbsp\;\\\\

\\\\\\\\\

\\&nbsp\;and\ it\ opens\ the\ page\ as\ below\:\\\\\

\\\&nbsp\;\\\\

\\\\with\ the\ required\ values\ passed\.\ Client\ can\ choose\ to\ pay\ via\ mobile\ number\ or\ CC\.\\\\\

\\\&nbsp\;\\\\

\On\ \"Continue\"\ it\ passed\ parameters\ back\ \"success\"\ or\ \"Failed\"\ again\ in\ Java\.\\\\\

\I\ have\ read\ most\ of\ the\ forums\/\ bloges\,\ looked\ all\ the\ payment\ acquirers\ in\ Odoo\,\ but\ I\ cannot\ seem\ to\ figure\ out\ how\ to\:\\\\\

\On\ odoo\ Pay\ Now\ \"Paytoday\"\,\&nbsp\;\ automatically\ calling\ the\ \"Pay\ with\ PayToday\ button\"\ and\ passing\ the\ parameters\ to\ create\ the\ Function\ so\ the\ Paytoday\ Payment\ screen\ pops\ up\ with\ the\ Values\.\ On\ \"submit\ payment\"\ on\ Paytoaday\,\ receive\ the\ values\ and\ continue\ normal\ checkout\ process\ in\ odoo\ with\ payment\ completed\.\ \(no\ tokens\,\ no\ authentications\.\ This\ as\ close\ as\ it\ comes\ to\ a\ API\)\\\\\

\I\ have\ created\ a\ custom\ module\ payment_paytoday\:\\\\\

\payment_acquirer_data\.xml\:\\\\\

\\&lt\;\?\\xml\ version\\\=\"1\.0\"\\&nbsp\;\\\encoding\\\=\"utf\-8\"\\\?\&gt\;\
\&lt\;odoo\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\ \&lt\;data\\&nbsp\;\\\noupdate\\\=\"1\"\\\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \&lt\;record\\&nbsp\;\\\id\\\=\"payment_acquirer_paytoday\"\\&nbsp\;\\\model\\\=\"payment\.acquirer\"\\\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \&lt\;field\\&nbsp\;\\\name\\\=\"name\"\\\&gt\;\\PayToday\\\&lt\;\/field\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \&lt\;field\\&nbsp\;\\\name\\\=\"provider\"\\\&gt\;\\paytoday\\\&lt\;\/field\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&lt\;field\\&nbsp\;\\\name\\\=\"company_id\"\\&nbsp\;\\\ref\\\=\"base\.main_company\"\\\/\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \&lt\;field\\&nbsp\;\\\name\\\=\"image_128\"\\&nbsp\;\\\type\\\=\"base64\"\\&nbsp\;\\\file\\\=\"payment_paytoday\/static\/src\/img\/paytoday_icon\.png\"\\\/\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \&lt\;field\\&nbsp\;\\\name\\\=\"view_template_id\"\\&nbsp\;\\\ref\\\=\"payment_paytoday\.paytoday_form\"\\\/\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \&nbsp\;\&lt\;\/record\&gt\;\
\&nbsp\;\&nbsp\;\&nbsp\;\ \&lt\;\/data\&gt\;\
\&lt\;\/odoo\&gt\;\\\\\\\

\Python\ payment\.py\\\\\

\\#\ coding\:\ utf\-8\
\
\\import\\&nbsp\;\\\logging\
\\import\\&nbsp\;\\\requests\
\
\\from\\&nbsp\;\\\odoo\\&nbsp\;\\\import\\&nbsp\;\\\api\\\,\\&nbsp\;\\\fields\\\,\\&nbsp\;\\\models\
\\from\\&nbsp\;\\\odoo\.tools\.float_utils\\&nbsp\;\\\import\\&nbsp\;\\\float_compare\\\,\\&nbsp\;\\\float_repr\\\,\\&nbsp\;\\\float_round\
\\from\\&nbsp\;\\\odoo\.addons\.payment\.models\.payment_acquirer\\&nbsp\;\\\import\\&nbsp\;\\\ValidationError\
\
_logger\ \=\ logging\.getLogger\(__name__\)\
\
\
\\class\\&nbsp\;\\\AcquirerPayToday\(models\.Model\)\:\
\&nbsp\;\&nbsp\;\&nbsp\;\ _inherit\ \=\\&nbsp\;\\\\'payment\.acquirer\'\
\
\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\provider\ \=\ fields\.Selection\(\\selection_add\\\=\[\(\\\'paytoday\'\\\,\\&nbsp\;\\\\'PayToday\'\\\)\]\)\
\&nbsp\;\&nbsp\;\&nbsp\;\ paytoday_business_id\ \=\ fields\.Char\(\\\'Paytoday\ ID\'\\\,\\&nbsp\;\\\required_if_provider\\\=\\\'paytoday\'\\\,\\&nbsp\;\\\groups\\\=\\\'base\.group_user\'\\\)\
\&nbsp\;\&nbsp\;\&nbsp\;\ paytoday_business_name\ \=\ fields\.Char\(\\\'Business\ Name\'\\\,\\&nbsp\;\\\required_if_provider\\\=\\\'paytoday\'\\\,\\&nbsp\;\\\groups\\\=\\\'base\.group_user\'\\\)\
\
\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\def\\&nbsp\;\\\paytoday_form_generate_values\\\(\\self\\\,\\&nbsp\;\\\values\)\:\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\self\\\.ensure_one\(\)\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\\#\ currency\ \=\ self\.env\[\'res\.currency\'\]\.sudo\(\)\.browse\(values\[\'currency_id\'\]\)\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \#\ if\ currency\ \!\=\ self\.env\.ref\(\'base\.NAD\'\)\:\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\ \#\&nbsp\;\&nbsp\;\&nbsp\;\ raise\ ValidationError\(_\(\'Currency\ not\ supported\ by\ PayToday\'\)\)\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\values\.update\(\{\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\\'business_id\'\\\:\\&nbsp\;\\\self\\\.paytoday_business_id\\\,\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\\'business_name\'\\\:\\&nbsp\;\\\self\\\.paytoday_business_name\\\,\
\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\\&nbsp\;\\\\'amount\'\\\:\ float_repr\(float_round\(values\.get\(\\\'amount\'\\\)\\\,\\&nbsp\;\\\2\\

0
Avatar
Discard
Avatar
Michael Byrne
Author Best Answer

Don't know why it came out so weird... attached are the pictures and code again.

the Jave script executed when pressing the button is:


Script

<div id="paytodaybtn"></div>
<script src="https://paytoday.com.na/js/pay-with-paytoday.js"></script> <script type="text/javascript">

//<![CDATA[
document.addEventListener('DOMContentLoaded', function() {
createButton('
Business_ID', 'Business_Name', 'Amount', 'Thank_you_URL', 'Reference_Number'); });

//]]> </script> 


the Java in HTMl looks like this:


If you press the button it opens:




with the passed parameters.

with the required values passed. Client can choose to pay via mobile number or CC.

 

On "Continue" it passed parameters back "success" or "Failed" again in Java.

I have read most of the forums/ blogs, looked all the payment acquirers in Odoo, but I cannot seem to figure out how to:

On odoo Pay Now "Paytoday",  automatically calling the "Pay with PayToday button" and passing the parameters to create the Function so the Paytoday Payment screen pops up with the Values. On "submit payment" on Paytoaday, receive the values and continue normal checkout process in odoo with payment completed. (no tokens, no authentications. This as close as it comes to a API)

I have created a custom module payment_paytoday:

payment_acquirer_data.xml:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data 
noupdate="1">
        <record 
id="payment_acquirer_paytoday" model="payment.acquirer">
            <field 
name="name">PayToday</field>
            <field 
name="provider">paytoday</field>
            <field 
name="company_id" ref="base.main_company"/>
            <field 
name="image_128" type="base64" file="payment_paytoday/static/src/img/paytoday_icon.png"/>
            <field 
name="view_template_id" ref="payment_paytoday.paytoday_form"/>
        </record>
    </data>
</odoo>

Python payment.py

# coding: utf-8

import logging
import requests

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

_logger = logging.getLogger(__name__)


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

    
provider = fields.Selection(selection_add=[('paytoday', 'PayToday')])
    paytoday_business_id = fields.Char(
'Paytoday ID', required_if_provider='paytoday', groups='base.group_user')
    paytoday_business_name = fields.Char(
'Business Name', required_if_provider='paytoday', groups='base.group_user')

    
def paytoday_form_generate_values(self, values):
        
self.ensure_one()
        
# currency = self.env['res.currency'].sudo().browse(values['currency_id'])
        # if currency != self.env.ref('base.NAD'):
        #    raise ValidationError(_('Currency not supported by PayToday'))
        
values.update({
            
'business_id': self.paytoday_business_id,
            
'business_name': self.paytoday_business_name,
            
'amount': float_repr(float_round(values.get('amount'), 2) * 100, 0),
            
'thank_you_url': '',
            
'reference': values.get('reference'),
        
})
        
print(values)
        
return values

and payment_paytoday_template.xml:

<?xml version="1.0" encoding="utf-8"?>


<odoo>
    <template 
id="paytoday_form">
        <t 
t-name="payment.default_acquirer_button">
            <form 
action="\http://172.17.24.130/paytoday" method="post" target="_self">
                <input 
type="hidden" name="data_set" t-att-data-action-url="tx_url" data-remove-me=""/>
                <input 
type="hidden" name="business_id" t-att-value='business_id'/>
                <input 
type="hidden" name="business_name" t-att-value="business_name"/>
                <input 
type="hidden" name="amount" t-att-value='amount'/>
                <inout 
type="hidden" name="reference" t-att-value="reference"/>
                
<!-- Submit -->

                
<button type="submit" width="100px" t-att-class="submit_class">
                    <img 
t-if="not submit_txt" src="/payment_transfer/static/src/img/transfer_icon.png"/>
                    <span 
t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span>
                </button>
            </form>
        </t>
    </template>
</odoo>

I am new to odoo. Can someone please help me or point me in the right direction or just tell me if this is actually possible?

Your help would be greatly appreciated. Have been struggeling for 5 days now and out of ideas.

 

I dont even know if this is easy or not..... Please help.

 

Regards

 

Michael Byrne


0
Avatar
Discard
Tack Shack, Sveng

Hi Micheal,

Did yu ever get this implemented? If how did you achieve it.

Tx, Sven

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
payment provider issues / External ID not found in the system: payment.payment_icon_cc_mastercard
payment-acquirers
Avatar
Avatar
2
Feb 24
4459
Payment provider ( Payment processing failed Expecting value: line 1 column 1 (char 0) )
payment-acquirers
Avatar
Avatar
1
Feb 24
3222
Can not add activity with record rule on vendor bill followers
odoo13.0
Avatar
0
Nov 23
2097
Vendor Bill not created from email
odoo13.0
Avatar
0
Jun 23
3220
Computing Signature Hash for New Payment Acquirer
payment-acquirers
Avatar
Avatar
1
Feb 23
2732
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