feat: log everything

This commit is contained in:
Shivam Mishra 2020-06-24 15:41:19 +05:30
parent bcb49e59e7
commit 4e40b9bdbe

View File

@ -81,17 +81,24 @@ def verify_signature(data):
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def trigger_razorpay_subscription(*args, **kwargs): def trigger_razorpay_subscription(*args, **kwargs):
data = frappe.request.get_data(as_text=True) data = frappe.request.get_data(as_text=True)
try:
verify_signature(data) verify_signature(data)
except Exception as e:
frappe.log_error(e, "Webhook Verification Error")
if isinstance(data, six.string_types): if isinstance(data, six.string_types):
data = json.loads(data) data = json.loads(data)
data = frappe._dict(data) data = frappe._dict(data)
try:
subscription = data.payload.get("subscription", {}).get('entity', {}) subscription = data.payload.get("subscription", {}).get('entity', {})
subscription = frappe._dict(subscription) subscription = frappe._dict(subscription)
payment = data.payload.get("payment", {}).get('entity', {}) payment = data.payload.get("payment", {}).get('entity', {})
payment = frappe._dict(payment) payment = frappe._dict(payment)
except Exception as e:
frappe.log_error(e, "Webhook Data Parsing Error")
return False
try: try:
data_json = json.dumps(data, indent=4, sort_keys=True) data_json = json.dumps(data, indent=4, sort_keys=True)
@ -103,7 +110,7 @@ def trigger_razorpay_subscription(*args, **kwargs):
if not member: if not member:
return False return False
try:
if data.event == "subscription.activated": if data.event == "subscription.activated":
member.customer_id = payment.customer_id member.customer_id = payment.customer_id
elif data.event == "subscription.charged": elif data.event == "subscription.charged":
@ -127,6 +134,8 @@ def trigger_razorpay_subscription(*args, **kwargs):
member.subscription_end = datetime.fromtimestamp(subscription.end_at) member.subscription_end = datetime.fromtimestamp(subscription.end_at)
member.subscription_activated = 1 member.subscription_activated = 1
member.save(ignore_permissions=True) member.save(ignore_permissions=True)
except Exception as e:
frappe.log_error(e, "Error creating membership entry")
return True return True