Enable Dark Mode!
By: Niyas Raphy

Payment Gateway Integration in Odoo

Technical Website&E-commerce

Payment Gateway Integration

Integrating the payment gateway with Odoo is an easy task if we have a basic knowledge in python. In this section let us look how to integration on a payment gateway with the Odoo. First of all, I am using the Paytab as the payment gateway provider here.

Once we create an account in the Pay tab we will get a merchant email and secret key. Which is then used as the login credentials.

After creating the account in Pay tab, we now let us focus on the integration. The main steps in the integration is,

  1. Validating the secret key
  2. Creating the pay page
  3. Verifying the payment

Now let us look how to validate the secret key

Secret Key validation

The secret is validating to check the existence of the account and to know the details of the account to which the amount has to be remitted.

This method uses the merchant email and secret key to validate your credentials.

You can find the secret key from your Pay tab account like this.

Click on Merchant’s Dashboard >> Pay Tabs Services >> e-commerce

Plugins and API. Here you can find the merchant email and the secret key.

After getting the both, we have to send a request to validate secret key like this,

URL: https://www.paytabs.com/apiv2/validate_secret_key

Method: POST


We have to pass the merchant email and the secret key along with this URL.

For the validation of the secret key.

Sample Code:

secret_key_validation_url = 'https://www.paytabs.com/apiv2/validate_secret_key/{}'
merchant_email = 'niyasraphyk@gmail.com'
secret_key = 'BSWzZCWTrCgeKzCpS3rugWnhWNDgNFopykYxXVqpxGDiggI9kaDA61S2OviCbH1K1ZiZUJosp1LGhtPBDtcKu4MiA5UMMWxOVPNQ'
params = {'merchant_email': merchant_email, 'secret_key': secret_key}
r = requests.post(url=secret_key_validation_url, data=params)

This is how we will send the validation request, then we will get the response from the gateway in the variable r.

Let us look the different response that we are possible to get,

4000Vaid Secret Key
4001missing secret_key or merchant_email parameter
4002Invalid Secret Key

If we get a response of 4000, we can process to the next step, i.e., Pay Page creation.

To get the response code from the variable r, we can use the following code

r = requests.post(url=payment_url, data=params)
d = ast.literal_eval(r.text)
print d['response_code']

Pay page creation

Pay page creation method will accept all the parameters required to create a Pay Page and then return the response as well as the link where all the parameters posted to the API will appear in the Pay Page customer can enter ONLY the credit card information such as account number and cvv to make the payment.

For the Pay Page creation, we have to pass the following values.

cc_first_nameFirst Name of the CustomerStringniyas
cc_last_nameLast Name of the CustomerStringraphy
cc_phone_numberCountry code for Phone Number of the CustomerString+91
phone_numberPhone Number of the CustomerString7736******
emailEmail of the customerStringniyasraphyk@gmail.com
products_per_titleProduct title of the product. If multiple products then add “||” separatorStringE.g.: IPhone || Samsung S5 || Samsung S4
unit_priceUnit price of the product. If multiple products then add “||” separatorStringE.g.: 21.09 || 22.12 || 12.01
quantityQuantity of products. If multiple Products then add “||” separator.StringE.g.: 1 || 2 || 3
other_chargesAdditional charges. e.g.: shipping charges, taxes, VAT, etcStringE.g.: 123.399
amountAmount of the products and other charges, it should be equal to: amount = (sum of all products’ (unit_price * quantity)) + other_charges This field will be displayed in the invoice as the subtotal fieldStringE.g.: 123.399
discountDiscount of the transaction The Total amount of the invoice will be= amount - discountStringE.g.: 123.399
currencyCurrency of the amount stated. 3 character ISO currency codeString
reference_noInvoice reference numberStringE.g.: Abc-5566
ip_customerThe client IP with which the order is placed.StringE.g.:
ip_merchantServer IP where the order is coming fromStringE.g.:
billing_addressComplete Address of the customer. Multiple address lines will be Merged into one single line.String
stateBilling State (part of the address) entered by the customerStringE.g.: Manama
cityName of the billing city selected by customerStringE.g.: Manama
postal_codeBilling Postal code provided by the customerString12345
countryCountry of the customerStringBHR
shipping_first_nameFirst Name of the Customer in shipping addressStringniyas
shipping_last_nameLast Name of the Customer in shipping addressStringraphy
address_shippingShipping address of the customerStringFlat abc road 123
city_shippingShipping City of the customerStringManama
state_shippingShipping State of the customerStringManama
postal_code_shippingShipping postal code of the customerString403129
country_shippingShipping country of the customerStringBHR
msg_langLanguage of the Pay Page to be created. Invalid or blank entries will default to EnglishStringEnglish / Arabic
cms_with_versionCMS / Language that you are using with its version. This will help us to troubleshoot issues, if any.StringMagento 0.1.9

