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});
});
if (!frm.doc.customer) {
frm.add_custom_button(__('Create Customer'), () => {
frm.call('make_customer_and_link').then(() => {
frm.reload_doc();
});
});
}
// indicator
erpnext.utils.set_party_dashboard_indicators(frm);

View File

@ -53,6 +53,19 @@ class Member(Document):
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):
member_list = frappe.get_all("Member", filters={'email': user_details.email, 'membership_type': user_details.plan_id})
if member_list and member_list[0]:
@ -83,8 +96,10 @@ def create_customer(user_details):
try:
contact = frappe.new_doc("Contact")
contact.first_name = user_details.fullname
contact.add_phone(user_details.mobile, is_primary_phone=1, is_primary_mobile_no=1)
contact.add_email(user_details.email, is_primary=1)
if user_details.mobile:
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.insert(ignore_permissions=True)
contact.append("links", {
@ -121,7 +136,7 @@ def create_member_subscription_order(user_details):
'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)
member = get_or_create_member(user_details)
if not member:

View File

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

View File

@ -81,7 +81,12 @@ def verify_signature(data):
@frappe.whitelist(allow_guest=True)
def trigger_razorpay_subscription(*args, **kwargs):
data = frappe.request.get_data(as_text=True)
verify_signature(data)
try:
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):
data = json.loads(data)
@ -99,36 +104,40 @@ 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)
return False
return { status: 'Failed' }
if not member:
return False
return { status: 'Failed' }
try:
if data.event == "subscription.activated":
member.customer_id = payment.customer_id
elif data.event == "subscription.charged":
membership = frappe.new_doc("Membership")
membership.update({
"member": member.name,
"membership_status": "Current",
"membership_type": member.membership_type,
"currency": "INR",
"paid": 1,
"payment_id": payment.id,
"webhook_payload": data_json,
"from_date": datetime.fromtimestamp(subscription.current_start),
"to_date": datetime.fromtimestamp(subscription.current_end),
"amount": payment.amount / 100 # Convert to rupees from paise
})
membership.insert(ignore_permissions=True)
if data.event == "subscription.activated":
member.customer_id = payment.customer_id
elif data.event == "subscription.charged":
membership = frappe.new_doc("Membership")
membership.update({
"member": member.name,
"membership_status": "Current",
"membership_type": member.membership_type,
"currency": "INR",
"paid": 1,
"payment_id": payment.id,
"webhook_payload": data_json,
"from_date": datetime.fromtimestamp(subscription.current_start),
"to_date": datetime.fromtimestamp(subscription.current_end),
"amount": payment.amount / 100 # Convert to rupees from paise
})
membership.insert(ignore_permissions=True)
# Update these values anyway
member.subscription_start = datetime.fromtimestamp(subscription.start_at)
member.subscription_end = datetime.fromtimestamp(subscription.end_at)
member.subscription_activated = 1
member.save(ignore_permissions=True)
except Exception as e:
log = frappe.log_error(e, "Error creating membership entry")
notify_failure(log)
return { status: 'Failed' }
# Update these values anyway
member.subscription_start = datetime.fromtimestamp(subscription.start_at)
member.subscription_end = datetime.fromtimestamp(subscription.end_at)
member.subscription_activated = 1
member.save(ignore_permissions=True)
return True
return { status: 'Success' }
def notify_failure(log):