使用 QuickBooks 时出错 PHP DevKit 示例

Error when using QuickBooks PHP DevKit examples

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

Notice: Undefined variable: Context in /Applications/MAMP/htdocs/quickbooks-php/test_qb.php on line 54

我试图找到 $Context 变量,但到处都在使用它,我不确定它在哪里设置等等...

感谢任何帮助!谢谢!

编辑

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

<?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 table 看起来像这样:

'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'

您 post 编写的代码在脚本顶部缺少几行。查看 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';

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

如果问题仍然存在,请post更新代码。

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

请注意,您必须连接到 QuickBooks 才能运行示例。我假设您已经点击了 "Connect to QuickBooks" 按钮并且已经连接...对吧?