添加客户时出现 Quickbooks 错误

Quickbooks error while Add customer

7001:[message=公司订阅已失效或使用了无效目的地 URL。 Sandbox 公司与 Sandbox URL 合作,Production 公司与 Production URL 合作;错误码=007001;状态码=400,]

我在 运行 以下 url 时收到上述错误 http://localhost/quickbooks/docs/partner_platform/example_app_ipp_v3/example_customer_add.php

/**
 * Intuit Partner Platform configuration variables
 * 
 * See the scripts that use these variables for more details. 
 * 
 * @package QuickBooks
 * @subpackage Documentation
 */

// Turn on some error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Require the library code
require_once dirname(__FILE__) . '/../../../QuickBooks.php';

// Your OAuth token (Intuit will give you this when you register an Intuit Anywhere app)
$token = '95555248baf11b43fbb944ab97de9134ad85';

// Your OAuth consumer key and secret (Intuit will give you both of these when you register an Intuit app)
// 
// IMPORTANT:
//  To pass your tech review with Intuit, you'll have to AES encrypt these and 
//  store them somewhere safe. 
// 
// The OAuth request/access tokens will be encrypted and stored for you by the 
//  PHP DevKit IntuitAnywhere classes automatically. 
$oauth_consumer_key = 'qyprdfkqo3bikN2vLrLu4FWHv6GbQp';
$oauth_consumer_secret = 'WDH56afDb1jr0ismQZAwdPuq4oDqpTmrKXc0oORz';

// If you're using DEVELOPMENT TOKENS, you MUST USE SANDBOX MODE!!!  If you're in PRODUCTION, then DO NOT use sandbox.
$sandbox = true;     // When you're using development tokens
//$sandbox = false;    // When you're using production tokens

// This is the URL of your OAuth auth handler page
$quickbooks_oauth_url = 'http://localhost/quickbooks/docs/partner_platform/example_app_ipp_v3/oauth.php';

// This is the URL to forward the user to after they have connected to IPP/IDS via OAuth
$quickbooks_success_url = 'http://localhost/quickbooks/docs/partner_platform/example_app_ipp_v3/success.php';

// This is the menu URL script 
$quickbooks_menu_url = 'http://localhost/quickbooks/docs/partner_platform/example_app_ipp_v3/menu.php';

// This is a database connection string that will be used to store the OAuth credentials 
// $dsn = 'pgsql://username:password@hostname/database';
// $dsn = 'mysql://username:password@hostname/database';
$dsn = 'mysqli://root:@localhost/example_app_ipp_v3';       
//$dsn = 'mysqli://forthera_demo:Reset123@forthera.in/forthera_test';   
// You should set this to an encryption key specific to your app
$encryption_key = 'bcde1234';

// Do not change this unless you really know what you're doing!!!  99% of apps will not require a change to this.
$the_username = 'DO_NOT_CHANGE_ME';

// The tenant that user is accessing within your own app
$the_tenant = 12345;

// Initialize the database tables for storing OAuth information
if (!QuickBooks_Utilities::initialized($dsn))
{
    // Initialize creates the neccessary database schema for queueing up requests and logging
    QuickBooks_Utilities::initialize($dsn);
}

// Instantiate our Intuit Anywhere auth handler 
// 
// The parameters passed to the constructor are:
//  $dsn                    
//  $oauth_consumer_key     Intuit will give this to you when you create a new Intuit Anywhere application at AppCenter.Intuit.com
//  $oauth_consumer_secret  Intuit will give this to you too
//  $this_url               This is the full URL (e.g. http://path/to/this/file.php) of THIS SCRIPT
//  $that_url               After the user authenticates, they will be forwarded to this URL
// 
$IntuitAnywhere = new QuickBooks_IPP_IntuitAnywhere($dsn, $encryption_key, $oauth_consumer_key, $oauth_consumer_secret, $quickbooks_oauth_url, $quickbooks_success_url);

