今天,我尝试将开发代码切换到限量发布的生产环境,并立即遇到问题。
QuickBooks Accounting API工作正常,但是当涉及到付款我能够在沙箱模式下接受它们但是生产返回“400 Bad Request”
我正在使用我的生产API密钥,我正在访问生产API端点(api.intuit.com而不是sandbox.api.intuit.com),我知道我发送的查询应该没问题因为它在沙箱模式下工作(请求正文中提供唯一的Request-Id,金额,令牌和货币,适当的内容类型标题等)
我也知道我的API密钥很好,因为它适用于QuickBooks Accounting API。我可以创建一个客户并创建一个发票,但是当我尝试在发票上收款时,它会引发我的注意。
可能出现什么问题?我可以发布任何代码片段或所需的错误。我正在使用Laravel 5.2和lusitanian编写的phpOauthLib包装器。
我正在使用的代码:
$oauth = OAuth::consumer('QuickBooks');
$oauth_token = unserialize(file_get_contents(storage_path("tokens/oauth.token")));
$storage = $oauth->getStorage();
$storage->storeAccessToken('QuickBooks', $oauth_token['access_token']);
$member = Member::find(Request::get('id'));
$query = urlencode("select * from customer where displayname = '" . $member->first_name . " " . $member->last_name . "'");
$result = json_decode($oauth->request("/v3/company/" . $oauth_token['company_id'] . "/query?query=" . $query, "GET"));
$donor = null;
if( !property_exists( $result->QueryResponse, 'Customer' ) ) {
$donor = $oauth->request("/v3/company/" . $oauth_token['company_id'] . "/customer", "POST", json_encode([
'DisplayName' => $member->first_name . " " . $member->last_name
]), array('Content-Type' => 'application/json'));
} else {
$donor = $result->QueryResponse->Customer[0];
}
$pledge = $oauth->request("/v3/company/" . $oauth_token['company_id'] . "/invoice", "POST", json_encode([
'Line' => [
[
'Amount' => '25.00',
'DetailType' => 'SalesItemLineDetail',
'SalesItemLineDetail' => [
'ItemRef' => [
'value' => '21'
]
]
]
],
'CustomerRef' => [
'value' => $donor->Id
]
]), array('Content-Type' => 'application/json'));
$pledge = json_decode( $pledge )->Invoice;
$guid = GUID();
/************** THIS IS THE LINE THAT FAILS: ***************/
$capture = $oauth->request("https://api.intuit.com/quickbooks/v4/payments/charges", "POST", json_encode([
'amount' => $amount,
'token' => Request::get('token'),
'currency' => "USD"
]), ['Content-Type' => 'application/json', 'Request-Id' => $guid]);
$capture = json_decode( $capture );
$payment = $oauth->request("/v3/company/" . $oauth_token['company_id'] . "/payment", "POST", json_encode([
'CustomerRef' => [
'value' => $donor->Id,
'name' => $donor->DisplayName
],
'TotalAmt' => $capture->amount,
'Line' => [
[
'Amount' => $capture->amount,
'LinkedTxn' => [
[
'TxnId' => $pledge->Id,
'TxnType' => 'Invoice'
]
]
]
]
]), ['Content-Type' => 'application/json']);
同样,此代码与沙盒API完美配合,但现在它失败了。今晚我将看到我能做些什么来获得HTTP事务(请求和响应)