Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Disallow cancelled 'Integration Requests' on checkout page #115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions payments/templates/pages/paytm_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
get_paytm_config,
get_paytm_params,
)
from payments.utils.utils import validate_integration_request


def get_context(context):
context.no_cache = 1
paytm_config = get_paytm_config()

try:
validate_integration_request(frappe.form_dict["order_id"])

doc = frappe.get_doc("Integration Request", frappe.form_dict["order_id"])

context.payment_details = get_paytm_params(json.loads(doc.data), doc.name, paytm_config)
Expand Down
5 changes: 5 additions & 0 deletions payments/templates/pages/razorpay_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from frappe import _
from frappe.utils import cint, flt

from payments.utils.utils import validate_integration_request

no_cache = 1

expected_keys = (
Expand All @@ -26,7 +28,10 @@ def get_context(context):
context.api_key = get_api_key()

try:
validate_integration_request(frappe.form_dict["token"])

doc = frappe.get_doc("Integration Request", frappe.form_dict["token"])

payment_details = json.loads(doc.data)

for key in expected_keys:
Expand Down
5 changes: 5 additions & 0 deletions payments/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields


def validate_integration_request(docname: str | None):
if frappe.db.get_value("Integration Request", docname, "status") == "Cancelled":
frappe.throw(_("Expired Token"))


def get_payment_gateway_controller(payment_gateway):
"""Return payment gateway controller"""
gateway = frappe.get_doc("Payment Gateway", payment_gateway)
Expand Down
Loading