Skip to content

Commit

Permalink
Merge pull request #115 from ruthra-kumar/throw_for_cancelled_and_fai…
Browse files Browse the repository at this point in the history
…led_irequests

refactor: Disallow cancelled 'Integration Requests' on checkout page
  • Loading branch information
ruthra-kumar authored Nov 7, 2024
2 parents d80039b + a827330 commit 9030aec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
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

0 comments on commit 9030aec

Please sign in to comment.