Enable Dark Mode!
default-payment-gateway-integration-in-odoo-15.jpg
By: Megha K

Default Payment Gateway Integration in Odoo 15

Technical Odoo 15

In a real-time scenario, the most commonly used financial transactions take place online, so it is essential to make possible the secure transmission of payment transaction data. A hosted software application that processes and makes payments between consumers and merchants is a payment gateway. Odoo ERP supports integrations with Paypal, Adyen, PayUmoney, Buckaroo, Authorize.net, Sips, and Stripe.
In this blog, we are going to discuss the default Odoo payment gateway integration with the help of an example.
Now let's move on to the Adyen integration steps.
While integrating a payment gateway with Odoo, first, we need to select a payment acquirer. Here we select Adyen as our payment provider.
In the Adyen record, it needs some fields for adding some needful data. It is different for each payment acquirer. Add the fields as per your requirement.    
<record id="payment.payment_acquirer_adyen" model="payment.acquirer">
   <field name="provider">adyen</field>
   <field name="inline_form_view_id" ref="inline_form"/>
   <field name="support_authorization">False</field>
   <field name="support_fees_computation">False</field>
   <field name="support_refund">partial</field>
   <field name="support_tokenization">True</field>
   <field name="allow_tokenization">True</field>
</record>
For the case of Adyen, we need some fields to save the credential details in our database. We must define those fields and add them to the acquirer view. Also, extend the selection field provider and add your provider name to it.
provider = fields.Selection(selection_add=[('adyen', "Adyen")], ondelete={'adyen': 'set default'})
Odoo provides some default functions to do payment gateway integration. By using some extra functions with those functions, we can check the different cases for various payment gateways.
Here are some default functions we use for this:
_get_specific_processing_values: this function is used to Return a dict of acquirer-specific values used to process the transaction. For an acquirer to add its own processing values, it must overwrite this method and return a dict of acquirer-specific processing values based on the generic values returned by this method. When clicking the pay now button on the payment page is called those functions.
Next function is _get_specific_rendering_values. This function is used to Return a dict of acquirer-specific values used to render the redirect form. For an acquirer to add its own rendering values, it must overwrite this method and return a dict of acquirer-specific values based on the processing values.
Also, we can create those redirect and inline form templates. We have two methods to pass those values. That is, we can pass it in an inline form, or we can pass it into a redirect page.
Inline form example:
<template id="inline_form">
   <div t-attf-id="o_adyen_dropin_container_{{acquirer_id}}" class="o_adyen_dropin"/>
</template>
Redirect from example:
<template id="redirect_form">
   <form t-att-action="api_url" method="post">
       <input type="hidden" name="Data" t-att-value="Data"/>
       <input type="hidden" name="InterfaceVersion" t-att-value="InterfaceVersion"/>
       <input type="hidden" name="Seal" t-att-value="Seal"/>
   </form>
</template>
_handle_feedback_data: It matches the transaction with feedback data, updates its state, and returns it.
_get_tx_form_feedback_data: This function is used to find the transaction based on the feedback data. For an acquirer to handle transaction post-processing, it must overwrite this method and return the transaction matching the data.
_process_feedback_data: It is used to update the transaction state and the acquirer reference based on the feedback data. It will be redirected to the payment status page. If the status is successful, then the transaction is processed. Otherwise, the transaction will be canceled or in an authorized state.
Also, we need to create a payment method for each payment acquirer. So we need to create a record for that.    
<record id="payment_method_adyen" model="account.payment.method">
           <field name="name">Adyen</field>
           <field name="code">adyen</field>
           <field name="payment_type">inbound</field>
</record>
This is the record of the payment method for Adyen. Also, we need to rewrite two functions that are _get_payment_method_information. This function is used to initialize the payment method. Next function is _get_default_payment_method_id, it is used to get the default payment method.
In payment integration, we need to specify the method, that is, in inline form or in redirect form. You can refer to the default payment acquirer that Odoo provides, like Paypal, mollie, paylatam, etc... In those gateways, it uses a redirected form. So it directly redirects into a user interface page of that acquirer then the users can confirm the transactions. In some other acquirers like Adyen, authorize.net, and stripes, this payment gateway follows inline form methods, So in that acquirer, we can see some js function for rendering the form.
We can specify the type like this in our data file:
Inline form:
<field name="inline_form_view_id" ref="inline_form"/>
Redirect form:
<field name="redirect_form_view_id" ref="redirect_form"/>
We already mentioned some default functions that are used in both inline and redirect form methods.
Now we can see some js functions that are used in the inline form method.
You can see in the payment module in Odoo addons some default javascript widgets, like checkout_form, manage_form, payment_mixins, and post_processing. The checkout_form and manage_form are extended by payment_mixins. There are some events like,
events: Object.assign({}, publicWidget.Widget.prototype.events, {
       'click div[name="o_payment_option_card"]': '_onClickPaymentOption',
       'click a[name="o_payment_icon_more"]': '_onClickMorePaymentIcons',
       'click a[name="o_payment_icon_less"]': '_onClickLessPaymentIcons',
       'click button[name="o_payment_submit_button"]': '_onClickPay',
       'click button[name="o_payment_submit_button"]': '_onClickSaveToken',
       'click button[name="o_payment_delete_token"]': '_onClickDeleteToken',
       'submit': '_onSubmit',
   }),
We can use these default events and it is also possible to extend this.
_oNClickPaymentOption function is used when clicking on the card of a payment option. It marks the radio button in the payment option as checked then it opens an inline form if the acquirer has any inline form. This is the click event of the payment option card.
_oNClickMorePaymentIcons this function is used when clicking the show more buttons. It is used to display all payment icons that are linked with that payment acquirer.
_oNClickLessPaymentIcons this function is used when clicking the show more buttons. It is used to hide all payment icons that are linked with that payment acquirer.
_oNClickSaveToken function is called when clicking the 'Save Payment Method' button of when submitting the form. It is used to create a new token.
_oNClickdeleteToken function is used when clicking on the 'Delete' button of a token. It is used to delete the token.
In the Adyen acquirer, it extended the payment form and checkout form.
const core = require('web.core');
const checkoutForm = require('payment.checkout_form');
const manageForm = require('payment.manage_form');
const _t = core._t;
Defined a function called _prepareInlineForm. Override these functions from payment mixins. It is used to prepare the inline form. Under this method, it's called _dropinOnAdditionalDetails, _dropinOnError and _dropinOnSubmit. It is used to handle the additional event, error event, and submit an event.
Also, it overrides _the process payment method from payment mixins.
async _processPayment(provider, paymentOptionId, flow) {
   if (provider !== 'adyen' || flow === 'token') {
       return this._super(...arguments); // Tokens are handled by the generic flow
   }
   if (this.adyenDropin === undefined) { // The drop-in has not been properly instantiated
       this._displayError(
           _t("Server Error"), _t("We are not able to process your payment.")
       );
   } else {
       return await this.adyenDropin.submit();
   }
}
This function Trigger the payment processing by submitting the drop-in
For some specific payment acquirers we need to prepare their inline form, for example in Authorize.Net payment acquirer we need to do this. For this, we can override the _prepareInlineForm method.
This is a common method for doing payment integration in Odoo. Payment gateways are different, Based on the Payment Gateway there is some difference in these methods. We can use those methods to do appropriate functionality.


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



0
Comments



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