我通過PHP做如下要求ChargeBee的API: -
ChargeBee_Environment::configure("chargebee-test","test_uybGuyguyguykynkgYgkfvyt");
$all = ChargeBee_Invoice::all(array(
"customer_id" => 2uyg23inuy2g3ou,
"limit" => 5,
"status[is]" => "paid",
"total[lte]" => 1000,
"sortBy[asc]" => "date"));
foreach($all as $entry){
$invoice = $entry->invoice();
echo'<pre>';
print_r($invoice);
echo'</pre>';
}
到$entry->invoice()
每個調用返回具有以下結構的對象:
ChargeBee_Invoice Object
(
[allowed:protected] => Array
(
[0] => id
[1] => poNumber
[2] => customerId
[3] => subscriptionId
)
[_values:protected] => Array
(
[id] => 4
[customer_id] => 2uyg23inuy2g3ou
[subscription_id] => 2uyg23inuy2g3ou
[line_items] => Array
(
[0] => Array
(
[id] => li_2uyg23inuy2g3ou
[date_from] => 1484106779
)
)
[sub_total] => 200
[linked_payments] => Array
(
[0] => Array
(
[txn_id] => txn_2uyg23inuy2g3ou
[applied_amount] => 200
[applied_at] => 1484106781
[txn_status] => success
[txn_date] => 1484106781
[txn_amount] => 200
)
)
[_subTypes:protected] => Array
(
[line_items] => ChargeBee_InvoiceLineItem
[discounts] => ChargeBee_InvoiceDiscount
[taxes] => ChargeBee_InvoiceTax
)
)
(我減少了上面的數據量,因爲返回的請求在這裏顯示的時間很長)
這是我陷入困境的地方,我如何能夠extrac來自對象的數據?
我已經嘗試以下操作: -
foreach($all as $entry){
$invoice = $entry->invoice();
echo'<pre>';
print_r($invoice->allowed);
echo'</pre>';
}
foreach($all as $entry){
$invoice = $entry->invoice();
echo'<pre>';
print_r($invoice->allowed());
echo'</pre>';
}
foreach($all as $entry){
$invoice = $entry->invoice();
echo'<pre>';
print_r($invoice->ChargeBee_Invoice);
echo'</pre>';
}
foreach($all as $entry){
$invoice = $entry->invoice();
echo'<pre>';
print_r($invoice->ChargeBee_Invoice());
echo'</pre>';
}
foreach($all as $entry){
$invoice = $entry->invoice();
echo'<pre>';
print_r($invoice['ChargeBee_Invoice']);
echo'</pre>';
}
foreach($all as $entry){
$invoice = $entry->invoice();
echo'<pre>';
print_r($invoice['allowed']);
echo'</pre>';
}
我也試圖用下面的代碼上面的許多變化: -
foreach($all as $entry){
$invoice = $entry->invoice();
foreach($invoice as $cinvoice) {
echo'<pre>';
print_r($cinvoice->allowed);
echo'</pre>';
}
}
但一切我嘗試剛剛返回: -
Fatal error: Uncaught exception 'Exception' with message 'Unknown property
任何幫助或推動正確的方向將非常讚賞
'_GET'(一個下劃線)不是一個魔術方法,它只是爲類'Result'(而不是類發票,他想查詢)的私有方法。儘管如此,文檔中有關公共屬性的一點也不錯。 – yivi
哦... ChargeBee_Result並鏈接到它 - 這是我不幸的誤印。我的意思是ChargeBee_Model。這個類是ChargeBee_Invoice的父類。而我用魔術方法__get(兩個下劃線)訪問數據的說法並沒有錯。查看源代碼。 – Ans