Untitled
unknown
javascript
a year ago
2.5 kB
7
Indexable
const cbLoan = async () => { const response = await axios.post(API_ENDPOINTS.invoice.exportINVPdf, { _id: paymentObj._id, }); try { const link = `${userAttachments.url}${response.blobPath}${userAttachments.token}`; const postData = { trade_financing_type: 'invoice_financing', currency: 'pkr', email, invoice_data: [ { resourceURL: link, name: paymentObj._id, }, ], required_financing: parseInt(requestedAmount), }; const rePostData = { invoice_data: [ { resourceURL: link, name: paymentObj._id, }, ], }; let cb = {} if (invoice?.invoiceFinanceObject?.advanceKycLoan?.event_data?.status === "need_more_info" || invoice?.invoiceFinanceObject?.advanceKycLoan?.event_data?.status === "rejected" ) { cb = await axios.post( `${CREDITBOOK_URL}/api/v1/external-lending/sme/loans/${invoice?.invoiceFinanceObject?.advanceKycLoan?.event_data.loan_id}`, { postData:rePostData}, { headers: { accept: 'application/json', Authorization: `Bearer ${creditBookToken}`, 'Content-Type': 'application/json', }, } ); } else { cb = await axios.post( `${CREDITBOOK_URL}/api/v1/external-lending/sme/loans`, postData, { headers: { accept: 'application/json', Authorization: `Bearer ${creditBookToken}`, 'Content-Type': 'application/json', }, } ); } // save all RAW responce on DB await axiosInstance.post(`${API_ENDPOINTS.finance.add_LP_Raw_Responce_invoice}`, { lendingPartner: 'CreditBook', vendorId: userId, invoiceMongoId: paymentObj._id, ...cb, }); // webhook await axios.post(`${API_ENDPOINTS.finance.cbLoan}`, { invoiceMongoId: paymentObj._id, lendingPartner: 'CreditBook', email, timestamp: new Date(), event_data: { status: 'pending', reason: 'Update by User', comment: '', loan_id: cb?.loan?.id, }, }); } catch (error) { console.log('🚀 ~ cbLoan ~ error:', error); throw new Error(error); } };
Editor is loading...
Leave a Comment