diff --git a/bank_integration/bank_integration/api/bank_api.py b/bank_integration/bank_integration/api/bank_api.py index 1b1266a..0fe5116 100644 --- a/bank_integration/bank_integration/api/bank_api.py +++ b/bank_integration/bank_integration/api/bank_api.py @@ -53,14 +53,13 @@ def logout(self): pass def setup_browser(self): - self.br = webdriver.Chrome(options=self.get_options(), port=12345) + self.br = webdriver.Chrome(options=self.get_options()) def get_options(self): options = Options() options.add_argument("window-size=990,1200") if not frappe.conf.developer_mode: options.add_argument("--headless") - options.add_experimental_option("w3c", False) return options diff --git a/bank_integration/bank_integration/api/hdfc_bank_api.py b/bank_integration/bank_integration/api/hdfc_bank_api.py index 2fd43f4..6043731 100644 --- a/bank_integration/bank_integration/api/hdfc_bank_api.py +++ b/bank_integration/bank_integration/api/hdfc_bank_api.py @@ -13,7 +13,6 @@ from bank_integration.bank_integration.api.bank_api import BankAPI, AnyEC # Selenium imports -from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import ( @@ -37,8 +36,6 @@ def login(self): cust_id = self.get_element("fldLoginUserId") cust_id.send_keys(self.username, Keys.ENTER) - pass_input = self.get_element("fldPassword") - try: secure_access_cb = self.get_element( "chkrsastu", "id", timeout=2, throw=False @@ -56,14 +53,15 @@ def login(self): "HDFC Netbanking is asking for a CAPTCHA, which we don't currently support. Exiting." ) - pass_input.send_keys(self.password, Keys.ENTER) + self.get_element("fldPassword").send_keys(self.password, Keys.ENTER) self.wait_until( AnyEC( EC.visibility_of_element_located( ( By.XPATH, - "//td/span[text()[contains(.,'The Customer ID/IPIN (Password) is invalid.')]]", + # Message has changed on incorrect password + "//td/span[text()[contains(.,'Your ID and IPIN do not match. Please try again')]]", ) ), EC.visibility_of_element_located((By.NAME, "fldOldPass")), @@ -74,6 +72,7 @@ def login(self): throw="ignore", ) + # Todo: don't think _found_element as an attribute works anymore in 4+ selenium if not self.br._found_element: self.handle_login_error() @@ -94,8 +93,9 @@ def login(self): self.process_otp() elif "fldAnswer" == self.br._found_element[-1]: self.process_security_questions() + else: - self.login_success() + self.logged_in = True def process_otp(self): mobile_no = email_id = None @@ -219,8 +219,6 @@ def handle_login_error(self): self.throw(alert) def login_success(self): - self.logged_in = 1 - if self.doctype == "Bank Integration Settings": self.show_msg("Credentials verified successfully!") self.emit_js("setTimeout(() => {frappe.hide_msgprint()}, 2000);") diff --git a/bank_integration/bank_integration/api/payments.py b/bank_integration/bank_integration/api/payments.py index 3214b0f..0259c83 100644 --- a/bank_integration/bank_integration/api/payments.py +++ b/bank_integration/bank_integration/api/payments.py @@ -8,13 +8,27 @@ import frappe from bank_integration.bank_integration.api import get_bank_api + @frappe.whitelist() def make_payment(docname, uid, data): + doctype = "Payment Entry" data = frappe._dict(json.loads(data)) - bi_name = frappe.db.get_value('Bank Account', {'account': data.from_account}, 'name') - bi = frappe.get_doc('Bank Integration Settings', bi_name) + bi_name = frappe.db.get_value( + "Bank Account", {"account": data.from_account}, "name" + ) + bi = frappe.get_doc("Bank Integration Settings", bi_name) data.from_account = bi.bank_account_no - bank = get_bank_api(bi.bank_name, bi.username, bi.get_password(), doctype="Payment Entry", docname=docname, - uid=uid, data=data) + bank = get_bank_api( + bi.bank_name, + bi.username, + bi.get_password(), + doctype=doctype, + docname=docname, + uid=uid, + data=data, + ) + + if bank.logged_in: + bank.login_success() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8b125f7..a7a4826 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ frappe -selenium==3.141.0 +selenium==4.7.2 pandas==1.5.0 \ No newline at end of file