// Are they connected to QuickBooks right now? 
if ($IntuitAnywhere->check($the_username, $the_tenant) and 
    $IntuitAnywhere->test($the_username, $the_tenant))
{
    // Yes, they are 
    $quickbooks_is_connected = true;

    // Set up the IPP instance
    $IPP = new QuickBooks_IPP($dsn);

    // Get our OAuth credentials from the database
    $creds = $IntuitAnywhere->load($the_username, $the_tenant);

    // Tell the framework to load some data from the OAuth store
    $IPP->authMode(
        QuickBooks_IPP::AUTHMODE_OAUTH, 
        $the_username, 
        $creds);

    if ($sandbox)
    {
        // Turn on sandbox mode/URLs 
        $IPP->sandbox(true);
    }

    // Print the credentials we're using
    //print_r($creds);

    // This is our current realm
    $realm = $creds['qb_realm'];

    // Load the OAuth information from the database
    $Context = $IPP->context();

    // Get some company info
    $CompanyInfoService = new QuickBooks_IPP_Service_CompanyInfo();
    $quickbooks_CompanyInfo = $CompanyInfoService->get($Context, $realm);
}
else
{
    // No, they are not
    $quickbooks_is_connected = false;
}

这是我的 config.php 文件,我在其中更改了令牌和密钥。

我的example_customer_add.php文件

<?php

require_once dirname(__FILE__) . '/config.php';

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

?>

<pre>

<?php

// Set up the IPP instance
$IPP = new QuickBooks_IPP($dsn);

// Get our OAuth credentials from the database
$creds = $IntuitAnywhere->load($the_username, $the_tenant);
// Tell the framework to load some data from the OAuth store
$IPP->authMode(
    QuickBooks_IPP::AUTHMODE_OAUTH, 
    $the_username, 
    $creds);

// Print the credentials we're using
//print_r($creds);

// This is our current realm
$realm = $creds['qb_realm']; 
// Load the OAuth information from the database
if ($Context = $IPP->context())
{ 
   // print_r($Context);
    $IPP->version(QuickBooks_IPP_IDS::VERSION_3);

    $CustomerService = new QuickBooks_IPP_Service_Customer();
    print($CustomerService->lastRequest($Context));
        print($CustomerService->lastResponse($Context));exit;
    $Customer = new QuickBooks_IPP_Object_Customer();
    $Customer->setTitle('Ms');
    $Customer->setGivenName('Sandeep');
    $Customer->setMiddleName('D');
    $Customer->setFamilyName('Reddy');
    $Customer->setDisplayName('Sandeep D Reddy' . 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();
    $PrimaryEmailAddr->setAddress('support@consolibyte.com');
    $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));
    }

    /*
    print('<br><br><br><br>');
    print("\n\n\n\n\n\n\n\n");
    print('Request [' . $IPP->lastRequest() . ']');
    print("\n\n\n\n");
    print('Response [' . $IPP->lastResponse() . ']');
    print("\n\n\n\n\n\n\n\n\n");
    */
}
else
{
    die('Unable to load a context...?');
}


?>

</pre>

<?php

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

当我尝试 print_r($Context) 时,我得到了以下输出。