The above-listed fields are required to create a Pay Page so that we have .to pass all these data along with the URL to create the Pay Page. 

URL: https://www.paytabs.com/apiv2/create_pay_page

Method: POST

Sample code

pay_page_url = "https://www.paytabs.com/apiv2/create_pay_page"
params2 = {'merchant_email': merchant_email, 'secret_key': secret_key, 'pay_page_url': pay_page_url,
           'site_url': site_url, 'return_url': return_url, 'title': title, 'currency': currency,
           'amount': amount, 'quantity': quantity, 'unit_price': unit_price, 'discount': discount,
           'other_charges': other_charges, 'cc_first_name': cc_first_name, 'cc_last_name': cc_last_name,
           'cc_phone_number': cc_phone_number, 'phone_number': phone_number, 'email': email,
           'products_per_title': products_per_title, 'msg_lang': msg_lang, 'country_shipping': country_shipping,
           'postal_code_shipping': postal_code_shipping, 'state_shipping': state_shipping,
           'city_shipping': city_shipping, 'address_shipping': address_shipping,
           'billing_address': billing_address, 'shipping_last_name': shipping_last_name,
           'shipping_first_name': shipping_first_name, 'country': country, 'postal_code': postal_code,
           'reference_no': reference_no, 'state': state, 'city': city, 'ip_merchant': ip_merchant,
           'ip_customer': ip_customer, 'cms_with_version': cms_with_version}
d = requests.post(url=pay_page_url, data=params2)

 After placing this request, we will get a response from the gateway.

 Response message

4012Pay Page created successfully
4404You don't have permissions to create an Invoice
4001Variable not found
4002Invalid Credentials
4007'currency' code used is invalid. Only 3 character ISO currency codes are valid.
4008Your SITE URL is not matching with your profile URL
4013Your 'amount' post variable should be between 0.27 and 5000.00 USD
4014Products titles, Prices, quantity are not matching
4094Your total amount is not matching with the sum of unit price amounts per quantity

Once the payment page is created successfully (pay page is the page where which user can add his card details)

After entering the card details, a user can click the pay now button. On creating the Pay Page we have to pass one more value, i.e., return url, the URL to which the page gets redirected after the payment.

Payment Verification 

To verify the payment we will receive a p_id in the response message to the page.

URL: https://www.paytabs.com/apiv2/verify_payment

Method: POST

To verify the payment we have to pass the following parameters along with url 

merchant_emailMerchant email that you use to sign up and/or login into Pay tabs Merchant Dashboardniyasraphyk@gmail.com
secret_keySECRET Key generated by merchant dashboardEG :- BSWzZCWTrCgeKzCpS3rugWnhWNDg NFopykYxXVqpxGDiggI9kaDA61S2OviCbH1K1ZiZUJ osp1LGhtPBDtcKu4MiA5UMMWxOVPNQ
payment_referenceThis is the p_id that is returned in the response of create Pay Page when the page is created successfully.E.g.: t2938yh202tu0

Response codes that you will get after this, 

Error CodeDescription
4001Missing parameters
4002Invalid Credentials
0404You don't have permissions
0400There are no transactions available
100Payment is completed
481 482This transaction may be suspicious. If this transaction is genuine, please contact Pay tabs customer service to inquire about the feasibility of processing this transaction.
Any response code other than 100, 481,482Any other response than 100, 482, 481 means that the transaction has been rejected and the rejection reason is the description of the corresponding response code

Sample code

verify_payment = 'https://www.paytabs.com/apiv2/verify_payment/{}'
merchant_email = "malappuram132@gmail.com"
secret_key = "BSWzZCWTrCgeKzCpS3rugWnhWNDgNFopykYxXVqpxGDiggI9kaDA61S2OviCbH1K1ZiZUJosp1LGhtPBDtcKu4MiA5UMMWxOVPNQ"
p_id = "85533"
params = {'merchant_email': merchant_email, 'secret_key': secret_key, 'payment_reference': p_id}
g = requests.post(url=verify_payment, data=params)

This is how a payment gateway odoo integration with the pay tab is done

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



Great. Nice and informative. Thanks for sharing the tutorial.





Doesn't show anything related to odoo, or at least to newbies.




Odoo User

Does Not show anything Related to odoo Integration or least for newbies




Leave a comment




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



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



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

Send Us A Message