Merge pull request #22819 from scmmishra/iff

This commit is contained in:
Shivam Mishra 2020-07-27 17:26:02 +05:30 committed by GitHub
commit 3c136ebf92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 31 deletions

View File

@ -29,6 +29,14 @@ frappe.ui.form.on('Member', {
frappe.set_route('query-report', 'Accounts Receivable', {member:frm.doc.name}); frappe.set_route('query-report', 'Accounts Receivable', {member:frm.doc.name});
}); });
if (!frm.doc.customer) {
frm.add_custom_button(__('Create Customer'), () => {
frm.call('make_customer_and_link').then(() => {
frm.reload_doc();
});
});
}
// indicator // indicator
erpnext.utils.set_party_dashboard_indicators(frm); erpnext.utils.set_party_dashboard_indicators(frm);

View File

@ -53,6 +53,19 @@ class Member(Document):
return subscription return subscription
def make_customer_and_link(self):
if self.customer:
frappe.msgprint(_("A customer is already linked to this Member"))
cust = create_customer(frappe._dict({
'fullname': self.member_name,
'email': self.email_id or self.user,
'phone': None
}))
self.customer = cust
self.save()
def get_or_create_member(user_details): def get_or_create_member(user_details):
member_list = frappe.get_all("Member", filters={'email': user_details.email, 'membership_type': user_details.plan_id}) member_list = frappe.get_all("Member", filters={'email': user_details.email, 'membership_type': user_details.plan_id})
if member_list and member_list[0]: if member_list and member_list[0]:
@ -83,7 +96,9 @@ def create_customer(user_details):
try: try:
contact = frappe.new_doc("Contact") contact = frappe.new_doc("Contact")
contact.first_name = user_details.fullname contact.first_name = user_details.fullname
if user_details.mobile:
contact.add_phone(user_details.mobile, is_primary_phone=1, is_primary_mobile_no=1) contact.add_phone(user_details.mobile, is_primary_phone=1, is_primary_mobile_no=1)
if user_details.email:
contact.add_email(user_details.email, is_primary=1) contact.add_email(user_details.email, is_primary=1)
contact.insert(ignore_permissions=True) contact.insert(ignore_permissions=True)
@ -121,7 +136,7 @@ def create_member_subscription_order(user_details):
'subscription_id': 'sub_EZycCvXFvqnC6p' 'subscription_id': 'sub_EZycCvXFvqnC6p'
} }
""" """
# {"plan_id":"IFF Starter","fullname":"Shivam Mishra","mobile":"7506056962","email":"shivam@shivam.dev","pan":"Testing123"}
user_details = frappe._dict(user_details) user_details = frappe._dict(user_details)
member = get_or_create_member(user_details) member = get_or_create_member(user_details)
if not member: if not member:

View File

@ -120,13 +120,15 @@
{ {
"fieldname": "webhook_payload", "fieldname": "webhook_payload",
"fieldtype": "Code", "fieldtype": "Code",
"hidden": 1,
"label": "Webhook Payload", "label": "Webhook Payload",
"options": "JSON", "options": "JSON",
"read_only": 1 "read_only": 1
} }
], ],
"index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2020-04-06 14:29:33.856060", "modified": "2020-07-27 14:28:11.532696",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Non Profit", "module": "Non Profit",
"name": "Membership", "name": "Membership",

View File

@ -81,7 +81,12 @@ 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:
signature = frappe.request.headers.get('X-Razorpay-Signature')
log = "{0} \n\n {1} \n\n {2} \n\n {3}".format(e, frappe.get_traceback(), signature, data)
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)
@ -99,11 +104,11 @@ def trigger_razorpay_subscription(*args, **kwargs):
except Exception as e: except Exception as e:
error_log = frappe.log_error(frappe.get_traceback() + '\n' + data_json , _("Membership Webhook Failed")) error_log = frappe.log_error(frappe.get_traceback() + '\n' + data_json , _("Membership Webhook Failed"))
notify_failure(error_log) notify_failure(error_log)
return False return { status: 'Failed' }
if not member: if not member:
return False return { status: 'Failed' }
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,8 +132,12 @@ 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:
log = frappe.log_error(e, "Error creating membership entry")
notify_failure(log)
return { status: 'Failed' }
return True return { status: 'Success' }
def notify_failure(log): def notify_failure(log):