public JsonResult MakePaymentData(PaymentModel objPaymentModel, PaymentModel ObjData) { eTracLoginModel ObjLoginModel = null; long Vendor = 0; var result = ""; var resultPayment = new BillPayment(); if (Session["eTrac"] != null) { ObjLoginModel = (eTracLoginModel)(Session["eTrac"]); } try { if (objPaymentModel != null && ObjData != null) { objPaymentModel.UserId = ObjLoginModel.UserId; string realmId = CallbackController.RealMId.ToString(); // Session["realmId"].ToString(); try { if (realmId != null) { string AccessToken = CallbackController.AccessToken.ToString(); //Session["access_token"].ToString(); var principal = User as ClaimsPrincipal; OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(AccessToken); // Create a ServiceContext with Auth tokens and realmId ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.MinorVersion.Qbo = "23"; DataService commonServiceQBO = new DataService(serviceContext); // Create a QuickBooks QueryService using ServiceContext QueryService <Vendor> querySvc = new QueryService <Vendor>(serviceContext); List <Vendor> vendorList = querySvc.ExecuteIdsQuery("SELECT * FROM Vendor MaxResults 1000").ToList(); QueryService <Account> querySvcAccount = new QueryService <Account>(serviceContext); List <Account> accountData = querySvcAccount.ExecuteIdsQuery("SELECT * FROM Account MaxResults 1000").ToList(); var VendorDetails = _IVendorManagement.GetCompanyQuickBookId(Convert.ToInt64(ObjData.VendorId)); //var getAccountDetails = _IVendorManagement.GetAccountDetailsByVendorId(Convert.ToInt64(objPaymentModel.OpeartorCAD_Id)); // (Convert.ToInt64(ObjData.VendorId)); var getAccountDetails = _IVendorManagement.GetAccountDetailsByVendorId(Convert.ToInt64(objPaymentModel.CompanyAccountId)); // (Convert.ToInt64(ObjData.VendorId)); var getBill = _IBillDataManager.GetBillQBKId(Convert.ToInt64(ObjData.BillNo)); QueryService <Bill> querySvcBill = new QueryService <Bill>(serviceContext); List <Bill> billData = querySvcBill.ExecuteIdsQuery("SELECT * FROM Bill MaxResults 1000").ToList(); var bill = billData.Where(x => x.Id == getBill.ToString()).FirstOrDefault(); // var vendorData = vendorList.Where(x => x.Id == "64").FirstOrDefault(); var payment = new BillPayment(); //Vendor Reference var reference = new ReferenceType(); var accountRef = new AccountBasedExpenseLineDetail(); var billPaymentCheck = new BillPaymentCheck(); var billPaymentCredit = new BillPaymentCreditCard(); var line = new Line(); var lineList = new List <Line>(); if (VendorDetails > 0) { var vendorData = vendorList.Where(x => x.Id == VendorDetails.ToString()).FirstOrDefault(); //Vendor Reference payment.VendorRef = new ReferenceType() { name = vendorData.DisplayName, Value = vendorData.Id }; } line.LineNum = "1"; var any = new IntuitAnyType(); if (getAccountDetails != null) { var ayintuit = new IntuitAnyType(); var accountsDetails = accountData.Where(x => x.Id == getAccountDetails.QuickbookAcountId.ToString()).FirstOrDefault();//getAccountDetails.QuickbookAcountId.ToString() if (ObjData.PaymentMode == "Wired") { payment.PayType = BillPaymentTypeEnum.CreditCard; var CCD = new CreditCardPayment(); billPaymentCredit.CCAccountRef = new ReferenceType() { name = accountsDetails.Name, Value = accountsDetails.Id, }; payment.AnyIntuitObject = billPaymentCredit; } else if (ObjData.PaymentMode == "Card") { payment.PayType = BillPaymentTypeEnum.CreditCard; var CCD = new CreditCardPayment(); billPaymentCredit.CCAccountRef = new ReferenceType() { name = accountsDetails.Name, Value = accountsDetails.Id, }; payment.AnyIntuitObject = billPaymentCredit; } else if (ObjData.PaymentMode == "Check") { var checking = new CheckPayment(); payment.PayType = BillPaymentTypeEnum.Check; billPaymentCheck.BankAccountRef = new ReferenceType() { name = accountsDetails.Name, Value = accountsDetails.Id }; billPaymentCheck.PrintStatus = PrintStatusEnum.NeedToPrint; payment.AnyIntuitObject = billPaymentCheck; } } payment.APAccountRef = new ReferenceType() { name = "Accounts Payable (A/P)", Value = "33" }; QueryService <Department> querySvcDept = new QueryService <Department>(serviceContext); var LocationName = _IBillDataManager.GetLocationDataByLocId(Convert.ToInt64(ObjData.LocationId)); payment.DepartmentRef = new ReferenceType() { name = LocationName.LocationName, Value = LocationName.QBK_Id.ToString() }; line.Amount = Convert.ToDecimal(ObjData.BillAmount); line.AmountSpecified = true; var linkedlist = new List <LinkedTxn>(); var linked = new LinkedTxn(); linked.TxnId = bill.Id; linked.TxnType = "Bill"; linkedlist.Add(linked); line.LinkedTxn = linkedlist.ToArray(); line.DetailType = LineDetailTypeEnum.PaymentLineDetail; lineList.Add(line); payment.Line = lineList.ToArray(); //payment.PayType = BillPaymentTypeEnum.CreditCard; payment.PayTypeSpecified = true; payment.TotalAmt = Convert.ToDecimal(ObjData.BillAmount); payment.TotalAmtSpecified = true; var metaData = new ModificationMetaData(); metaData.CreateTime = Convert.ToDateTime(ObjData.BillDate); payment.MetaData = metaData; payment.PayTypeSpecified = true; resultPayment = commonServiceQBO.Add(payment) as BillPayment; //To close PO after Payment. Update Payment in Quickbook. QueryService <PurchaseOrder> querySvcPO = new QueryService <PurchaseOrder>(serviceContext); List <PurchaseOrder> POList = querySvcPO.ExecuteIdsQuery("SELECT * FROM PurchaseOrder MaxResults 1000").ToList(); if (ObjData.BillType == "PO") { var getPOQData = _IPaymentManager.GetPODetails(objPaymentModel, ObjData); if (getPOQData.QuickBookPOId > 0) { var data = POList.Where(x => x.Id == getPOQData.QuickBookPOId.ToString()).FirstOrDefault(); data.POStatus = PurchaseOrderStatusEnum.Closed; var update = commonServiceQBO.Update(data) as PurchaseOrder; } } } else { ViewBag.Message = CommonMessage.FailureMessage(); result = CommonMessage.FailureMessage(); ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; return(Json(result, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { ViewBag.Message = ex.Message; ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; } result = _IPaymentManager.MakePayment(objPaymentModel, ObjData); if (result != null) { return(Json(result, JsonRequestBehavior.AllowGet)); } else { ViewBag.Message = CommonMessage.FailureMessage(); ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; return(Json(result, JsonRequestBehavior.AllowGet)); } } else { ViewBag.Message = CommonMessage.FailureMessage(); ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger; } } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } //return null; return(Json(result, JsonRequestBehavior.AllowGet)); }