Skip to content

Commit 05fe118

Browse files
author
Sameer Chauhan
committed
all testing done at pe and bug fixing
1 parent 6eb945c commit 05fe118

File tree

8 files changed

+86
-60
lines changed

8 files changed

+86
-60
lines changed

razorpay_payment_links_integration/controller.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,27 @@ def resend_notification(**kwargs):
2727
paymentLinkId = kwargs['paymentLinkId']
2828
RazorpayController().resend_notification(paymentLinkId)
2929

30+
3031
@frappe.whitelist()
3132
def create_payment_link(**Kwargs):
3233
"""
3334
create request on the basis of pe_doc
3435
then create a new Razorpay Payment link record if payment link is created
3536
"""
3637
pe_doc=json.loads(Kwargs['doc'])
37-
frappe.log_error('create payment link',pe_doc)
3838

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

4141
request = {}
42-
request['amount'] = pe_doc.get('paid_amount')
42+
request['amount'] = int(pe_doc.get('paid_amount')) * 100 # convert it to smallest value
4343
request['currency'] = "INR"
44-
request['description'] = "For SO" # to udpate
44+
45+
request['description'] = ""
46+
for ref in pe_doc.get('references', []):
47+
request['description'] = request['description'] + f"{ref.get('reference_doctype')}: {ref.get('reference_name')}, "
4548

4649
request['customer'] = {}
47-
request['customer']['name'] = f"{contact_doc.get('first_name', '')} {contact_doc.get('middle_name', '')} {contact_doc.get('last_name')}"
50+
request['customer']['name'] = f"{contact_doc.get('first_name') or ''} {contact_doc.get('middle_name') or ''} {contact_doc.get('last_name') or ''}"
4851
request['customer']['email'] = contact_doc.get('email_id', '')
4952
request['customer']['contact'] = contact_doc.get('mobile_no', '')
5053

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

60-
razorpayObj = RazorpayController.get_client()
61+
razorpayObj = RazorpayController().get_client()
6162
link_obj = razorpayObj.payment_link.create(request)
6263

6364
if(link_obj.get('error')):
@@ -70,13 +71,13 @@ def create_payment_link(**Kwargs):
7071
doc.link = link_obj.get('short_url')
7172
doc.amount = link_obj.get('amount')
7273
doc.insert()
74+
frappe.db.set_value('Payment Entry', pe_doc.get('name'), 'razorpay_payment_link', doc.name)
7375
return doc
7476

7577

7678
@frappe.whitelist(allow_guest=True)
7779
def webhooks_handler():
7880
data = json.loads(frappe.request.data)
79-
frappe.log_error('Razorpay', data)
8081
doc = False
8182

8283
try:

razorpay_payment_links_integration/customizations/payment_entry.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

razorpay_payment_links_integration/fixtures/custom_field.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"docstatus": 0,
6666
"doctype": "Custom Field",
6767
"dt": "Payment Entry",
68-
"fetch_from": "razorpay_payment_link.status",
68+
"fetch_from": "razorpay_payment_links.status",
6969
"fetch_if_empty": 1,
7070
"fieldname": "razorpay_payment_status",
7171
"fieldtype": "Data",

razorpay_payment_links_integration/fixtures/property_setter.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,21 @@
3030
"property_type": "Check",
3131
"row_name": null,
3232
"value": "1"
33+
},
34+
{
35+
"default_value": null,
36+
"doc_type": "Payment Entry",
37+
"docstatus": 0,
38+
"doctype": "Property Setter",
39+
"doctype_or_field": "DocField",
40+
"field_name": "contact_person",
41+
"is_system_generated": 0,
42+
"modified": "2022-12-27 17:51:31.467468",
43+
"module": "Razorpay Payment Links Integration",
44+
"name": "Payment Entry-contact_person-reqd",
45+
"property": "reqd",
46+
"property_type": "Check",
47+
"row_name": null,
48+
"value": "1"
3349
}
3450
]

razorpay_payment_links_integration/hooks.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@
88
app_license = "MIT"
99
app_icon = "octicon credit-card"
1010
app_color = "blue"
11-
app_version = "0.0.3"
11+
app_version = "1.0.0"
1212

1313
doctype_js = {
1414
"Payment Entry" : "public/js/payment_entry.js"
1515
}
1616

1717
before_install = "razorpay_payment_links_integration.setup.install.before_install"
1818

