2014-10-31 124 views
1

我正在尝试使用带有PHP的Stripe API检索我的条纹余额。条纹API余额

我打电话以下几点:

function retrieve_balance() 
{ 
    $response = Stripe_Balance::retrieve(); 

    return $response; 
} 

这将返回是这样的:

object(Stripe_Balance)#28 (5) { 
    ["_apiKey":protected]=> 
    string(32) "my_key_here" 
    ["_values":protected]=> 
    array(4) { 
    ["pending"]=> 
     array(1) { 
     [0]=> 
      object(Stripe_Object)#32 (5) { 
      ["_apiKey":protected]=> 
      string(32) "my_key_here" 
       ["_values":protected]=> 
       array(2) { 
       ["amount"]=> 
        int(0) 
       ["currency"]=> 
        string(3) "usd" 

       etc... 

我试着做以下,但它只能导致错误。我正在尝试获取待处理和可用的数量。

<?php 
    var_dump($balance); 
    /*Issue Line Below*/ 
    echo $balance->pending->amount; 
?> 

我得到的错误是:Trying to get property of non-object

+0

它看起来像挂起的是对象的数组,你有没有试过'$ BALANCE->待定[0] - > amount' – Cory 2014-11-01 00:15:23

回答

2

这里的问题是,pending不是一个对象,而是一个数组,这就是为什么PHP会抛出这个错误。你的代码应该是这样的:

$response = Stripe_Balance::retrieve(); 
foreach($response->pending as $pendingBalance) 
{ 
    echo "Pending balance of " . $pendingBalance->amount . " in " . $pendingBalance->currency . "<br>"; 
} 
0

我怀疑问题是因为您使用的是功能的包装了这一点。实际上不需要定义你自己的函数,其唯一目的是调用另一个函数,在这种情况下这样做可能会导致问题。我会采取的第一步是删除函数包装,并直接使用条纹库。

希望帮助, 拉里

PS我在条纹上的支持工作。

2

一种更好的方式

$balance = Stripe_Balance::retrieve(); 
$balanceArr = $balance->__toArray(true); 
$amount = $balanceArr['pending']['0']['amount'];