Through Odoo apps, In-App Purchases (IAP) enable service providers to offer continuing services. Users can purchase service tokens via Odoo. When a service request is made, service providers take tokens from the user’s Odoo account.
OVERVIEW
*Service Providers ( You )
*Odoo
*Client
Service providers will give the client value in the form of a service paid for per-use. The client sets up your Odoo app, and it is where they will make service requests. When a client adds credit to their account through Odoo’s brokering system, you may then use those credits to perform services.
External Service
The External Service is an optional player; you can either supply a service directly or delegate the real service, functioning as a bridge or translator between an Odoo system and the actual service.
Service Flow
*The customer makes a service request.
*The Service Provider generates a transaction over that amount after checking with Odoo to see if the Client’s account has enough credits for the requested service.
*The service provider provides the service. (either directly or via calling external services).
*The Service Provider returns to Odoo to capture or cancel the transaction made.
*The service provider informs the client that the service has been completed, either displaying or saving the results in the client’s system.
Lack of Credit
*The same client demands the same service.
*Odoo responds negatively when the Service Provider inquires about whether the Client’s account has adequate credits.
*A reminder of this is sent to the client.
*Whose Odoo account is forwarded in order to credit it and attempt again?
IAP Services in Odoo
*You must first register your service on the IAP endpoint.
*Go to your Portal Account on the IAP endpoint (https://iap.odoo.com) for production, (https://iap-sandbox.odoo.com) for testing.
*Alternatively, you can choose In-App Services by going to your portal in Odoo (https://iap.odoo.com/my/home).
*For log in, go to My Account -> In-App Services
*Create your service by providing fields of service.
Fields used in Service
*name: When requesting a transaction from Odoo inside the client’s app, you must supply the string name – Service Name. self.env[‘iap.account].get(name)
*label
*icon
*Key (ServiceKey) this is a secret key. It will be shown on the creation of service. This is a key that identifies the service.
*Trial credits – This is a placeholder for the trial credits that will be given to app users following their first use. Keep in mind that only clients with active enterprise contracts will have access to this service.
*privacy policy – This should clearly state what data you gather, how you use it, why it’s important to the operation of your business, and how the client can view, correct, or delete their personal information.
Packs
Essentially, a credit pack is a product containing the following five features:
*Name: the pack’s name,
*Icon: a unique icon for the pack (if none is provided, the service icon will be used instead), Details about the pack that will be shown on the shop website and on the invoice.
*Amount: The number of credits to which the customer is entitled upon purchasing the pack
*pricing: pricing in EUR (but USD support is being planned).
*On every sale of a pack, Odoo keeps 25% of the proceeds. Price your product appropriately.
*The cost per credit may change from one pack to another, depending on the approach.
Develop an Odoo app using IAP Services
Using IAP, we will build an Odoo module. IAP is a typical module, and the dependency guarantees that a local account is properly configured.
We will only be adding an action button to the partner’s page, but you may still add a lot of value locally by developing an application and remotely by offering further services.
For eg :
<odoo>
<record id=”res_partner_view_form” model=”ir.ui.view”>
<field name=”name”>res.partner.view.form.inherit.modulename
</field>
<field name=”model”>res.partner</field>
<field name=”inherit_id” ref=”base.view_partner_form”/>
<field name=”arch” type=”xml”>
<div name=”button_box” position=”inside”>
<button class=”oe_stat_button” type=”object” name=”get_partner” icon=”fa-gears”>
</button>
</div>
</field>
</record>
</odoo>
manifest.py :
‘name’: “Module Name”,
‘category’:’Tools’,
‘depends’:[‘iap’],
‘data’:[
‘views/res_partner_view.xml’
],
*To call a JSON-RPC2 endpoint on another Odoo instance and transparently re-raise the appropriate Odoo exceptions (InsufficientCreditError, odoo.exceptions.AccessError, and odoo.exceptions.UserError), iap offers the iap_jsonrpc() utility.
Needs for a call
Client parameter
the account_token field of the iap.account model, which contains the token of the current client. By executing env[‘iap.account’], you can get the account for your service.get(service_name), where service_name is the service’s name as registered on the IAP endpoint.
For eg :
From odoo import api, models
From odoo.addons.iap import jsonrpc, InsufficientCreditError
DEFAULT_ENDPOINT = “http://localhost:8030”
Class ResPartner(models.Model):
_inherit = “res.partner”
def get_partner(self):
user_token = self.env[‘iap.account’].get(“service”)
params = {
‘account_token”: user_token.account_token
}
endpoint = self.env[‘ir.config_parameter’].sudo().get_param(“service.endpoint”, DEFAULT_ENDPOINT)
jsonrpc(endpoint + ‘/roll’, params=params)
return True
Odoo Helpers
*Charging
For use in the backend or proxy, a context manager for authorizing, automatically capturing, or canceling transactions.
similar to a cursor context manager, for example:
approves a transaction with the supplied parameters right away;
carries out the with body;
If the body executes flawlessly, it records the transaction.
If not, cancel it.
For retrieving the iap.endpoint configuration key, utilize the env (odoo.api.Environment) parameters.
(ServiceKey) key
(UserToken) token
float credit –
(Str) description
(Qweb template) credit_template
TTL (Integer)
*Cancel
For retrieving the iap.endpoint configuration key, utilize the env (odoo.api.Environment) parameters.
token_transaction (str) –
(ServiceKey) key
*Capture
For retrieving the iap.endpoint configuration key, utilize the env (odoo.api.Environment) parameters.
token_transaction (str) –
(ServiceKey) key
the credit
Test the API
We suggest a sandbox platform for testing the produced app, which enables you to:
Test the entire process from the client’s perspective using real services and consultable transactions. (Again, changing the endpoint is necessary; see the warning remark in Service).
Examine the API.
The latter comprises unique tokens that are only compatible with IAP-Sandbox.
A nonexistent account is represented by the token 000000. Upon an authorization attempt, returns an InsufficientCreditError.
The account with insufficient credits to execute any services is represented by token 000111. Upon an authorization attempt, returns an InsufficientCreditError.
The account with sufficient credits to perform any service is represented by the token 111111. An attempt to authorize will produce a fake transaction token, which the capture and cancel routes will handle.
Types
*class ServiceName String identifying your service on https://iap.odoo.com (production) as well as the account connected to it in the client’s database.
*class ServiceKey Identifier developed for the supplier’s service. Each key (and service) is associated with a token that the service provider created and assigned a fixed value to.
*class UserToken User account identifier.
*class TransactionToken Transaction identifier that is used to capture or cancel transactions and is returned by the authorization process.
*exception odoo.addons.iap.tools.iap_tools.InsufficientCreditError
If the desired credits are not currently available on the account (either because there are not enough credits or because there are too many outstanding transactions or holds), a transaction authorization error may be raised.
*odoo. exceptions.AccessError exception
any action that calls for a service token that fails if the service token is invalid; any inter-server call failure (usually in iap_jsonrpc()).
*odoo. exceptions is an exception.UserError
raised by any unusual behavior, at the app developer’s (you) choice.