c# - 未创建付款

标签 c# asp.net intuit-partner-platform

我的付款未显示在 QuickBooks 中。

我可以成功创建和更新客户。我还可以成功创建和更新发票。我无法创建付款。但事情是这样的,当我在我的付款对象上执行更新命令时,我确实得到了一个正确的 ID 和域 (NG) 传回。我在运行同步后检查了同步日志文件 (IntuitSyncManagerLogger.log),但没有错误消息。一切看起来都很好,只是没有与 QuickBooks 中的发票相关联的付款。

我相信我正在设置所有必填字段,但我不确定其中两个字段。

1) PaymentLine 有一个名为 TxnId 的字段。我将其设置为 InvoiceHeader 的 ID 和域,但不确定这是否正确。

2) 还有另一个必填字段(根据文档),但我将其留空,因为我不知道用什么填充它。它是 DiscountAccountId 字段。我不想要与发票相关的折扣。

这是我的代码...

SqlConnection connection = new SqlConnection(m_connectionString);
connection.Open();

SqlCommand cmd = new SqlCommand("dbo.Intuit_GetPayment", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@glmvSyncId", SqlDbType.Int).Value = glmvSyncId;

SqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();

Intuit.Ipp.Data.Qbd.PaymentHeader paymentHeader = new Intuit.Ipp.Data.Qbd.PaymentHeader();
paymentHeader.ARAccountId = new Intuit.Ipp.Data.Qbd.IdType() {
    idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.QB,
    Value = "37"
};
paymentHeader.ARAccountName = "Accounts Receivable";
paymentHeader.DepositToAccountId = new Intuit.Ipp.Data.Qbd.IdType() {
    idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.QB,
    Value = "35"
};
paymentHeader.DepositToAccountName = "Undeposited Funds";
paymentHeader.CustomerId = new Intuit.Ipp.Data.Qbd.IdType() {
    idDomain = (rdr["cust_iddomain"].ToString() == "QB" ? Intuit.Ipp.Data.Qbd.idDomainEnum.QB : Intuit.Ipp.Data.Qbd.idDomainEnum.NG),
    Value = rdr["cust_idvalue"].ToString()
}; // cust_iddomain and cust_idvalue are from the Customer
paymentHeader.DocNumber = rdr["invoicekey"].ToString();
paymentHeader.TxnDate = DateTime.Now; 

List<Intuit.Ipp.Data.Qbd.PaymentLine> listLine = new List<Intuit.Ipp.Data.Qbd.PaymentLine>();

var paymentLine = new Intuit.Ipp.Data.Qbd.PaymentLine();
paymentLine.Amount = Convert.ToDecimal(rdr["amount"]);
paymentLine.TxnId = new Intuit.Ipp.Data.Qbd.IdType() {
    idDomain = (rdr["invc_iddomain"].ToString() == "QB" ? Intuit.Ipp.Data.Qbd.idDomainEnum.QB : Intuit.Ipp.Data.Qbd.idDomainEnum.NG),
    Value = rdr["invc_idvalue"].ToString()
}; // invc_iddomain and invc_idvalue are from the InvoiceHeader

listLine.Add(paymentLine);

Intuit.Ipp.Data.Qbd.Payment syncPayment = new Intuit.Ipp.Data.Qbd.Payment();
syncPayment.Header = paymentHeader;
syncPayment.Line = listLine.ToArray();

connection.Close();

Intuit.Ipp.Data.Qbd.Payment resultPayment = new Intuit.Ipp.Data.Qbd.Payment();

resultPayment = commonService.Add(syncPayment);

我怀疑问题出在 TxnId 上。

我所做的就是创建客户,然后为客户创建发票,然后为发票创建付款。我是否在某处遗漏了某个对象?

非常感谢任何帮助。

最佳答案

同步后付款可能会进入错误状态。您可以通过执行 PaymentQuery 并设置 ErroredObjectsOnly=true 来进行检查。

https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0500_QuickBooks_Windows/0100_Calling_Data_Services/0015_Retrieving_Objects#Objects_in_Error_State

如果实体处于错误状态,您可以使用 Status API 查询具体原因:

https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0500_QuickBooks_Windows/0600_Object_Reference/SyncStatus

SyncStatusRequest syncStatusRequest = new SyncStatusRequest();
syncStatusRequest.ErroredObjectsOnly = true;
syncStatusRequest.NgIdSet = new NgIdSet[] { new NgIdSet { NgId = <<EnterYourNgIdHere>>, NgObjectType = objectName.Payment } };
SyncStatusResponse[] response = dataServices.GetSyncStatus(syncStatusRequest);

如果付款处于错误状态,您可以从云中删除该实体,因为它从未与 QuickBooks 同步过:

https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0500_QuickBooks_Windows/0100_Calling_Data_Services/Deleting_an_Object

如果至少一次与实体成功同步,但随后更新将其插入错误状态,您将需要执行恢复:

https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0500_QuickBooks_Windows/0100_Calling_Data_Services/Reverting_an_Object

一旦您从 Status API 知道原因,您也可以尝试直接对处于错误状态的实体执行更新,但它没有记录在案,因此它可能不起作用。

关于c# - 未创建付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14863355/

相关文章:

java - 使用 QBOVendorService 的 NPE

intuit-partner-platform - Quickbooks Online 连接到特定公司

javascript - 如何将 Repeater 中控件的 clientId 传递给 JavaScript 函数?

c# - 从 C# 发送 sql server 时间戳

c# - 为什么我不能将 String func(SomeEnum) 转换为 Func<Enum, String>?

c# - 两个可枚举之间的相等性

c# - 多张结果表的SqlCommand

c# - 如何找出动态创建的复选框是否被选中

c# - 从 C# 在 Quickbooks Online 中创建客户

c# - 带有 XML 文件的 Entity Framework