Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/version-14-hotfix' into versio…
Browse files Browse the repository at this point in the history
…n-14
  • Loading branch information
barredterra committed Feb 18, 2025
2 parents 40d788c + 396e06e commit 6ad0ae8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 80 deletions.
73 changes: 27 additions & 46 deletions banking/connectors/admin_request.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,49 @@
# Copyright (c) 2023, ALYF GmbH and contributors
# For license information, please see license.txt
import json
import requests


class AdminRequest:
def __init__(
self,
ip_address: str,
user_agent: str,
api_token: str,
url: str,
customer_id: str,
) -> None:
self.ip_address = ip_address
self.user_agent = user_agent
self.api_token = api_token
self.url = url
self.base_url = url
self.customer_id = customer_id

@property
def headers(self):
return {"Alyf-Banking-Authorization": f"Token {self.api_token}"}

@property
def data(self):
return {
"ip_address": self.ip_address,
"user_agent": self.user_agent,
"customer_id": self.customer_id,
}
def request(self, method: str, endpoint: str, data: dict | None = None):
return requests.request(
method=method,
url=f"{self.base_url}/api/method/{endpoint}",
headers={
"Alyf-Banking-Authorization": f"Token {self.api_token}",
"Alyf-Customer-Id": self.customer_id,
},
json=data,
)

def fetch_subscription(self):
method = "banking_admin.api.fetch_subscription_details"
return requests.post(
url=self.url + method, headers=self.headers, data=json.dumps(self.data)
)
return self.request("GET", "banking_admin.api.fetch_subscription_details")

def get_customer_portal(self):
method = "banking_admin.api.get_customer_portal"
return requests.get(url=self.url + method)
return self.request("GET", "banking_admin.api.get_customer_portal")

def get_fintech_license(self):
method = "banking_admin.ebics_api.get_fintech_license"
return requests.post(
url=self.url + method, headers=self.headers, json=self.data.copy()
)

def register_ebics_user(self, host_id: str, partner_id: str, user_id: str):
data = self.data
data.update({"host_id": host_id, "partner_id": partner_id, "user_id": user_id})
method = "banking_admin.ebics_api.register_ebics_user"
return requests.post(
url=self.url + method,
headers=self.headers,
json=data,
)

def remove_ebics_user(self, host_id: str, partner_id: str, user_id: str):
data = self.data
data.update({"host_id": host_id, "partner_id": partner_id, "user_id": user_id})
method = "banking_admin.ebics_api.remove_ebics_user"
return requests.post(
url=self.url + method,
headers=self.headers,
json=data,
return self.request("GET", "banking_admin.ebics_api.get_fintech_license")

def register_ebics_user(
self, host_id: str, partner_id: str, user_id: str, remove: bool = False
):
if remove:
endpoint = "banking_admin.ebics_api.remove_ebics_user"
else:
endpoint = "banking_admin.ebics_api.register_ebics_user"

return self.request(
"POST",
endpoint,
{"host_id": host_id, "partner_id": partner_id, "user_id": user_id},
)
4 changes: 3 additions & 1 deletion banking/ebics/doctype/ebics_user/ebics_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def remove_user(self):
"""Indempotent method to remove the user from the admin backend."""
host_id = frappe.db.get_value("Bank", self.bank, "ebics_host_id")
try:
r = Admin().request.remove_ebics_user(host_id, self.partner_id, self.user_id)
r = Admin().request.register_ebics_user(
host_id, self.partner_id, self.user_id, remove=True
)
r.raise_for_status()
except HTTPError:
title = _("Failed to remove EBICS user registration.")
Expand Down
8 changes: 1 addition & 7 deletions banking/klarna_kosma_integration/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from banking.connectors.admin_request import AdminRequest
from banking.klarna_kosma_integration.exception_handler import ExceptionHandler
from banking.klarna_kosma_integration.utils import get_current_ip


class Admin:
Expand All @@ -15,19 +14,14 @@ def __init__(self, settings=None) -> None:
:param settings: Banking Settings document. Enables you to pass the most recent settings that may not be in the database yet.
"""
self.ip_address = get_current_ip()
self.user_agent = frappe.get_request_header("User-Agent") if frappe.request else None

settings = settings or frappe.get_single("Banking Settings")
self.api_token = settings.get_password("api_token")
self.customer_id = settings.customer_id
self.url = settings.admin_endpoint + "/api/method/"
self.url = settings.admin_endpoint

@property
def request(self):
return AdminRequest(
ip_address=self.ip_address,
user_agent=self.user_agent,
api_token=self.api_token,
url=self.url,
customer_id=self.customer_id,
Expand Down
26 changes: 0 additions & 26 deletions banking/klarna_kosma_integration/utils.py

This file was deleted.

0 comments on commit 6ad0ae8

Please sign in to comment.