1

我正在尝试使用 IPP 将银行帐户添加到 QuickBooks Online。我的代码失败并说该帐户无效。这是我的代码:

            Account account = new Account();
            account.Desc = "Desc";
            account.Name = "Checking2";
            account.Type = AccountTypeEnum.Revenue;
            account.TypeSpecified = true;
            account.Subtype = AccountSubtypeEnum.Bank.ToString();
            dataServices.Add(account);

我需要添加字段吗?我还收到存在同名帐户的错误,但是,我没有看到它。

我的日志中没有看到任何 XML:

            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, ConfigurationManager.AppSettings["consumerKey"].ToString(), ConfigurationManager.AppSettings["consumerSecret"].ToString());
        ServiceContext context = new ServiceContext(oauthValidator, accessToken, companyID, IntuitServicesType.QBO);
        context.EnableServiceRequestsLogging = true;
        context.IdsLogger = new MyCustomLogger();
        dataServices = new DataServices(context);
        return "OK";


public class MyCustomLogger : ILogger
{
public MyCustomLogger()
{
}

public string ClearLog()
{
    try
    {
        string path = HttpContext.Current.Server.MapPath("/qblog.txt");

        if (File.Exists(path))
        {
            File.Delete(path);
        }

        return "OK";

    }
    catch (Exception ex)
    {
        return ex.ToString();
    }
}

public void Log(TraceLevel idsTraceLevel, string messageToWrite)
{
    string level = idsTraceLevel.ToString();
    WriteToLog(new ErrorMessage(MessageSeverity.Error, "QBFS", messageToWrite));
}

public string WriteToLog(ErrorMessage message)
{
    if (!String.IsNullOrEmpty(message.Message))
    {
        string path = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/qblog.txt");
        FileStream fileStream = null;

        //If the file exists, then append it
        if (File.Exists(path))
        {
            fileStream = new FileStream(path, FileMode.Append);
        }
        else
        {
            fileStream = new FileStream(path, FileMode.OpenOrCreate);
        }
        StreamWriter sw = new StreamWriter(fileStream);
        try
        {
            sw.WriteLine(String.Format("{0} : {1} {2} {3}", message.ApplicationName, message.Severity, DateTime.Now, message.Message));
            return "OK";
        }
        //If there is an error, just do nothing. Don't stop.
        catch (Exception ex)
        {
            return ex.ToString();
        }
        finally
        {
            sw.Close();
            fileStream.Close();
        }

    }

    return "Message is null or empty";
}

}

这是我的 xml 请求:

<?xml version="1.0" encoding="utf-8"?><q1:Account xmlns="http://www.intuit.com/sb/cdm/qbo" xmlns:q1="http://www.intuit.com/sb/cdm/v2"><q1:Name>Checking</q1:Name><q1:Desc>Desc</q1:Desc><q1:Subtype>Bank</q1:Subtype></q1:Account>

这是我的回应:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><FaultInfo xmlns="http://www.intuit.com/sb/cdm/baseexceptionmodel/xsd"><Message>Another account is already using this name. Please use a different name.</Message><ErrorCode>BAD_REQUEST</ErrorCode><Cause>-11202</Cause></FaultInfo>
4

1 回答 1

1

我需要使用真实变量指定期初余额和当前余额:

            ac = new Account();
            ac.Desc = "Desc";
            ac.Name = "Testy";
            ac.Subtype = QboAccountDetailTypeEnum.Checking.ToString();
            ac.OpeningBalanceDate = DateTime.Now;
            ac.OpeningBalanceDateSpecified = true;
            ac.CurrentBalance = 0;
            ac.CurrentBalanceSpecified = true;
            dataServices.Add(ac);

我的子类型也不正确。我需要使用 QboAccountDetailTypeEnum。

于 2013-05-09T21:08:25.370 回答