feat: razorpay order creation and checkout redirection

This commit is contained in:
Jannat Patel
2023-08-04 19:37:08 +05:30
parent c284e95dc8
commit 9c021ef3b1
4 changed files with 61 additions and 35 deletions

View File

@@ -281,3 +281,8 @@
</p>
{% endif %}
{% endmacro %}
{%- block script %}
{{ super() }}
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
{% endblock %}

View File

@@ -22,16 +22,7 @@ frappe.ready(() => {
});
$("#buy-course").click((e) => {
e.preventDefault();
frappe.call({
method: "lms.lms.doctype.lms_course.lms_course.buy_course",
args: {
course: decodeURIComponent(
$(e.currentTarget).attr("data-course")
),
},
callback: (data) => {},
});
generate_checkout_link(e);
});
});
@@ -155,3 +146,24 @@ const submit_for_review = (e) => {
},
});
};
generate_checkout_link = (e) => {
e.preventDefault();
let course = decodeURIComponent($(e.currentTarget).attr("data-course"));
if (frappe.session.user == "Guest") {
window.location.href = `/login?redirect-to=/courses/${course}`;
return;
}
frappe.call({
method: "lms.lms.doctype.lms_course.lms_course.get_payment_options",
args: {
course: course,
},
callback: (data) => {
let rzp1 = new Razorpay(data.message);
rzp1.open();
},
});
};