From 2ba85ba6a70c64b007ff75e9ea782b091c1b0dd5 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 14 Aug 2023 19:30:33 +0530 Subject: [PATCH] feat: paid course from course creation form --- lms/lms/doctype/lms_course/lms_course.py | 9 +++++- lms/lms/utils.py | 2 +- lms/public/css/style.css | 2 +- lms/templates/reviews_cta.html | 2 +- lms/www/billing/__init__.py | 0 lms/www/billing/billing.html | 29 +++++++------------ lms/www/billing/billing.js | 8 ++++- lms/www/courses/course.html | 16 ++++++---- lms/www/courses/course.py | 1 + lms/www/courses/create.html | 37 ++++++++++++++++++++++++ lms/www/courses/create.js | 17 +++++++++++ lms/www/courses/create.py | 5 ++-- 12 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 lms/www/billing/__init__.py diff --git a/lms/lms/doctype/lms_course/lms_course.py b/lms/lms/doctype/lms_course/lms_course.py index 7cc082a4..2d56bd63 100644 --- a/lms/lms/doctype/lms_course/lms_course.py +++ b/lms/lms/doctype/lms_course/lms_course.py @@ -5,7 +5,7 @@ import json import random import frappe from frappe.model.document import Document -from frappe.utils import cint +from frappe.utils import cint, validate_phone_number from frappe.utils.telemetry import capture from lms.lms.utils import get_chapters, can_create_courses from ...utils import generate_slug, validate_image @@ -213,6 +213,9 @@ def save_course( published, upcoming, image=None, + paid_course=False, + course_price=None, + currency=None, ): if not can_create_courses(): return @@ -232,6 +235,9 @@ def save_course( "tags": tags, "published": cint(published), "upcoming": cint(upcoming), + "paid_course": cint(paid_course), + "course_price": course_price, + "currency": currency, } ) doc.save(ignore_permissions=True) @@ -360,6 +366,7 @@ def reorder_chapter(chapter_array): @frappe.whitelist() def get_payment_options(course, phone): + validate_phone_number(phone, True) course_details = frappe.db.get_value( "LMS Course", course, ["name", "title", "currency", "course_price"], as_dict=True ) diff --git a/lms/lms/utils.py b/lms/lms/utils.py index d472e6cf..0758d0c5 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -475,7 +475,7 @@ def get_evaluation_details(course, member=None): def format_amount(amount, currency): amount_reduced = amount / 1000 if amount_reduced < 1: - return amount + return fmt_money(amount, 0, currency) precision = 0 if amount % 1000 == 0 else 1 return _("{0}k").format(fmt_money(amount_reduced, precision, currency)) diff --git a/lms/public/css/style.css b/lms/public/css/style.css index c3768a6c..823b9e52 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -421,7 +421,7 @@ input[type=checkbox] { } .course-price { - font-weight: 700; + font-weight: 500; } .view-course-link { diff --git a/lms/templates/reviews_cta.html b/lms/templates/reviews_cta.html index 73bd63a7..dfb06f44 100644 --- a/lms/templates/reviews_cta.html +++ b/lms/templates/reviews_cta.html @@ -2,7 +2,7 @@ {{ _("Write a review") }} -{% elif not is_instructor(course.name) and frappe.session.user == "Guest" %} +{% elif not is_instructor and frappe.session.user == "Guest" %} {{ _("Write a review") }} diff --git a/lms/www/billing/__init__.py b/lms/www/billing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lms/www/billing/billing.html b/lms/www/billing/billing.html index 373461d9..31e84e04 100644 --- a/lms/www/billing/billing.html +++ b/lms/www/billing/billing.html @@ -15,7 +15,7 @@ {% endblock %} {% macro Header() %} -
+
{{ _("Order Details") }}
@@ -26,25 +26,18 @@ {% endmacro %} {% macro CourseDetails() %} -
-
-
- {{ _("Course:") }} +
+
+
+
+ {{ _("Course Name: ") }} {{ course.title }} +
-
- {{ course.title }} -
-
-
- -
-
- {{ _("Total Price:") }} -
-
- - {{ frappe.utils.fmt_money(course.course_price, 2, course.currency) }} +
+
+ {{ _("Total Price: ") }} {{ frappe.utils.fmt_money(course.course_price, 2, course.currency) }} +
diff --git a/lms/www/billing/billing.js b/lms/www/billing/billing.js index 51f57cef..4767fe03 100644 --- a/lms/www/billing/billing.js +++ b/lms/www/billing/billing.js @@ -99,7 +99,13 @@ const handle_success = (response, course, address, order_id) => { order_id: order_id, }, callback: (data) => { - window.location.href = data.message; + frappe.show_alert({ + message: __("Payment Successful"), + indicator: "green", + }); + setTimeout(() => { + window.location.href = data.message; + }, 2000); }, }); }; diff --git a/lms/www/courses/course.html b/lms/www/courses/course.html index 450cf640..3f3bedbe 100644 --- a/lms/www/courses/course.html +++ b/lms/www/courses/course.html @@ -122,6 +122,10 @@ {{ Notes(course) }} +
+ {{ format_amount(course.course_price, course.currency) }} +
+
@@ -194,18 +198,18 @@ membership.current_lesson else "1.1" if first_lesson_exists(course.name) else None %}
- {% if is_instructor(course.name) and not course.published and course.status != "Under Review" %} + {% if is_instructor and not course.published and course.status != "Under Review" %}
{{ _("Submit for Review") }}
- {% elif is_instructor(course.name) and lesson_index %} + {% elif is_instructor and lesson_index %} {{ _("Checkout Course") }} - {% elif course.upcoming and not is_user_interested and not is_instructor(course.name) %} + {% elif course.upcoming and not is_user_interested and not is_instructor %}
{{ _("Notify me when available") }}
@@ -221,7 +225,7 @@ {{ _("Continue Learning") }} - {% elif course.paid_course %} + {% elif course.paid_course and not is_instructor %} {{ _("Buy This Course") }} @@ -247,7 +251,7 @@ {% endif %} {% endif %} - {% if is_instructor(course.name) or has_course_moderator_role() %} + {% if is_instructor or has_course_moderator_role() %}