19-
# doc_events = {
20-
# "Payment Entry": {
21-
# "before_submit": "razorpay_payment_links_integration.customizations.payment_entry.before_submit"
22-
# }
23-
# }
24-
2519
fixtures = [
2620
{"dt": "Custom Field", "filters": [["module", "=", "Razorpay Payment Links Integration"]]},
2721
{"dt": "Property Setter", "filters": [["module", "=", "Razorpay Payment Links Integration"]]}
Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
frappe.ui.form.on("Payment Entry", {
2-
refresh: function(frm) {
3-
if(frm.doc.razorpay_payment_link){
2+
refresh: function (frm) {
3+
if (frm.doc.razorpay_payment_link) {
44
frm.add_custom_button(__('Resend Notification'), () => {
55
frappe.call({
66
method: "razorpay_payment_links_integration.controller.resend_notification",
7-
args: {"paymentLinkId": frm.doc.razorpay_payment_link},
8-
callback: function(r) {
7+
args: { "paymentLinkId": frm.doc.razorpay_payment_link },
8+
callback: function (r) {
99
console.log(r);
1010
}
1111
});
1212
})
1313
}
14-
},
15-
mode_of_payment (frm) {
16-
if (frm.doc.mode_of_payment!="Razorpay Payment Link") {
17-
frm.add_custom_button(__("Create payment Link ") ,()=> {
18-
frappe.call({
19-
method:"razorpay_payment_links_integration.controller.create_payment_link",
20-
args:{
21-
doc: frm.doc
22-
},
23-
callback: function(r) {
24-
console.log(r);
14+
if (!frm.doc.__islocal && frm.doc.mode_of_payment == "Razorpay Payment Link" && !frm.doc.razorpay_payment_link) {
15+
frm.add_custom_button(__("Create payment Link "), () => {
16+
if (!frm.doc.paid_amount) {
17+
frm.get_field('paid_amount').input.focus()
18+
frappe.throw(__('Please enter Paid Amount to send payment link!'))
19+
}
20+
if (!frm.doc.contact_person) {
21+
frm.get_field('contact_person').input.focus()
22+
frappe.throw(__('Please select Contact to send payment link!'))
23+
}
24+
25+
frappe.call({
26+
method: "razorpay_payment_links_integration.controller.create_payment_link",
27+
args: {
28+
doc: frm.doc
29+
},
30+
callback: function (r) {
31+
console.log(r);
32+
frm.refresh();
2533
}
2634
})
27-
2835
})
29-
3036
}
3137
},
32-
razorpay_payment_status(frm) {
33-
if (razorpay_payment_status=="Paid") {
34-
frm.save('Submit');
35-
// } else if (razorpay_payment_status=="Cancelled") {
36-
// frm.save('Cancel');
37-
// } else if (razorpay_payment_status=="Expired") {
38-
// frm.save('Cancel');
39-
// }
40-
}
38+
before_submit: function (frm) {
39+
if (frm.doc.razorpay_payment_link && frm.doc.razorpay_payment_status != "Paid") {
40+
frappe.warn('Are you sure you want to proceed?',
41+
'Payment Entry documents are supposed to be auto-submitted when the Payment confirmation is received from the Razorpay.',
42+
() => {
43+
// action to perform if Continue is selected
44+
},
45+
'Continue',
46+
true // Sets dialog as minimizable
47+
)
48+
}
4149
}
4250
})

razorpay_payment_links_integration/razorpay_payment_links_integration/doctype/razorpay_payment_links/razorpay_payment_links.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"in_create": 1,
6565
"index_web_pages_for_search": 1,
6666
"links": [],
67-
"modified": "2022-11-24 01:51:03.389025",
67+
"modified": "2022-12-27 18:14:07.145460",
6868
"modified_by": "Administrator",
6969
"module": "Razorpay Payment Links Integration",
7070
"name": "Razorpay Payment Links",
@@ -82,6 +82,15 @@
8282
"role": "System Manager",
8383
"share": 1,
8484
"write": 1
85+
},
86+
{
87+
"create": 1,
88+
"delete": 1,
89+
"email": 1,
90+
"read": 1,
91+
"report": 1,
92+
"role": "All",
93+
"select": 1
8594
}
8695
],
8796
"sort_field": "modified",
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
# Copyright (c) 2022, Sameer Chauhan and contributors
22
# For license information, please see license.txt
33

4-
# import frappe
4+
import frappe
55
from frappe.model.document import Document
66

77
class RazorpayPaymentLinks(Document):
8-
pass
8+
def on_update(self):
9+
if(self.get('payment_for')):
10+
if(self.get('status') == "Paid"):
11+
try:
12+
pe_doc = frappe.get_doc('Payment Entry', self.get('payment_for'))
13+
if(pe_doc.razorpay_payment_status != "Paid" and pe_doc.docstatus != 1):
14+
pe_doc.razorpay_payment_status = "Paid"
15+
pe_doc.docstatus = 1
16+
pe_doc.save(ignore_permissions=True)
17+
except:
18+
frappe.log_error('Razorpay Payment entry submit failed', 'Razorpay Payment entry submit failed')
19+
else:
20+
frappe.db.set_value('Payment Entry', self.get('payment_for'), 'razorpay_payment_status', self.status)
21+

0 commit comments

Comments
 (0)