kenince
September 18, 2018, 7:52pm
1
Hi Guys,
I’ve tried all I could but I still can’t seem to figure it out.
I want to make a Post Rest call from erpnext as soon as a Sale Invoice is paid. I’ve noticed that the doc type changes to Payment Entry once you click on Make Payment.
I would like to pass the payment details of the invoice on to another server as soon as the invoice is marked paid. Say the URL for the endpoint is: http://myserver:8001/middlewareserver/callback/
The information I would like to pass to the middleware is:
{
“doctype”: “Sales Invoice”,
“name”: “ACC-SINV-2018-00046”,
“creation”: “2018-09-18 22:01:03.201931”,
“customer_name”: “ALEX WAYNE”,
“customer”: “CUST-2018-00054”,
“grand_total”: 150,
“outstanding_amount”: 0
}
If it’s not possible to get the invoice data directly from the Sales Invoice doc type, then from the Payment Entry doc type, I could get:
{
“party_balance”: 150,
“creation”: “2018-09-18 21:24:10.524375”,
“name”: “ACC-PAY-2018-00025”,
“paid_amount”: 120,
“title”: “CUST-2018-00058”
}
Could you assist me in knowing how I can implement that call to the middleware server and pass that information.
Thanks in advance.
Kenince
@kenince share the code snippets you tried
kenince
September 19, 2018, 2:06pm
3
@hereabdulla here you go…
In payment_request.py
@frappe.whitelist ()
def update_middleware(doc, method):
if doc.references:
for item in doc.references:
header = {‘content-type’: “application/json”, }
url = ‘http://myserver:8001/middlewareserver/callback/ ’
data = {
“reference_doctype”: item.reference_doctype,
“creation”: item.creation,
“name”: item.name,
“paid_amount”: item.total_amount,
“customer”: item.reference_name
}
res = requests.post(url, data=data, haeders=header)
return res
In hooks.py
“Payment Entry”: {
“on_submit”: [“erpnext.regional.france.utils.create_transaction_log”, “erpnext.accounts.doctype.payment_request.payment_request.make_status_as_paid”,
“erpnext.accounts.doctype.payment_request.payment_request.update_middleware”],
“on_trash”: “erpnext.regional.check_deletion_permission”
},
kenince:
payment_request.py
In the 15th line of your payment_request.py file you have a typo (‘haeders’)…That may be the issue.
1 Like
kenince
September 20, 2018, 5:50am
5
Thanks @chabito79 for noticing that. Let me fix this and try again. I’ll give feedback.