Skip to content

Commit

Permalink
all testing done at pe and bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sameer Chauhan committed Dec 27, 2022
1 parent 6eb945c commit 05fe118
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 60 deletions.
17 changes: 9 additions & 8 deletions razorpay_payment_links_integration/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,27 @@ def resend_notification(**kwargs):
paymentLinkId = kwargs['paymentLinkId']
RazorpayController().resend_notification(paymentLinkId)


@frappe.whitelist()
def create_payment_link(**Kwargs):
"""
create request on the basis of pe_doc
then create a new Razorpay Payment link record if payment link is created
"""
pe_doc=json.loads(Kwargs['doc'])
frappe.log_error('create payment link',pe_doc)

contact_doc = frappe.get_doc('Contact', pe_doc.get('contact_person'))

request = {}
request['amount'] = pe_doc.get('paid_amount')
request['amount'] = int(pe_doc.get('paid_amount')) * 100 # convert it to smallest value
request['currency'] = "INR"
request['description'] = "For SO" # to udpate

request['description'] = ""
for ref in pe_doc.get('references', []):
request['description'] = request['description'] + f"{ref.get('reference_doctype')}: {ref.get('reference_name')}, "

request['customer'] = {}
request['customer']['name'] = f"{contact_doc.get('first_name', '')} {contact_doc.get('middle_name', '')} {contact_doc.get('last_name')}"
request['customer']['name'] = f"{contact_doc.get('first_name') or ''} {contact_doc.get('middle_name') or ''} {contact_doc.get('last_name') or ''}"
request['customer']['email'] = contact_doc.get('email_id', '')
request['customer']['contact'] = contact_doc.get('mobile_no', '')

Expand All @@ -54,10 +57,8 @@ def create_payment_link(**Kwargs):
"whatsapp": True
}
request['reminder_enable'] = True
request['callback_url'] = "https://erp.brivan.in/"
request['callback_method'] = "get"

razorpayObj = RazorpayController.get_client()
razorpayObj = RazorpayController().get_client()
link_obj = razorpayObj.payment_link.create(request)

if(link_obj.get('error')):
Expand All @@ -70,13 +71,13 @@ def create_payment_link(**Kwargs):
doc.link = link_obj.get('short_url')
doc.amount = link_obj.get('amount')
doc.insert()
frappe.db.set_value('Payment Entry', pe_doc.get('name'), 'razorpay_payment_link', doc.name)
return doc


@frappe.whitelist(allow_guest=True)
def webhooks_handler():
data = json.loads(frappe.request.data)
frappe.log_error('Razorpay', data)
doc = False

try:
Expand Down
15 changes: 0 additions & 15 deletions razorpay_payment_links_integration/customizations/payment_entry.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Payment Entry",
"fetch_from": "razorpay_payment_link.status",
"fetch_from": "razorpay_payment_links.status",
"fetch_if_empty": 1,
"fieldname": "razorpay_payment_status",
"fieldtype": "Data",
Expand Down
16 changes: 16 additions & 0 deletions razorpay_payment_links_integration/fixtures/property_setter.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,21 @@
"property_type": "Check",
"row_name": null,
"value": "1"
},
{
"default_value": null,
"doc_type": "Payment Entry",
"docstatus": 0,
"doctype": "Property Setter",
"doctype_or_field": "DocField",
"field_name": "contact_person",
"is_system_generated": 0,
"modified": "2022-12-27 17:51:31.467468",
"module": "Razorpay Payment Links Integration",
"name": "Payment Entry-contact_person-reqd",
"property": "reqd",
"property_type": "Check",
"row_name": null,
"value": "1"
}
]
8 changes: 1 addition & 7 deletions razorpay_payment_links_integration/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@
app_license = "MIT"
app_icon = "octicon credit-card"
app_color = "blue"
app_version = "0.0.3"
app_version = "1.0.0"

doctype_js = {
"Payment Entry" : "public/js/payment_entry.js"
}

before_install = "razorpay_payment_links_integration.setup.install.before_install"

