mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-12 17:51:20 +00:00
feat: decode signed json and QR code
This commit is contained in:
committed by
Deepesh Garg
parent
b855a32d84
commit
bc3b5e334b
@@ -29,6 +29,19 @@ frappe.ui.form.on('E Invoice Settings', {
|
|||||||
callback: (res) => console.log(res)
|
callback: (res) => console.log(res)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frm.add_custom_button(__("Fetch IRN Details"),
|
||||||
|
() => {
|
||||||
|
frm.call({
|
||||||
|
doc: frm.doc,
|
||||||
|
method: 'get_irn_details',
|
||||||
|
args: {
|
||||||
|
'irn': 'c63d9e180dfdaa9242e29e2e1e0a8d76f20e116ed3de179a2e9120f384e1b432'
|
||||||
|
},
|
||||||
|
freeze: true,
|
||||||
|
callback: (res) => console.log(res)
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
show_fetch_token_btn(frm) {
|
show_fetch_token_btn(frm) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import jwt
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
import frappe
|
import frappe
|
||||||
@@ -65,6 +66,9 @@ class EInvoiceSettings(Document):
|
|||||||
enc_msg = cipher.encrypt(padded_bytes_msg)
|
enc_msg = cipher.encrypt(padded_bytes_msg)
|
||||||
b64_enc_msg = base64.b64encode(enc_msg)
|
b64_enc_msg = base64.b64encode(enc_msg)
|
||||||
return b64_enc_msg.decode()
|
return b64_enc_msg.decode()
|
||||||
|
|
||||||
|
def jwt_decrypt(self, token):
|
||||||
|
return jwt.decode(token, verify=False)
|
||||||
|
|
||||||
def make_authentication_request(self):
|
def make_authentication_request(self):
|
||||||
endpoint = 'https://einv-apisandbox.nic.in/eivital/v1.03/auth'
|
endpoint = 'https://einv-apisandbox.nic.in/eivital/v1.03/auth'
|
||||||
@@ -129,9 +133,12 @@ class EInvoiceSettings(Document):
|
|||||||
res = make_post_request(endpoint, headers=headers, data=json.dumps(payload))
|
res = make_post_request(endpoint, headers=headers, data=json.dumps(payload))
|
||||||
self.handle_err_response(res)
|
self.handle_err_response(res)
|
||||||
|
|
||||||
return res
|
data = json.loads(res)
|
||||||
|
self.handle_irn_response(data)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def get_irn_detials(self, irn):
|
def get_irn_details(self, irn):
|
||||||
endpoint = 'https://einv-apisandbox.nic.in/eicore/v1.03/Invoice/irn/{irn}'.format(irn=irn)
|
endpoint = 'https://einv-apisandbox.nic.in/eicore/v1.03/Invoice/irn/{irn}'.format(irn=irn)
|
||||||
headers = self.get_header()
|
headers = self.get_header()
|
||||||
|
|
||||||
@@ -140,9 +147,19 @@ class EInvoiceSettings(Document):
|
|||||||
|
|
||||||
enc_json = res.get('Data')
|
enc_json = res.get('Data')
|
||||||
json_str = self.aes_decrypt(enc_json, self.sek)
|
json_str = self.aes_decrypt(enc_json, self.sek)
|
||||||
|
|
||||||
data = json.loads(json_str)
|
data = json.loads(json_str)
|
||||||
|
self.handle_irn_response(data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def handle_irn_response(self, data):
|
||||||
|
enc_signed_invoice = data['SignedInvoice']
|
||||||
|
enc_signed_qr_code = data['SignedQRCode']
|
||||||
|
signed_invoice = self.jwt_decrypt(enc_signed_invoice)['data']
|
||||||
|
signed_qr_code = self.jwt_decrypt(enc_signed_qr_code)['data']
|
||||||
|
data['DecryptedSignedInvoice'] = json.loads(signed_invoice)
|
||||||
|
data['DecryptedSignedQRCode'] = json.loads(signed_qr_code)
|
||||||
|
|
||||||
def handle_err_response(self, response):
|
def handle_err_response(self, response):
|
||||||
if response.get('Status') == 0:
|
if response.get('Status') == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user