Merge pull request #22198 from scmmishra/membership-fixes

fix: verification for razorpay hooks
This commit is contained in:
Deepesh Garg 2020-06-12 21:28:07 +05:30 committed by GitHub
commit 28fecb1b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -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,11 @@ def create_customer(user_details):
"link_name": customer.name
})
contact.insert()
contact.save()
except frappe.DuplicateEntryError:
return customer.name
except Exception as e:
frappe.log_error(frappe.get_traceback(), _("Contact Creation Failed"))
pass

View File

@ -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')
@ -77,7 +80,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):
@ -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