I am able to create invoice on quickbook online, but when i check quickbook invoice online, it create the item lists but the price and description is missing. What i am doing wrong.
invoice.AlternateId = new NameValue[] { new NameValue() { Name = "InvoiceID", Value = service.InvoiceId } };
InvoiceHeader Header = new InvoiceHeader();
Header.DocNumber = service.InvoiceId;
Header.TxnDate = service.ServiceDate;
Header.TxnDateSpecified = true;
Header.Msg = service.Note.ToString();
Header.Note = service.Note.ToString();
Header.CustomerId = new IdType() { idDomain = idDomainEnum.QBO, Value = service.CustomerNumberOnline };
Header.Currency = currencyCode.USD;
Header.ShipDate = service.ServiceDate;
Header.ShipDateSpecified = true;
//Print and Email Option fields
if (EmailPrintOption == "Both")
{
Header.ToBeEmailed = true;
Header.ToBeEmailedSpecified = true;
Header.ToBePrinted = true;
Header.ToBePrintedSpecified = true;
}
else if (EmailPrintOption == "print")
{
Header.ToBePrinted = true;
Header.ToBePrintedSpecified = true;
}
else if (EmailPrintOption == "email")
{
Header.ToBeEmailed = true;
Header.ToBeEmailedSpecified = true;
}
else
{
Header.ToBeEmailed = false;
Header.ToBeEmailedSpecified = false;
Header.ToBePrinted = false;
Header.ToBePrintedSpecified = false;
}
PhysicalAddress BillAddress = new PhysicalAddress();
BillAddress.Line1 = service.SoldToAddress;
BillAddress.City = service.SoldToCity;
BillAddress.CountrySubDivisionCode = service.SoldToState;
BillAddress.PostalCode = service.SoldToZip;
BillAddress.Tag = new string[] { "Billing" };
Header.BillAddr = BillAddress;
PhysicalAddress ShipAddress = new PhysicalAddress();
ShipAddress.Line1 = service.JobJocationAddress;
ShipAddress.City = service.JobLocationCity;
ShipAddress.CountrySubDivisionCode = service.JobLocationState;
ShipAddress.PostalCode = service.JobLocationZip;
BillAddress.Tag = new string[] { "Shipping" };
Header.ShipAddr = ShipAddress;
decimal discount;
if (decimal.TryParse(service.Discount, out discount))
{
Header.ItemElementName = ItemChoiceType2.DiscountAmt;
Header.Item = -1 * discount; //discount must be negative
}
InvoiceLine[] InvoiceLines = new InvoiceLine[TaskOnlineIDs.Count];
object[] intuitItems = new object[TaskOnlineIDs.Count];
for (int i = 0; i < InvoiceLines.Length; i++)
{
InvoiceLines[i] = new InvoiceLine();
InvoiceLines[i].ItemsElementName = new Intuit.Ipp.Data.Qbo.ItemsChoiceType2[]
{
Intuit.Ipp.Data.Qbo.ItemsChoiceType2.ItemId
};
InvoiceLines[i].Items = new object[] {
new IdType(){idDomain=idDomainEnum.QBO, Value=TaskOnlineIDs[i]}
};
}
invoice.Line = InvoiceLines;
Header.SalesTermName = service.PaymentType;
Header.SalesRepName = service.TechName;
Header.PONumber = service.PurchaseOrder;
invoice.Header = Header;
What i miss here ??
Here what happen is, when i add invoice lines to invoice it set amount of each item to "0" by default, so when i try to add discount pragmatically it give's me error of discount greater than subtotal which is correct. But my question is why do i need to add cost for each item explicitly when i have already defined them earlier. We should add only itemId and rest QB should calculate.
Related
I have below json data I need to apply CAdES-BES Signature with Automatic JSON Canonicalization. Please find my json data below. Helpful link from https://www.example-code.com/Csharp/itida_egypt_cades_bes_json_canonicalization.asp. I follow the steps but still digital signature is not applying. Its returns normal json data.
[HttpGet]
[Route("api/invoiceLines/")]
public IHttpActionResult getEInvoiceLines()
{
Chilkat.Crypt2 crypt = new Chilkat.Crypt2();
crypt.VerboseLogging = true;
Chilkat.Cert cert = new Chilkat.Cert();
cert.VerboseLogging = true;
// Set the smart card PIN, which will be needed for signing.
cert.SmartCardPin = "1245345";
// There are many ways to load the certificate.
// This example was created for a customer using an ePass2003 USB token.
// Assuming the USB token is the only source of a hardware-based private key..
bool success = cert.LoadFromSmartcard(#"E"); //Is this Right way To load certificate ?
Chilkat.JsonObject cmsOptions = new Chilkat.JsonObject();
// Setting "DigestData" causes OID 1.2.840.113549.1.7.5 (digestData) to be used.
cmsOptions.UpdateBool("DigestData", true);
cmsOptions.UpdateBool("OmitAlgorithmIdNull", true);
// Indicate that we are passing normal JSON and we want Chilkat do automatically
// do the ITIDA JSON canonicalization:
cmsOptions.UpdateBool("CanonicalizeITIDA", true);
crypt.CmsOptions = cmsOptions.Emit();
// The CadesEnabled property applies to all methods that create CMS/PKCS7 signatures.
// To create a CAdES-BES signature, set this property equal to true.
crypt.CadesEnabled = true;
crypt.HashAlgorithm = "sha256";
Chilkat.JsonObject jsonSigningAttrs = new Chilkat.JsonObject();
jsonSigningAttrs.UpdateInt("contentType", 1);
jsonSigningAttrs.UpdateInt("signingTime", 1);
jsonSigningAttrs.UpdateInt("messageDigest", 1);
jsonSigningAttrs.UpdateInt("signingCertificateV2", 1);
crypt.SigningAttributes = jsonSigningAttrs.Emit();
// By default, all the certs in the chain of authentication are included in the signature.
// If desired, we can choose to only include the signing certificate:
crypt.IncludeCertChain = false;
EInvoiceModel.Example ds = new EInvoiceModel.Example();
//Start issuer details
ds.issuer = new EInvoiceModel.Issuer();
ds.issuer.type = "B";
ds.issuer.id = "113317713";
ds.issuer.name = "Issuer Company";
//Start issuer address details
ds.issuer.address = new EInvoiceModel.Address();
ds.issuer.address.branchID = "1";
ds.issuer.address.country = "EG";
ds.issuer.address.governate = "Cairo";
ds.issuer.address.regionCity = "Nasr City";
ds.issuer.address.street = "stree1";
ds.issuer.address.buildingNumber = "Bldg. 0";
ds.issuer.address.postalCode = "68030";
ds.issuer.address.floor = "1";
ds.issuer.address.room = "123";
ds.issuer.address.landmark = "7660 Melody Trail";
ds.issuer.address.additionalInformation = "beside Town Hall";
//Start Receiver details
ds.receiver = new EInvoiceModel.Receiver();
ds.receiver.type = "B";
ds.receiver.id = "3125617";
ds.receiver.name = "Receiver company";
//Start Receiver address datails
ds.receiver.address = new EInvoiceModel.AddressReceiver();
ds.receiver.address.country = "EG";
ds.receiver.address.governate = "Cairo";
ds.receiver.address.regionCity = "Nasr City";
ds.receiver.address.street = "stree1";
ds.receiver.address.buildingNumber = "Bldg. 0";
ds.receiver.address.postalCode = "68030";
ds.receiver.address.floor = "1";
ds.receiver.address.room = "123";
ds.receiver.address.landmark = "7660 Melody Trail";
ds.receiver.address.additionalInformation = "beside Town Hall";
//Document type & version
ds.documentType = "i";
ds.documentTypeVersion = "1.0";
DateTime d = new DateTime();
ds.dateTimeIssued = d; //Invoice date
ds.taxpayerActivityCode = "9478"; //needed info
ds.internalID = "WADIn1234"; //Internal Invoice number
ds.salesOrderReference = "So1234"; //So number //optional
ds.salesOrderDescription = "SO1234"; //So additional Info //optional
ds.proformaInvoiceNumber = "SoPro123"; //optional
//Invoiceline Start
ds.invoiceLines = new List<EInvoiceModel.InvoiceLine>
{
new EInvoiceModel.InvoiceLine
{
description = "Computer1",
itemType = "GPC",
itemCode = "10001774",
unitType = "EA",
quantity = 2,
internalCode = "IC0",
salesTotal = 23.99,
total = 2969.89,
valueDifference = 7.00,
totalTaxableFees = 817.42,
netTotal = 880.71,
itemsDiscount = 5.00,
unitValue = new EInvoiceModel.UnitValue
{
currencySold = "EUR",
amountEGP = 189.40,
amountSold = 10.00,
currencyExchangeRate = 18.94,
},
discount = new EInvoiceModel.Discount
{
rate = 7,
amount = 66.29
},
taxableItems = new List<EInvoiceModel.TaxableItem>
{
new EInvoiceModel.TaxableItem
{
taxType = "T1",
amount = 272.07,
subType = "T1",
rate = 12
}
}
}
}; //Invoice Lines End
//Items total Discount and Sales/NetAmount
ds.totalDiscountAmount = 76.29;
ds.totalSalesAmount = 1609.90;
ds.netAmount = 1533.61;
//Tax Total Start
ds.taxTotals = new List<EInvoiceModel.TaxTotal>
{
new EInvoiceModel.TaxTotal
{
taxType = "T1",
amount = 477.54,
}
};//Tax Total End
//Total Sales Amount & discounts
ds.totalAmount = 5191.50;
ds.extraDiscountAmount = 5.00;
ds.totalItemsDiscountAmount = 14.00;
string strResultJson = JsonConvert.SerializeObject(ds);
//System.IO.File.WriteAllText(#"C:\inetpub\wwwroot\path.json", strResultJson);
// File.WriteAllText(#"ds.json", strResultJson);
// string jsonToSign = "{ ... }";
string jsonToSign = strResultJson;
// Create the CAdES-BES signature.
crypt.EncodingMode = "base64";
// Make sure we sign the utf-8 byte representation of the JSON string
crypt.Charset = "utf-8";
string sigBase64 = crypt.SignStringENC(jsonToSign);
// return Ok(ds);
return Ok(sigBase64);
}
public static string SerializeObject2(object obj, int indent = 0)
{
var sb = new StringBuilder();
if (obj != null)
{
string indentString = new string(' ', indent);
if (obj is string || obj.IsNumber())
{
sb.Append($"\"{obj}\"");
}
else if (obj.GetType().BaseType == typeof(Enum))
{
sb.Append($"\"{obj.ToString()}\"");
}
else if (obj is Array)
{
var elems = obj as IList;
sb.Append($"{indentString}- [{elems.Count}] :\n");
for (int i = 0; i < elems.Count; i++)
{
sb.Append(SerializeObject2(elems[i], indent + 4));
}
}
else
{
Type objType = (obj).GetType();
PropertyInfo[] props = objType.GetProperties();
foreach (PropertyInfo prop in props)
{
if (prop.GetIndexParameters().Length == 0)
{
object propValue = prop.GetValue(obj);
var elems = propValue as IList;
if (elems != null)
{
sb.Append($"\"{prop.Name.ToUpper()}\"");
foreach (var item in elems)
{
sb.Append($"\"{prop.Name.ToUpper()}\"");
sb.Append(SerializeObject2(item, indent + 4));
}
}
else
{
if (Assembly.GetExecutingAssembly().DefinedTypes.Select(p => p.Assembly).ToList().Contains(prop.PropertyType.Assembly))
{
sb.Append($"\"{prop.Name.ToUpper()}\"");
sb.Append(SerializeObject2(propValue, indent + 4));
}
else
{
sb.Append($"\"{prop.Name.ToUpper()}\"\"{propValue}\"");
}
}
}
else if (objType.GetProperty("Item") != null)
{
int count = -1;
if (objType.GetProperty("Count") != null &&
objType.GetProperty("Count").PropertyType == typeof(int))
{
count = (int)objType.GetProperty("Count").GetValue(obj, null);
}
for (int i = 0; i < count; i++)
{
object val = prop.GetValue(obj, new object[] { i });
sb.Append(SerializeObject2(val, indent + 4));
}
}
}
}
}
return sb.ToString();
}
In a list i have 4 rows and I am try to get all the rows of the list but it is giving only one row, how to get all the rows of the list.
I have tried below code
public async Task<ResponseUserModel> get()
{
List<ResponseUserModel> responseUsers = new List<ResponseUserModel>();
using (nae2sasqld0003Entities context = new nae2sasqld0003Entities())
{
var listt = context.Producers.Select(all => all).ToList();
foreach (var item in listt)
{
responseUsers.Add(new ResponseUserModel
{
ProducerName = item.ProducerName,
ResidentState = item.ResidentState,
ResidentCity = item.ResidentCity,
ProducerStatus = item.ProducerStatus,
ProducerCode = item.ProducerCode,
MasterCode = item.MasterCode,
NationalCode = item.NationalCode,
LegacyChubbCodes = item.LegacyChubbCodes,
LegacyPMSCode = item.LegacyPMSCode,
ProducingBranchCode = item.ProducingBranchCode,
CategoryCode = item.CategoryCode
});
}
return responseUsers;
}
}
please let me know where i to fix the issue
Use list to return all:
List<ResponseUserModel> responseUsers = new List<ResponseUserModel>();
then
foreach (var item in listt)
{
responseUsers.Add(new ResponseUserModel
{
ProducerName = item.ProducerName,
ResidentState = item.ResidentState,
ResidentCity = item.ResidentCity,
ProducerStatus = item.ProducerStatus,
ProducerCode = item.ProducerCode,
MasterCode = item.MasterCode,
NationalCode = item.NationalCode,
LegacyChubbCodes = item.LegacyChubbCodes,
LegacyPMSCode = item.LegacyPMSCode,
ProducingBranchCode = item.ProducingBranchCode,
CategoryCode = item.CategoryCode
});
}
return responseUsers;
Note: change return type of the method to IList<ResponseUserModel>
or in this way
using (var context = new nae2sasqld0003Entities())
{
return context.Producers.Select(item =>
new ResponseUserModel
{
ProducerName = item.ProducerName,
ResidentState = item.ResidentState,
ResidentCity = item.ResidentCity,
ProducerStatus = item.ProducerStatus,
ProducerCode = item.ProducerCode,
MasterCode = item.MasterCode,
NationalCode = item.NationalCode,
LegacyChubbCodes = item.LegacyChubbCodes,
LegacyPMSCode = item.LegacyPMSCode,
ProducingBranchCode = item.ProducingBranchCode,
CategoryCode = item.CategoryCode
}).ToList();
}
I'm currently having an error(as mentioned in the title). I don't know what's wrong or which line I'm having problems with. I'm sure all the values mentioned in the error are the same but it still pops up the same error.
My aim is to make the all the values the same to solve the error.
Here's the full description of my error:
{
"name": "https://stackoverflow.com/VALIDATION_ERROR",
"details": [
{
"field": "transactions[0]",
"issue": "Item amount must add up to specified amount subtotal (or total if amount details not specified)"
}
],
"message": "Invalid request - see details",
"information_link": "https://developer.paypal.com/docs/api/payments/#errors",
"debug_id": "67a354f1a8fc7"
}
Please help!
Here are my codes for reference:
// scList has 2 values inside.
List<UserShoppingCartDAO> scList = UserShoppingCartDAO.GetCartOfUser(uID);
List<Item> itms = new List<Item>();
ItemList itemList = new ItemList();
decimal deliveryCharges = 0;
string deliveryChargesStr = "";
decimal postagePackingCost = 0;
decimal examPaperPrice = 0;
int quantityOfExamPapers = 0;
decimal subtotal = 0;
decimal total = 0;
var transactionDetails = new Details();
var transactionAmount = new Amount();
Transaction tran = new Transaction();
for (int iCounter = 0; iCounter < scList.Count; iCounter++)
{
Product p = Product.getProduct(scList[iCounter].ProductID.ToString());
deliveryCharges = p.price * 0.05m;
deliveryChargesStr = deliveryCharges.ToString();
postagePackingCost = 10m;
examPaperPrice = p.price;
quantityOfExamPapers = scList[iCounter].ProductQuantity;
subtotal = (quantityOfExamPapers * examPaperPrice);
total = subtotal + postagePackingCost;
var examPaperItem = new Item();
examPaperItem.name = p.productName;
examPaperItem.currency = "SGD";
examPaperItem.price = total.ToString();
examPaperItem.sku = p.productID.ToString();
examPaperItem.description = p.productDesc;
examPaperItem.quantity = quantityOfExamPapers.ToString();
itms.Add(examPaperItem);
itemList.items = itms;
// var transactionDetails = new Detail
transactionDetails.tax = "0";
if (transactionDetails.shipping == null)
{
transactionDetails.shipping = postagePackingCost.ToString();
}
else
{
decimal total2 = decimal.Parse(transactionDetails.shipping) + postagePackingCost;
transactionDetails.shipping = total2.ToString();
}
if (transactionDetails.subtotal == null)
{
transactionDetails.subtotal = subtotal.ToString();
}
else
{
decimal total2 = decimal.Parse(transactionDetails.subtotal) + subtotal;
transactionDetails.subtotal = total2.ToString();
}
//transactionDetails.shipping = postagePackingCost.ToString();
//transactionDetails.subtotal = subtotal.ToString("0.00");
// var transactionAmount = new Amount();
transactionAmount.currency = "SGD";
if (transactionAmount.total == null)
{
transactionAmount.total = total.ToString();
}
else
{
decimal total2 = decimal.Parse(transactionAmount.total) + total;
transactionAmount.total = total2.ToString();
}
transactionAmount.details = transactionDetails;
// Transaction tran = new Transaction();
tran.description = scList[0].ProductDescription;
tran.invoice_number = Guid.NewGuid().ToString();
tran.amount = transactionAmount;
// transaction.item_list = new List<Item>();
tran.item_list = itemList;
transactionList.Add(tran);
}
transactionList.Remove(transactionList[1]);
//Authenticate with paypal
var config = ConfigManager.Instance.GetProperties();
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
//Get APIContent Object
var apiContext = new APIContext(accessToken);
var payer = new Payer();
payer.payment_method = "paypal";
var redirectUrls = new RedirectUrls();
redirectUrls.cancel_url = "http://localhost60681/Cancel.aspx";
redirectUrls.return_url = "http://localhost:60681/CompletePurchase.aspx";
var payment = Payment.Create(apiContext, new Payment
{
intent = "sale",
payer = payer,
transactions = transactionList,
redirect_urls = redirectUrls
});
Session["paymentId"] = payment.id;
foreach (var link in payment.links)
{
if (link.rel.ToLower().Trim().Equals("approval_url"))
{
Response.Redirect(link.href);
}
}
I get this exception when button_click method is over.
The problem is that in this part of code i do not have any string format or something like this.
I can't understand why this is happening.
The button is in a popup form in a detail grid. The weird thing is that the record is update just fine.
Below is my code.
protected void ASPxButton3_Click(object sender, EventArgs e)
{
try
{
DateTime birth = DateTime.Now.AddMonths(Convert.ToInt32(MONTH.Text));
birth = birth.AddYears(-Convert.ToInt32(YEAR.Text));
int key = 0;
Prsnout_RootObject prsn = new Prsnout_RootObject();
prsn.data = new PrsnData();
prsn.data.PRSNOUT = new List<PRSNOUT>();
prsn.data.PRSEXTRA = new List<PRSEXTRA>();
prsn.data.PRSOUTEXTRA = new List<PRSOUTEXTRA>();
if ((Session["newrecord"] != null))
{
if (!(Boolean)(Session["newrecord"]))
key = Convert.ToInt32(Session["KEYROWPRSN"].ToString().Split(';')[1]);
}
prsn.data.PRSNOUT.Add(new PRSNOUT
{
CODE = (key == 0 ? "*" : null),
NAME = ASPxTextBox4.Text,
NAME2 = ASPxTextBox4.Text,
CCCZOOSEX = Convert.ToInt32(ASPxComboBox1.Value),
CCCRATSA = Convert.ToInt32(CCCRATSA.Value),
CCCANIMAL = Convert.ToInt32(CCCANIMAL.Value),
UPDDATE = (((DateTime)DateTime.Now).ToString("yyyy-MM-dd HH:mm")),
BIRTHDATE = (((DateTime)birth).ToString("yyyy-MM-dd")),
CCCCHARACTER = Convert.ToInt32(CHARACTER.Value),
CCCORIGIN = country.Text,
CCCBREEDER = EKTROFEAS.Text,
CCCFOOD = EIDDIATR.Text,
CCCCHARACTERISTICS = IDIAITCHAR.Text,
CCCBLOOD = Convert.ToInt32(AIMA.Value),
CCCHISTORY = PAST.Text,
}
);
double kj = Convert.ToDouble(WEIGHT.Text);
prsn.data.PRSOUTEXTRA.Add(new PRSOUTEXTRA
{
BOOL01 = Convert.ToInt32(CROSS.Checked),
VARCHAR05 = MICROCHIP.Text,
NUM01 = WEIGHT.Text != "" ? WEIGHT.Text.ToString().Replace(",", ".") : "", //!= null ? int.Parse(WEIGHT.Text) : 0.0,
CCCHM = (Convert.ToInt32(DIATROFI.Items.FindByValue("1").Selected)).ToString(),
CCCDF = (Convert.ToInt32(DIATROFI.Items.FindByValue("2").Selected)).ToString(),
CCCCF = (Convert.ToInt32(DIATROFI.Items.FindByValue("3").Selected)).ToString(),
UTBL03 = Convert.ToInt32(Session["D"]),
UTBL04 = Convert.ToInt32(Session["U"]),
UTBL05 = Convert.ToInt32(Session["DV"]),
CCCCOLOUR1 = Convert.ToInt32(COLOUR.Items.FindByValue("GREY").Selected),
CCCCOLOUR2 = Convert.ToInt32(COLOUR.Items.FindByValue("RED").Selected),
CCCCOLOUR3 = Convert.ToInt32(COLOUR.Items.FindByValue("BROWN").Selected),
CCCCOLOUR4 = Convert.ToInt32(COLOUR.Items.FindByValue("WHITE").Selected),
CCCCOLOUR5 = Convert.ToInt32(COLOUR.Items.FindByValue("BLACK").Selected),
CCCCOLOUR6 = Convert.ToInt32(COLOUR.Items.FindByValue("MEL").Selected),
CCCCOLOUR7 = Convert.ToInt32(COLOUR.Items.FindByValue("BEZ").Selected),
CCCCOLOUR8 = Convert.ToInt32(COLOUR.Items.FindByValue("BLONDE").Selected),
CCCCOLOUR9 = Convert.ToInt32(COLOUR.Items.FindByValue("TIGER").Selected),
CCCCOLOUR10 = Convert.ToInt32(COLOUR.Items.FindByValue("APAL").Selected),
CCCCOLOUR11 = Convert.ToInt32(COLOUR.Items.FindByValue("PAL").Selected),
CCCCOLOUR12 = Convert.ToInt32(COLOUR.Items.FindByValue("STR").Selected),
CCCCOLOUR13 = Convert.ToInt32(COLOUR.Items.FindByValue("ISAV").Selected),
CCCCOLOUR14 = Convert.ToInt32(COLOUR.Items.FindByValue("ORED").Selected),
CCCCOLOUR15 = Convert.ToInt32(COLOUR.Items.FindByValue("ORMEL").Selected),
CCCCOLOUR16 = Convert.ToInt32(COLOUR.Items.FindByValue("ORF").Selected),
CCCCOLOUR17 = Convert.ToInt32(COLOUR.Items.FindByValue("IRON").Selected),
CCCCOLOUR18 = Convert.ToInt32(COLOUR.Items.FindByValue("RACE").Selected),
CCCCOLOUR19 = Convert.ToInt32(COLOUR.Items.FindByValue("FAIO").Selected),
CCCCOLOUR20 = Convert.ToInt32(COLOUR.Items.FindByValue("VWHITE").Selected)
}
);
string kkk = (Convert.ToInt32(COLOUR.Items.FindByValue("GREY").Selected)).ToString();
Def.result r = (Def.result)ws.SetData(ResultLogin, "setdata", "PRSNOUT", "Κτηνιατρείο(2)(2)", key, prsn.data);
if (ws.Error != null)
{
POST.HeaderText = "Error";
ASPxLabel2.Text = ws.Error;
}
else
{
POST.HeaderText = "";
ASPxLabel2.Text = "H καταχώρηση ολοκληρώθηκε.";
ASPxPopupControl1.ShowOnPageLoad = false;
}
}
catch (Exception ee)
{
POST.HeaderText = "Error";
ASPxLabel2.Text = ee.Message;
}
ASPxPopupControl1.ShowOnPageLoad = false;
POST.ShowOnPageLoad = true;
Session.Add("newrecord", false);
}
I am able to successfully create an invoice, and a payment, but don't seem to be able to properly link the payment to the invoice. I have tried several variations, but it either does not link at all, or I get a "Business Validation Error: Unexpected Internal Error." error in my error logs. Below is my c# code. Is there a simplified way (example) of linking a payment to an invoice?
Invoice i = QBGet_InvoiceByMDVInvoiceNum(MDVInvoiceNum);
Payment p = new Payment();
Customer customer = QBGet_CustomerByName(ClientName, "CompanyName");
Account acc = QBGet_AccountsReceivableAccount();
p.TxnDate = DateTime.Now;
p.TxnDateSpecified = true;
List<Line> lineList1 = new List<Line>();
Line pmtLine = new Line();
pmtLine.Amount = ReceivedPaymentAmt;
pmtLine.AmountSpecified = true;
List<LinkedTxn> linkedTxnList = new List<LinkedTxn>();
LinkedTxn linkedtxn = new LinkedTxn();
linkedtxn.TxnId = i.Id;
linkedtxn.TxnType = "invoice";
linkedTxnList.Add(linkedtxn);
pmtLine.LinkedTxn = linkedTxnList.ToArray();
//p.LinkedTxn = linkedTxnList.ToArray();
lineList1.Add(pmtLine);
p.Line = lineList1.ToArray();
p.CustomerRef = new ReferenceType()
{
Value = customer.Id
};
p.DepositToAccountRef = new ReferenceType() { Value = acc.Id };
p.PaymentRefNum = ReceiptCheckNo;
p.TotalAmt = ReceivedPaymentAmt;
p.TotalAmtSpecified = true;
DataService service = new DataService(context);
var result = service.Add<Payment>(p);
I have also tried this approach:
p.CustomerRef = new ReferenceType()
{
Value = customer.Id
};
p.PrivateNote ="ReferralID: " + ReferralId + "\r\n" + "PaymentDetailID: " + PaymentDetailID + "\r\n" + Comments;
p.PaymentRefNum = ReceiptCheckNo;
p.PaymentType = PaymentTypeEnum.Check;
p.PaymentTypeSpecified = true;
p.DocNumber = MDVInvoiceNum;
p.TotalAmt = ReceivedPaymentAmt;
p.TotalAmtSpecified = true;
p.TxnDate = PaymentReceivedDate;
p.TxnDateSpecified = true;
LinkedTxn[] lt = {new LinkedTxn()
{
TxnId=i.Id,
TxnType="invoice"
}
};
Line l = new Line()
{
Amount = ReceivedPaymentAmt,
LinkedTxn = lt
};
Line[] aryL = {l};
DataService service = new DataService(context);
Payment pmt = service.Add(p);
p.Line = aryL;
p.LinkedTxn = lt;
Payment pmt2 = service.Update(p);
Sharing the Java code and corresponding working JSON payload. It might help.
private void paymentAgainstInvoice() {
Payment payment = new Payment();
Date currentDateTime = null;
try {
currentDateTime = DateUtils.getCurrentDateTime();
} catch (ParseException e) {
e.printStackTrace();
}
payment.setTxnDate(currentDateTime);
Line line = new Line();
line.setAmount(new BigDecimal("100"));
LinkedTxn linkedTxn = new LinkedTxn();
linkedTxn.setTxnId("248");
linkedTxn.setTxnType("Invoice");
List<LinkedTxn> linkedTxnList = new ArrayList<LinkedTxn>();
linkedTxnList.add(linkedTxn);
line.setLinkedTxn(linkedTxnList);
List<Line> lineList = new ArrayList<Line>();
lineList.add(line);
payment.setLine(lineList);
ReferenceType custReferenceType = new ReferenceType();
custReferenceType.setValue("29");
custReferenceType.setName("ABC");
payment.setCustomerRef(custReferenceType);
payment.setTotalAmt(new BigDecimal("100"));
ReferenceType accountRefType = new ReferenceType();
accountRefType.setValue("63");
payment.setPaymentRefNum("ABC-100-Invoice");
payment.setDepositToAccountRef(accountRefType );
try {
this.service.add(payment);
} catch (FMSException e) {
e.printStackTrace();
}
}
JSON payload ( Payment )
{
"CustomerRef":{
"value":"29",
"name":"ABC"
},
"DepositToAccountRef":{
"value":"63"
},
"PaymentRefNum":"ABC-100-Invoice",
"TotalAmt":100,
"TxnDate":"2014-11-30",
"Line":[
{
"Amount":100,
"LinkedTxn":[
{
"TxnId":"248",
"TxnType":"Invoice"
}
]
}
]
}