# doc_events = {
# "Payment Entry": {
# "before_submit": "razorpay_payment_links_integration.customizations.payment_entry.before_submit"
# }
# }

fixtures = [
{"dt": "Custom Field", "filters": [["module", "=", "Razorpay Payment Links Integration"]]},
{"dt": "Property Setter", "filters": [["module", "=", "Razorpay Payment Links Integration"]]}
Expand Down
60 changes: 34 additions & 26 deletions razorpay_payment_links_integration/public/js/payment_entry.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
frappe.ui.form.on("Payment Entry", {
refresh: function(frm) {
if(frm.doc.razorpay_payment_link){
refresh: function (frm) {
if (frm.doc.razorpay_payment_link) {
frm.add_custom_button(__('Resend Notification'), () => {
frappe.call({
method: "razorpay_payment_links_integration.controller.resend_notification",
args: {"paymentLinkId": frm.doc.razorpay_payment_link},
callback: function(r) {
args: { "paymentLinkId": frm.doc.razorpay_payment_link },
callback: function (r) {
console.log(r);
}
});
})
}
},
mode_of_payment (frm) {
if (frm.doc.mode_of_payment!="Razorpay Payment Link") {
frm.add_custom_button(__("Create payment Link ") ,()=> {
frappe.call({
method:"razorpay_payment_links_integration.controller.create_payment_link",
args:{
doc: frm.doc
},
callback: function(r) {
console.log(r);
if (!frm.doc.__islocal && frm.doc.mode_of_payment == "Razorpay Payment Link" && !frm.doc.razorpay_payment_link) {
frm.add_custom_button(__("Create payment Link "), () => {
if (!frm.doc.paid_amount) {
frm.get_field('paid_amount').input.focus()
frappe.throw(__('Please enter Paid Amount to send payment link!'))
}
if (!frm.doc.contact_person) {
frm.get_field('contact_person').input.focus()
frappe.throw(__('Please select Contact to send payment link!'))
}

frappe.call({
method: "razorpay_payment_links_integration.controller.create_payment_link",
args: {
doc: frm.doc
},
callback: function (r) {
console.log(r);
frm.refresh();
}
})

})

}
},
razorpay_payment_status(frm) {
if (razorpay_payment_status=="Paid") {
frm.save('Submit');
// } else if (razorpay_payment_status=="Cancelled") {
// frm.save('Cancel');
// } else if (razorpay_payment_status=="Expired") {
// frm.save('Cancel');
// }
}
before_submit: function (frm) {
if (frm.doc.razorpay_payment_link && frm.doc.razorpay_payment_status != "Paid") {
frappe.warn('Are you sure you want to proceed?',
'Payment Entry documents are supposed to be auto-submitted when the Payment confirmation is received from the Razorpay.',
() => {
// action to perform if Continue is selected
},
'Continue',
true // Sets dialog as minimizable
)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-11-24 01:51:03.389025",
"modified": "2022-12-27 18:14:07.145460",
"modified_by": "Administrator",
"module": "Razorpay Payment Links Integration",
"name": "Razorpay Payment Links",
Expand All @@ -82,6 +82,15 @@
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"read": 1,
"report": 1,
"role": "All",
"select": 1
}
],
"sort_field": "modified",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# Copyright (c) 2022, Sameer Chauhan and contributors
# For license information, please see license.txt

# import frappe
import frappe
from frappe.model.document import Document

class RazorpayPaymentLinks(Document):
pass
def on_update(self):
if(self.get('payment_for')):
if(self.get('status') == "Paid"):
try:
pe_doc = frappe.get_doc('Payment Entry', self.get('payment_for'))
if(pe_doc.razorpay_payment_status != "Paid" and pe_doc.docstatus != 1):
pe_doc.razorpay_payment_status = "Paid"
pe_doc.docstatus = 1
pe_doc.save(ignore_permissions=True)
except:
frappe.log_error('Razorpay Payment entry submit failed', 'Razorpay Payment entry submit failed')
else:
frappe.db.set_value('Payment Entry', self.get('payment_for'), 'razorpay_payment_status', self.status)

0 comments on commit 05fe118

Please sign in to comment.