QuickBooks_IPP Object
(
    [_test:protected] => 
    [_key:protected] => 
    [_username:protected] => 
    [_password:protected] => 
    [_ticket:protected] => 
    [_token:protected] => 
    [_dbid:protected] => 
    [_flavor:protected] => 
    [_baseurl:protected] => 
    [_sandbox:protected] => 
    [_authmode:protected] => oauth
    [_authuser:protected] => DO_NOT_CHANGE_ME
    [_authcred:protected] => Array
        (
            [quickbooks_oauth_id] => 1
            [app_username] => DO_NOT_CHANGE_ME
            [app_tenant] => 12345
            [oauth_request_token] => qyprdWOXU3PLf73TRCi9HijjtCcNJSI4TUukCeOc0vlHJ01k
            [oauth_request_token_secret] => R46vV6bolaZ13p6xcpsXS5eCVdRk77MNbPYLI3xB
            [oauth_access_token] => qyprdkY9wV2nKB8CsITcV2r0A69dMmHtyHM56260NM9vh7Jx
            [oauth_access_token_secret] => i7NldF676khb8YWK31WjsJRbQagT4AH0f7EXFqpR
            [qb_realm] => 396652311
            [qb_flavor] => QBO
            [qb_user] => 
            [request_datetime] => 2015-03-12 13:20:42
            [access_datetime] => 2015-03-12 13:21:24
            [touch_datetime] => 2015-03-13 05:51:55
            [oauth_consumer_key] => qyprdOMSkgvrLqR3PmV3yXMWsufQaB
            [oauth_consumer_secret] => SoVpK5TGyFE0vVG3FtHFibUTiUuLwYTn64X2LfJg
        )

    [_authsign:protected] => 
    [_authkey:protected] => 
    [_debug:protected] => 
    [_last_request:protected] => 
    [_last_response:protected] => 
    [_last_debug:protected] => Array
        (
        )

    [_masking:protected] => 1
    [_driver:protected] => QuickBooks_Driver_SQL_Mysqli Object
        (
            [_conn:protected] => mysqli Object
                (
                    [affected_rows] => 1
                    [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $
                    [client_version] => 50011
                    [connect_errno] => 0
                    [connect_error] => 
                    [errno] => 0
                    [error] => 
                    [error_list] => Array
                        (
                        )

                    [field_count] => 0
                    [host_info] => localhost via TCP/IP
                    [info] => Rows matched: 1  Changed: 1  Warnings: 0
                    [insert_id] => 0
                    [server_info] => 5.6.16
                    [server_version] => 50616
                    [stat] => Uptime: 1402  Threads: 3  Questions: 53  Slow queries: 0  Opens: 71  Flush tables: 1  Open tables: 64  Queries per second avg: 0.037
                    [sqlstate] => 00000
                    [protocol_version] => 10
                    [thread_id] => 7
                    [warning_count] => 0
                )

            [_res:protected] => 
            [_log_level:protected] => 1
            [_last_error] => 
            [_hooks:protected] => Array
                (
                )

            [_dbname:protected] => /example_app_ipp_v3
            [_max_log_history:protected] => -1
            [_max_queue_history:protected] => -1
            [_max_ticket_history:protected] => -1
            [_loglevel:protected] => 1
        )

    [_certificate:protected] => 
    [_errcode:protected] => 0
    [_errtext:protected] => 
    [_errdetail:protected] => 
    [_cookies:protected] => Array
        (
        )

    [_ids_parser:protected] => 1
    [_ids_version:protected] => v3
)
7001: [message=Subscription for company has lapsed or Invalid destination URL is used. Sandbox company works with Sandbox URL and Production company works with Production URL.; errorCode=007001; statusCode=400, ]

错误的意思:

如果您从开发应用向在线公司发送数据,或者从在线应用向沙盒公司发送数据,通常会出现此错误。

您在使用开发令牌吗?如果是这样,请确保您将数据发送到 development/sandbox URL(https://sandbox-quickbooks.api.intuit.com/v3 用于 dev/sandbox vs https://quickbooks.api.intuit.com/v3 用于实时)

如果您使用此代码:

然后你可以强制库使用沙盒URL通过设置这个:

$IPP->sandbox(true);

进一步故障排除:

如果之后问题仍然存在,您需要 post 一些调试输出,以便我们可以进一步帮助您。

要做到这一点,请在您的服务实例上调用 ->lastRequest()->lastResponse() 方法,以便将原始 XML 发送到 QuickBooks,然后得到原始 XML从 QuickBooks 回来。例如:

print($CustomerService->lastRequest($Context));
print($CustomerService->lastResponse($Context));

Post 在此处(或在该库的支持论坛上:http://www.consolibyte.com/forum/),我们可以进一步帮助您。

我已经从 https://github.com/consolibyte/quickbooks-php 下载了最新版本,现在对我来说工作正常。

特别感谢 Keith Palmer- Consolibyte 的巨大努力。