refactor: make payments app a soft dependency (#33245)

refactor: make payment app a soft dependency
diff --git a/erpnext/utilities/__init__.py b/erpnext/utilities/__init__.py
index c2b4229..24bfdc6 100644
--- a/erpnext/utilities/__init__.py
+++ b/erpnext/utilities/__init__.py
@@ -1,6 +1,9 @@
 ## temp utility
 
+from contextlib import contextmanager
+
 import frappe
+from frappe import _
 from frappe.utils import cstr
 
 from erpnext.utilities.activation import get_level
@@ -35,3 +38,16 @@
 		domain = frappe.get_cached_value("Company", cstr(company), "domain")
 
 	return {"company": company, "domain": domain, "activation": get_level()}
+
+
+@contextmanager
+def payment_app_import_guard():
+	marketplace_link = '<a href="https://frappecloud.com/marketplace/apps/payments">Marketplace</a>'
+	github_link = '<a href="https://github.com/frappe/payments/">GitHub</a>'
+	msg = _("payments app is not installed. Please install it from {} or {}").format(
+		marketplace_link, github_link
+	)
+	try:
+		yield
+	except ImportError:
+		frappe.throw(msg, title=_("Missing Payments App"))