Enable Dark Mode!
payment-gateway-integration-in-odoo.jpg
By: Noushid Khan

What is Payment Gateway Integration in Odoo

Technical

Monetary transactions for the mercantile sector are dealt by the payment Gateway schemes which include transactions such as credit card, recurring and electronic funds transfers (EFT). All systems which are properly integrated will receive transaction information at the purchase points through key entry or card swipe, which will be transmitted to the payment gateway system. A response will be reflected at the point of purchase once the system process approval or decline of the transaction.
It's very easy to integrate payment gateways in Odoo with just basic python programming knowledge and basic integration skills and formats.
In this blog let's discuss the default Odoo payment gateway integration with the help of an example here: the Paytm integration is described.
Now let's move on to the Paytm integration steps .
In the paytm record, it needs some extra fields for adding some needful data. In each case it could be different, add the fields as per your requirement.
Moreover we can add a Paytm record here using the XML code given below.
<record id="payment_acquirer_atom" model="payment.acquirer">
   <field name="name">Paytm</field>
   <field name="provider">paytm</field>
   <field name="company_id" ref="base.main_company"/>
   <field name="image_128" type="base64"         file="paytm_payment_gateway/static/description/icon.png"/>
   <field name="view_template_id" ref="paytm_form"/>
   <field name="state">test</field>
   <field name="paytm_merchant_id">demo</field>
   <field name="paytm_merchant_key">demo</field>
</record>
The below image is the Paytm payment acquirer configuration window in Odoo.
payment-gateway-integration-in-odoo-cybrosys
Here in payment acquirer we can add the credentials merchant ID and  merchant key which we get when we register for a  Paytm account under developer settings as described in the following image.
payment-gateway-integration-in-odoo-cybrosys
Let's now checkout the integration procedure to complete this transaction.
Odoo provides some default functions for the payment gateway integration. We can use it along with some extra functions to check the different cases for various payment gateways. Down below are the certain default functions we use for this:
In this we have a method def “payment gateway name”_form_generate_values(self, values), this will provide the latest transaction values in the function and also have certain default methods. These functions will be called upon when we click the pay now button in the payment page. In the function we will create a dictionary with all the needed data for the payment page, for an example in the case of Paytm we can write like below:

def paytm_form_generate_values(self,values):
paytm_values=dict (
                 MID=self.paytm_merchant_id ,
                 ORDER_ID=str(values ['reference']) ,
                 CUST_ID = str(values.get('partner_id')),
                 INDUSTRY_TYPE_ID='Retail' ,
                 CHANNEL_ID = 'WEB',
                 TXN_AMOUNT=str(values ['amount']) ,
                 WEBSITE='WEBSTAGING',
                 EMAIL=str(values.get ('partner_email')) ,
                 MOBILE_NO = str(values.get('partner_phone')),
                 CALL_BACK_URL=urls.url_join (base_url ,'/payment/paytm/return/') ,
                 )
We can set up the dictionary like above this dictionary will return from its function.
Example for API response is given below:
{'partner_id': 3, 'type': 'form', 'return_url': '/payment/process', 'reference': 'S00036-6', 'amount': 1508.64, 'currency_id': 2, 'currency': res.currency(2,), 'partner': res.partner(3,), 'partner_name': 'Mitchell Admin', 'partner_lang': 'en_US', 'partner_email': 'admin@yourcompany.example.com', 'partner_zip': '18503', 'partner_city': 'Scranton', 'partner_address': '215 Vine St', 'partner_country_id': 233, 'partner_country': res.country(233,), 'partner_phone': '+1 555-555-5555', 'partner_state': res.country.state(47,), 'billing_partner': res.partner(3,), 'billing_partner_id': 3, 'billing_partner_name': 'Mitchell Admin', 'billing_partner_commercial_company_name': 'YourCompany', 'billing_partner_lang': 'en_US', 'billing_partner_email': 'admin@yourcompany.example.com', 'billing_partner_zip': '18503', 'billing_partner_city': 'Scranton', 'billing_partner_address': '215 Vine St', 'billing_partner_country_id': 233, 'billing_partner_country': res.country(233,), 'billing_partner_phone': '+1 555-555-5555', 'billing_partner_state': res.country.state(47,), 'partner_first_name': 'Mitchell', 'partner_last_name': 'Admin', 'billing_partner_first_name': 'Mitchell', 'billing_partner_last_name': 'Admin'}
Next default function is def “payment gateway name”_get_form_action_url()
In Paytm we can use it as def paytm_get_form_action_url(self)
It will call the payment processing url from the other function that will be set as def get_”payment gateway name”_urls()
Here, it can be set as def get_paytm_urls(self) which will set the url for the order processing page of the needed payment gateway. These are the default functions that need to be added in the payment acquirer model by inheriting it.
There are three more functions to run, that functions will add in the payment transaction model by inheriting it.
The first one is def _”payment gateway name”_form_get_tx_from_data(self, data) it uses  check the transaction record in the transaction model based on transaction data, this function will return the specific transaction record.
In the Paytm we can write the function like def paytm_form_get_tx_from-data(self,data)
Another default function we use is def _”payment gateway name”_form_get_invalid_parameters(self ,data):
This function is used to get invalid parameters from the transaction which will return the invalid parameters in the specific transaction.
This can be used as def _paytm_form_get_invalid_parameters(self, data).
Next function we use is def _”payment gateway method”_form_validate(self ,data):
This function is used to validate the transaction details checking the transaction status from the given data in the functions. If the status is successful then the transaction is processed and it will be redirected to the payment success page. Otherwise the transaction will be cancelled, and will return the write function result of the payment transaction based on payment acquire and date.
This is a general method for doing payment integration in Odoo.
Furthermore, in Odoo addons having payment acquire modules configured are done using the above method.
Watch Video:


If you need any assistance in odoo, we are online, please chat with us.



1
Comments

SHAN E ALAM

if possible please write a blog fot paytm integration in odoo15

16/06/2022

-

6:56AM



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message