duanchi0897 2014-05-22 14:37
浏览 33
已采纳

QuickBooks PHP API添加付款错误

I'm trying to update a QB invoice with a payment using the PHP API by Keith Palmer. What I'm doing is:

1) Grab the invoice information (See code bellow)

2) Add a payment

Following this code example:

https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_payment_add.php

I've created this:

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...?';
    }
}

What I've noticed, when getting the invoice info is, all numbers are negatives, and if I assigned them to variable they are {-123}. My response is always:

2030: [Invalid ID, Id should be a valid number. Supplied value:{-10643}]

I imagine I'm setting something wrong somewhere. Would someone care to explain what I'm doing wrong please? Thanks!

UPDATE:

Request:

    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>

Response:

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>
  • 写回答

1条回答 默认 最新

  • dongmu7335 2014-05-22 19:48
    关注

    This highlights your problem here:

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

    You're not setting a valid Id value for the transaction for some reason.

    This is probably because of one of two reasons:

    • You're just not setting a valid TxnId in your code somewhere (if you print out print($Invoice->getId()); what do you see?)

    OR

    • You're using an outdated version of the code from GitHub, which had a but related to this in it (make sure you're using the very latest code from GitHub, as of today)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作