QuickBooks PHP API添加付款错误

QuickBooks PHP API添加付款错误,php,quickbooks,quickbooks-online,Php,Quickbooks,Quickbooks Online,我正在尝试使用Keith Palmer的PHP API更新QB发票和付款。我正在做的是: 1) 抓取发票信息(参见下面的代码) 2) 追加付款 以下代码示例: 我创造了这个: function updateQBInvoice($invoiceNumber = null, $depositAmount = null) { $this->autoRender = false; Configure::write('debug', 2); include(APP."we

我正在尝试使用Keith Palmer的PHP API更新QB发票和付款。我正在做的是:

1) 抓取发票信息(参见下面的代码)

2) 追加付款

以下代码示例:

我创造了这个:

function updateQBInvoice($invoiceNumber = null, $depositAmount = null) {
    $this->autoRender = false;
    Configure::write('debug', 2);

    include(APP."webroot".DS."quickbooks-php".DS."docs".DS."example_app_ipp_v3".DS."config.php");
    $IPP = new QuickBooks_IPP($dsn);
    $creds = $IntuitAnywhere->load($the_username, $the_tenant);
    $IPP->authMode(QuickBooks_IPP::AUTHMODE_OAUTH, $the_username, $creds);  
    $realm = $creds['qb_realm'];

    if ($Context = $IPP->context()) {
        $IPP->version(QuickBooks_IPP_IDS::VERSION_3);
        $InvoiceService = new QuickBooks_IPP_Service_Invoice();
        $invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE DocNumber='".$invoiceNumber."'");
        $Invoice = $invoices[0];

        $docNumber = $Invoice->getDocNumber();
        $CustomerRef = $Invoice->getCustomerRef();
        $invoiceId = $Invoice->getId();

        $PaymentService = new QuickBooks_IPP_Service_Payment();

        $Payment = new QuickBooks_IPP_Object_Payment();
        $Payment->setPaymentRefNum($invoiceNumber);
        $Payment->setTxnDate(date('Y-m-d'));
        $Payment->setTotalAmt($depositAmount);

        $Line = new QuickBooks_IPP_Object_Line();
        $Line->setAmount($depositAmount);

        $LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
        $LinkedTxn->setTxnId($invoiceId);
        $LinkedTxn->setTxnType('Invoice');

        $Line->setLinkedTxn($LinkedTxn);

        $Payment->addLine($Line);

        $Payment->setCustomerRef($CustomerRef);

        debug($Payment);

        if ($resp = $PaymentService->add($Context, $realm, $Payment)) {
            print('Our new Payment ID is: [' . $resp . ']');
        } else {
            print($PaymentService->lastError());
        }

        debug('Request [' . $PaymentService->lastRequest() . ']');
        debug('Response [' . $PaymentService->lastResponse() . ']');                
    } else {
        echo 'Unable to load a context...?';
    }
}
我注意到,当获取发票信息时,所有的数字都是负数,如果我把它们赋给变量,它们就是{-123}。我的回答总是:

2030: [Invalid ID, Id should be a valid number. Supplied value:{-10643}]
我想我在什么地方搞错了。有人能解释一下我做错了什么吗?谢谢

更新:

请求:

    POST https://quickbooks.api.intuit.com/v3/company/210896252/payment HTTP/1.1
Content-Type: application/xml
Authorization: OAuth realm="", oauth_signature_method="HMAC-SHA1", oauth_signature="jxw2JuAGtvcg9ynRxXApi8VjcWk%3D",  oauth_nonce="uvJB5", oauth_timestamp="1400786567", oauth_token="xxx", oauth_consumer_key="xxx", oauth_version="1.0"
Content-Length: 414

<Payment xmlns="http://schema.intuit.com/finance/v3">
    <Line xmlns="http://schema.intuit.com/finance/v3">
        <Amount>45</Amount>
        <LinkedTxn xmlns="http://schema.intuit.com/finance/v3">
            <TxnId>{-10643}</TxnId>
            <TxnType>Invoice</TxnType>
        </LinkedTxn>
    </Line>
    <PaymentRefNum>2060</PaymentRefNum>
    <TxnDate>2014-05-22</TxnDate>
    <TotalAmt>45</TotalAmt>
    <CustomerRef>627</CustomerRef>
</Payment>
POSThttps://quickbooks.api.intuit.com/v3/company/210896252/payment HTTP/1.1
内容类型:application/xml
授权:OAuth realm=“”,OAuth_signature_method=“HMAC-SHA1”,OAuth_signature=“jxw2JuAGtvcg9ynRxXApi8VjcWk%3D”,OAuth_nonce=“uvJB5”,OAuth_timestamp=“1400786567”,OAuth_token=“xxx”,OAuth_consumer_key=“xxx”,OAuth_version=“1.0”
内容长度:414
45
{-10643}
发票联
2060
2014-05-22
45
627
答复:

HTTP/1.1 400 Bad Request
Date: Thu, 22 May 2014 19:22:47 GMT
Content-Type: application/xml
Content-Length: 278
intuit_tid: c53e5e81-fd5e-4a24-b511-cd6b3449d012
Via: 1.1 ipp-gateway-.net
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: close

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-05-22T12:22:47.834-07:00"><Fault type="ValidationFault"><Error code="2030" element="LinkedTxn.TxnId"><Message>Invalid ID</Message><Detail>Id should be a valid number. Supplied value:{-10643}</Detail></Error></Fault></IntuitResponse>
HTTP/1.1400错误请求
日期:2014年5月22日星期四19:22:47 GMT
内容类型:application/xml
内容长度:278
肠套叠:c53e5e81-fd5e-4a24-b511-cd6b3449d012
通过:1.1 ipp网关-.net
改变:接受编码
内容编码:gzip
连接:关闭
无效IDId应为有效数字。提供的值:{-10643}

这突出了您的问题:

<LinkedTxn xmlns="http://schema.intuit.com/finance/v3">
            <TxnId>0</TxnId>
            <TxnType>Invoice</TxnType>
        </LinkedTxn>

0
发票联
由于某些原因,您没有为事务设置有效的Id值

这可能是因为以下两个原因之一:

  • 您只是没有在代码的某个地方设置有效的TxnId(如果您打印出
    print($Invoice->getId());
    您看到了什么?)

  • 您使用的是来自GitHub的过时版本的代码,其中包含一个与此相关的版本(请确保您使用的是GitHub的最新代码,从今天开始)

发布$PaymentService->lastRequest()和$PaymentService->lastResponse()的输出,这样我们就可以真正看到您在做什么。@KeithPalmer ConsoleByte我已将响应和请求添加到原始邮件中。在浏览器中查看>源。您没有查看完整的请求/响应-您发布了一个非常截断的版本,这没有帮助。@KeithPalmer ConsoleByte我用正确的请求和响应信息更新了帖子。我用新代码更新了我的原始帖子,等等。至于打印($Invoice->getId());我得到的回应是:{-10643}。也许我把变量设置错了?我正在加载发票,收集信息,然后向发票中添加付款。根据这个例子,我需要设置setPaymentRefNum(INVOICE#?)、setTxnId(INVOICE#?)和其他变量。所有这些都在上面的代码中。我做得不对吗?您使用的是GitHub的最新版本吗?今天早上,针对这个问题推出了一个补丁。您有最新的代码吗?另外,这个值:{-10643}是正确的,如前所述。