Skip to Content
Menu
This question has been flagged

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\\

Avatar
Discard
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


Avatar
Discard

Hi Micheal,

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

Tx, Sven

Related Posts Replies Views Activity
2
Feb 24
925
1
Feb 24
743
0
Nov 23
277
0
Jun 23
1472
1
Feb 23
977