我通过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
)
)(我已经减少了上面的数据量,因为返回的请求很难在这里显示)
这就是我陷入困境的地方,我如何能够从对象中提取数据?
我尝试了以下几点:
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发布于 2017-01-31 13:13:03
从文档中可以看到发票对象的公共属性。
例如,要访问它们,您只需:
echo "<pre>";
foreach($all as $entry){
$invoice = $entry->invoice();
echo "Invoice #{$invoice->customerId} for a total of {$invoice->amountDue} has status '{$invoice->status}'"\n;
}
echo "</pre>";测试它,并检查文档中的其他可用属性。
发布于 2017-01-31 14:59:34
https://stackoverflow.com/questions/41954733
复制相似问题