Using v16 community. Trying to create a new payment provider (BTCpayserver) and am trying to figure out a few items. First I cannot link a payment journal to a New payment provider record or a BTCpayserver record. When I try to save the journal the form just goes back to a blank line. When I duplicate a current record (Stripe) I can save payment journal but not when the code is set to BTCpay, to test this I added the code field to another part of the form so I can change it. So currently try to understand and correct this behavior.
model.py:
import logging
import uuid
import requests
from werkzeug.urls import url_encode, url_join, url_parse
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
_logger = logging.getLogger(__name__)
class PaymentProvider(models.Model):
_inherit = 'payment.provider'
code = fields.Selection(
selection_add=[('btcpay', "BTCpay")], ondelete={'btcpay': 'set default'})
btcpay_server_url = fields.Char(string='Server URL')
btcpay_api_key = fields.Char(string='API Key')
btcpay_store_id = fields.Char(string='Store ID')
btcpay_expiration_minutes = fields.Integer('Expiration Minutes')
btcpay_monitoring_minutes = fields.Integer('Monitoring Minutes')
btcpay_speed_policy = fields.Selection(
[("HighSpeed", "HighSpeed"), ("MediumSpeed", "MediumSpeed"), ("LowMediumSpeed", "LowMediumSpeed"),
("LowSpeed", "LowSpeed")],
default="HighSpeed",
string="Speed Policy",
)
def test_btcpay_server_connection(self):
try:
server_url = self.btcpay_server_url + "/api/v1/api-keys/current"
headers = {"Authorization": "Token %s" % (self.btcpay_api_key)}
response = requests.request(method="GET", url=server_url, headers=headers)
is_success = True if response.status_code == 200 else False
return is_success
except Exception as e:
raise UserError(_("Test Connection Error: %s", e.args))
def action_test_connection(self):
is_success = self.test_btcpay_server_connection()
type = (
"success"
if is_success
else "danger"
)
messages = (
"Everything seems properly set up!"
if is_success
else "Server credential is wrong. Please check credential."
)
title = _("Connection Testing")
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": title,
"message": messages,
"sticky": False,
"type": type
},
}
view.xml:
provider.form.btcpay
payment.provider