Skip to content

Commit

Permalink
perf: cache razorpay client object in frappe.local
Browse files Browse the repository at this point in the history
  • Loading branch information
NagariaHussain committed Nov 12, 2023
1 parent 6fc9376 commit 04e21b3
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions printrov_merch_store/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,24 @@ def get_available_couriers(


def get_razorpay_client():
razorpay_settings = frappe.get_cached_doc(
"Printrove Razorpay Settings"
)
key_id = razorpay_settings.key_id
key_secret = razorpay_settings.get_password("key_secret")

return razorpay.Client(auth=(key_id, key_secret))
if not hasattr(frappe.local, "store_razorpay_client_object"):
razorpay_settings = frappe.get_cached_doc(
"Printrove Razorpay Settings"
)
key_id = razorpay_settings.key_id
key_secret = razorpay_settings.get_password("key_secret")

if not (key_id and key_secret):
frappe.throw(
"Setup razorpay via Printrove Razorpay Settings before using"
" printrov_merch_store.api.get_razorpay_client"
)

frappe.local.store_razorpay_client_object = razorpay.Client(
auth=(key_id, key_secret)
)

return frappe.local.store_razorpay_client_object


def get_categories_with_count():
Expand Down

0 comments on commit 04e21b3

Please sign in to comment.