From 8d61a0abefc5604ae0424dd03cfc1c62f1b8abf3 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 11 Jun 2020 13:34:25 +0530 Subject: [PATCH 1/4] fix: use string to verify webhook --- erpnext/non_profit/doctype/membership/membership.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index 4b932425b2..c4f43185f7 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -77,7 +77,7 @@ def verify_signature(data): @frappe.whitelist(allow_guest=True) def trigger_razorpay_subscription(*args, **kwargs): - data = frappe.request.get_data() + data = frappe.request.get_data(as_text=True) verify_signature(data) if isinstance(data, six.string_types): From 84fcc55a36fef6caa1ca45056bdf7d0d8711a0de Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 11 Jun 2020 13:34:40 +0530 Subject: [PATCH 2/4] refactor: do nothing if member is not found --- erpnext/non_profit/doctype/membership/membership.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py index c4f43185f7..7a0caed621 100644 --- a/erpnext/non_profit/doctype/membership/membership.py +++ b/erpnext/non_profit/doctype/membership/membership.py @@ -62,7 +62,10 @@ def get_member_based_on_subscription(subscription_id, email): 'subscription_id': subscription_id, 'email_id': email }, order_by="creation desc") - return frappe.get_doc("Member", members[0]['name']) + try: + return frappe.get_doc("Member", members[0]['name']) + except: + return None def verify_signature(data): signature = frappe.request.headers.get('X-Razorpay-Signature') @@ -96,7 +99,10 @@ def trigger_razorpay_subscription(*args, **kwargs): except Exception as e: error_log = frappe.log_error(frappe.get_traceback() + '\n' + data_json , _("Membership Webhook Failed")) notify_failure(error_log) - raise e + return False + + if not member: + return False if data.event == "subscription.activated": member.customer_id = payment.customer_id From 49d51b8ce72f7bcdb8931a3c23fde76e43c7a7b9 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 11 Jun 2020 14:24:07 +0530 Subject: [PATCH 3/4] feat: check duplicate contact explicitly --- erpnext/non_profit/doctype/member/member.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/non_profit/doctype/member/member.py b/erpnext/non_profit/doctype/member/member.py index 571f87af87..aaa56ba118 100644 --- a/erpnext/non_profit/doctype/member/member.py +++ b/erpnext/non_profit/doctype/member/member.py @@ -92,6 +92,10 @@ def create_customer(user_details): }) contact.insert() + + except frappe.DuplicateEntryError: + return customer.name + except Exception as e: frappe.log_error(frappe.get_traceback(), _("Contact Creation Failed")) pass From 8c24810f309f525d5ae334862af87b15cccb3073 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 11 Jun 2020 14:37:50 +0530 Subject: [PATCH 4/4] refactor: ignore mandatory for customer --- erpnext/non_profit/doctype/member/member.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/non_profit/doctype/member/member.py b/erpnext/non_profit/doctype/member/member.py index aaa56ba118..d1294ccc08 100644 --- a/erpnext/non_profit/doctype/member/member.py +++ b/erpnext/non_profit/doctype/member/member.py @@ -77,6 +77,7 @@ def create_customer(user_details): customer = frappe.new_doc("Customer") customer.customer_name = user_details.fullname customer.customer_type = "Individual" + customer.flags.ignore_mandatory = True customer.insert(ignore_permissions=True) try: @@ -91,7 +92,7 @@ def create_customer(user_details): "link_name": customer.name }) - contact.insert() + contact.save() except frappe.DuplicateEntryError: return customer.name