diff --git a/lms/lms/doctype/lms_settings/lms_settings.js b/lms/lms/doctype/lms_settings/lms_settings.js
index 6cb5f425..c0c9ac82 100644
--- a/lms/lms/doctype/lms_settings/lms_settings.js
+++ b/lms/lms/doctype/lms_settings/lms_settings.js
@@ -2,6 +2,28 @@
// For license information, please see license.txt
frappe.ui.form.on("LMS Settings", {
- // refresh: function(frm) {
- // }
+ setup: function (frm) {
+ frappe.call({
+ method: "lms.lms.doctype.lms_settings.lms_settings.check_payments_app",
+ callback: (data) => {
+ if (!data.message) {
+ frm.set_df_property("payment_section", "hidden", 1);
+ frm.trigger("set_no_payments_app_html");
+ } else {
+ frm.set_df_property("no_payments_app", "hidden", 1);
+ }
+ },
+ });
+ },
+
+ set_no_payments_app_html(frm) {
+ frm.get_field("payments_app_is_not_installed").html(`
+
+ Please install the
+
+ Payments app
+
+ to enable payment gateway.
+ `);
+ },
});
diff --git a/lms/lms/doctype/lms_settings/lms_settings.json b/lms/lms/doctype/lms_settings/lms_settings.json
index adbc63ca..d8bae686 100644
--- a/lms/lms/doctype/lms_settings/lms_settings.json
+++ b/lms/lms/doctype/lms_settings/lms_settings.json
@@ -49,6 +49,8 @@
"apply_gst",
"show_usd_equivalent",
"apply_rounding",
+ "no_payments_app",
+ "payments_app_is_not_installed",
"email_templates_tab",
"certification_template",
"batch_confirmation_template",
@@ -323,15 +325,23 @@
},
{
"fieldname": "payment_gateway",
- "fieldtype": "Link",
- "label": "Payment Gateway",
- "options": "Payment Gateway"
+ "fieldtype": "Data",
+ "label": "Payment Gateway"
+ },
+ {
+ "fieldname": "no_payments_app",
+ "fieldtype": "Section Break"
+ },
+ {
+ "fieldname": "payments_app_is_not_installed",
+ "fieldtype": "HTML",
+ "label": "Payments app is not installed"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2024-09-30 18:30:28.689084",
+ "modified": "2024-10-01 12:15:49.800242",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Settings",
diff --git a/lms/lms/doctype/lms_settings/lms_settings.py b/lms/lms/doctype/lms_settings/lms_settings.py
index 4d90bc41..a58c117c 100644
--- a/lms/lms/doctype/lms_settings/lms_settings.py
+++ b/lms/lms/doctype/lms_settings/lms_settings.py
@@ -39,3 +39,33 @@ class LMSSettings(Document):
frappe.bold("Course Evaluator"),
)
)
+
+
+@frappe.whitelist()
+def check_payments_app():
+ installed_apps = frappe.get_installed_apps()
+ print("payments" not in installed_apps)
+ if "payments" not in installed_apps:
+ return False
+ else:
+ filters = {
+ "doctype_or_field": "DocField",
+ "doc_type": "LMS Settings",
+ "field_name": "payment_gateway",
+ }
+ if frappe.db.exists("Property Setter", filters):
+ return True
+
+ link_property = frappe.new_doc("Property Setter")
+ link_property.update(filters)
+ link_property.property = "fieldtype"
+ link_property.value = "Link"
+ link_property.save()
+
+ options_property = frappe.new_doc("Property Setter")
+ options_property.update(filters)
+ options_property.property = "options"
+ options_property.value = "Payment Gateway"
+ options_property.save()
+
+ return True
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index 0c9abbbd..bd70e2ce 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -908,39 +908,6 @@ def get_upcoming_evals(student, courses):
return upcoming_evals
-@frappe.whitelist()
-def get_payment_options(doctype, docname, phone, country):
- if not frappe.db.exists(doctype, docname):
- frappe.throw(_("Invalid document provided."))
-
- validate_phone_number(phone, True)
- details = get_details(doctype, docname)
-
- details.amount, details.currency = check_multicurrency(
- details.amount, details.currency, country, details.amount_usd
- )
- if details.currency == "INR":
- details.amount, details.gst_applied = apply_gst(details.amount, country)
-
- client = get_client()
- order = create_order(client, details.amount, details.currency)
-
- options = {
- "key_id": frappe.db.get_single_value("LMS Settings", "razorpay_key"),
- "name": frappe.db.get_single_value("Website Settings", "app_name"),
- "description": _("Payment for {0} course").format(details["title"]),
- "order_id": order["id"],
- "amount": cint(order["amount"]) * 100,
- "currency": order["currency"],
- "prefill": {
- "name": frappe.db.get_value("User", frappe.session.user, "full_name"),
- "email": frappe.session.user,
- "contact": phone,
- },
- }
- return options
-
-
def check_multicurrency(amount, currency, country=None, amount_usd=None):
settings = frappe.get_single("LMS Settings")
show_usd_equivalent = settings.show_usd_equivalent
@@ -998,78 +965,6 @@ def apply_gst(amount, country=None):
return amount, gst_applied
-def get_details(doctype, docname):
- if doctype == "LMS Course":
- details = frappe.db.get_value(
- "LMS Course",
- docname,
- ["name", "title", "paid_course", "currency", "course_price as amount", "amount_usd"],
- as_dict=True,
- )
- if not details.paid_course:
- frappe.throw(_("This course is free."))
- else:
- details = frappe.db.get_value(
- "LMS Batch",
- docname,
- ["name", "title", "paid_batch", "currency", "amount", "amount_usd"],
- as_dict=True,
- )
- if not details.paid_batch:
- frappe.throw(_("To join this batch, please contact the Administrator."))
-
- return details
-
-
-def get_client():
- settings = frappe.get_single("LMS Settings")
- razorpay_key = settings.razorpay_key
- razorpay_secret = settings.get_password("razorpay_secret", raise_exception=True)
-
- if not razorpay_key and not razorpay_secret:
- frappe.throw(
- _(
- "There is a problem with the payment gateway. Please contact the Administrator to proceed."
- )
- )
-
- return razorpay.Client(auth=(razorpay_key, razorpay_secret))
-
-
-def create_order(client, amount, currency):
- try:
- return client.order.create(
- {
- "amount": cint(amount) * 100,
- "currency": currency,
- }
- )
- except Exception as e:
- frappe.throw(
- _(
- "Error during payment: {0} Please contact the Administrator. Amount {1} Currency {2} Formatted {3}"
- ).format(e, amount, currency, cint(amount))
- )
-
-
-def get_payment_details(doctype, docname, address):
- amount_field = "course_price" if doctype == "LMS Course" else "amount"
- amount = frappe.db.get_value(doctype, docname, amount_field)
- currency = frappe.db.get_value(doctype, docname, "currency")
- amount_usd = frappe.db.get_value(doctype, docname, "amount_usd")
- amount_with_gst = 0
-
- amount, currency = check_multicurrency(amount, currency, None, amount_usd)
- if currency == "INR" and address.country == "India":
- amount_with_gst, gst_applied = apply_gst(amount, address.country)
-
- return {
- "amount": amount,
- "currency": currency,
- "amount_with_gst": amount_with_gst,
- }
-
-
def create_membership(course, payment):
membership = frappe.new_doc("LMS Enrollment")
membership.update(