使用QuickBooks PHP DevKit示例时出错

时间:2015-06-04 16:20:11

标签: php quickbooks intuit-partner-platform

我已成功设置Quickbooks PHP DevKit,但我目前正在尝试使用我的沙箱运行example_customer_add脚本。当我这样做时,我收到以下错误:

  

注意:未定义的变量:第54行的/Applications/MAMP/htdocs/quickbooks-php/test_qb.php中的上下文

我试图追踪$Context变量,但它在整个地方都被使用,我不确定它的设置位置等等......

任何帮助表示赞赏!谢谢!

编辑

我只是使用Quickbooks PHP DevKit的docs文件夹中包含的脚本:

<?php
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/views/header.tpl.php';
?>

<pre>

<?php

$CustomerService = new QuickBooks_IPP_Service_Customer();

$Customer = new QuickBooks_IPP_Object_Customer();
$Customer->setTitle('Ms');
$Customer->setGivenName('Shannon');
$Customer->setMiddleName('B');
$Customer->setFamilyName('Palmer');
$Customer->setDisplayName('Shannon B Palmer ' . mt_rand(0, 1000));

// Terms (e.g. Net 30, etc.)
$Customer->setSalesTermRef(4);

// Phone #
$PrimaryPhone = new QuickBooks_IPP_Object_PrimaryPhone();
$PrimaryPhone->setFreeFormNumber('860-532-0089');
$Customer->setPrimaryPhone($PrimaryPhone);

// Mobile #
$Mobile = new QuickBooks_IPP_Object_Mobile();
$Mobile->setFreeFormNumber('860-532-0089');
$Customer->setMobile($Mobile);

// Fax #
$Fax = new QuickBooks_IPP_Object_Fax();
$Fax->setFreeFormNumber('860-532-0089');
$Customer->setFax($Fax);

// Bill address
$BillAddr = new QuickBooks_IPP_Object_BillAddr();
$BillAddr->setLine1('72 E Blue Grass Road');
$BillAddr->setLine2('Suite D');
$BillAddr->setCity('Mt Pleasant');
$BillAddr->setCountrySubDivisionCode('MI');
$BillAddr->setPostalCode('48858');
$Customer->setBillAddr($BillAddr);

// Email
$PrimaryEmailAddr = new QuickBooks_IPP_Object_PrimaryEmailAddr();
$Customer->setPrimaryEmailAddr($PrimaryEmailAddr);

if ($resp = $CustomerService->add($Context, $realm, $Customer))
{
  print('Our new customer ID is: [' . $resp . '] (name "' . $Customer-    >getDisplayName() . '")');
}
else
{
  print($CustomerService->lastError($Context));
}


?>

</pre>
<?php
require_once dirname(__FILE__) . '/views/footer.tpl.php';

在尝试连接后,quickbooks_oauth表如下所示:

'1', 'DO_NOT_CHANGE_ME', '12345', 'qyprdaX1yo1uYqu3GU8xxPvs8raoTss2ZVRBE3fHWy7qZdAB', 'IWZHlW2e956sqR9GVIxa2JOU82NdSrJixZLpb3af', 'KNwiKE2bUXtqFqJ/Vb0NhjzBGYMXwRRcT9xtFOQiV6F8aEgUoqGzA7aheRLPJ/z6EPYy1ZS4e6ZuVpteBaQtxc5H0cN5VcCmWLfj+lryaCpLgw8mGK5+E/Muv2wJ+3UwbOyqVstU+pYQw/yNgFKhfSuA3lOgjgqctuO6ZpMK1wWr42IycA05QrJuOB4+LQ==', 'rCj1V3zl4Jj5mHgTw+BPCPN7SDcJkzLQPWb1tyerEXedsQB0WsZ+caMCBafS+hfN3ECZl3mfNDSyIqKDK+t8RSEAKyFWwRSPOh3UcWDCDEhXrTSUddmKhoIq6pL6yVtNEyETyNtfMaKYN+U6uIwSEMKZB/4IUjK8c0GP5KhoKSl0dv+Bp9w=', '1391140255', 'QBO', NULL, '2015-06-04 19:57:58', '2015-06-04 19:58:36', '2015-06-04 19:58:36'

1 个答案:

答案 0 :(得分:1)

您发布的代码在脚本顶部缺少几行。看看GitHub上的例子:

https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_customer_add.php#L3

您缺少两个require_once语句。 $Context在这些必需文件中定义。

require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/views/header.tpl.php';

修复您的代码,以便您完全使用示例代码,并确保实际包含所需的文件。

如果您仍然遇到问题,请发布更新的代码。

您可以在此处查看$Context的定义位置:

请注意,必须连接到QuickBooks才能运行示例。我假设你已经点击了#34;连接到QuickBooks&#34;按钮已经连接了......对吧?