ChargeBee发票PHP API请求,访问$invoices
我通过PHP向ChargeBee的API发出以下请求:-ChargeBee发票PHP API请求,访问$invoices,php,api,oop,Php,Api,Oop,我通过PHP向ChargeBee的API发出以下请求:- ChargeBee_Environment::configure("chargebee-test","test_uybGuyguyguykynkgYgkfvyt"); $all = ChargeBee_Invoice::all(array( "customer_id" => 2uyg23inuy2g3ou, "limit" => 5, "status[is]" => "paid",
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>';
}
(我已经减少了上面的数据量,因为返回的请求在这里显示的时间太长了)
这就是我陷入困境的地方,我如何才能从对象中提取数据
我尝试了以下几点:-
foreach($all as $entry){
$invoice = $entry->invoice();
foreach($invoice as $cinvoice) {
echo'<pre>';
print_r($cinvoice->allowed);
echo'</pre>';
}
}
从中可以看到发票对象的公共属性
要访问它们,您只需执行以下操作,例如:
echo”“;
foreach($all as$entry){
$invoice=$entry->invoice();
echo“发票{$Invoice->customerId}的状态为“{$Invoice->status}”,总共{$Invoice->amountDue}的状态为“{$Invoice->status}”;
}
回声“;
测试它,并检查文档中的其他可用属性。您想直接访问受保护的属性。对ChargeBee_Invoice对象中数据的访问是通过魔术方法()实现的。可查看的可用属性列表。 此代码帮助您开始:
\u get
(一个下划线)不是一个神奇的方法,它只是类结果的私有方法(不是他想要查询的类发票)。文档中关于公共属性的部分还可以。哦。。。ChargeBee__结果和链接-这是我不幸的打印错误。我指的是ChargeBee_模型。此类是ChargeBee\u发票的父类。我关于通过magic方法(两个下划线)访问数据的陈述没有错。请参阅源代码。
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
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>";
<?php
foreach ($all as $entry)
{
/* Get next invoice */
$invoice = $entry->invoice();
/* Get properties from invoice */
echo $invoice->id;
echo $invoince->subscription_id;
/* And so on */
}
?>