我正在构建与 WordPress 的 Stripe 连接集成,并尝试检索已连接帐户的余额。
到目前为止,这是我的代码:
// Show User Balance
function show_user_balance($uid){
require 'vendor/autoload.php';
$user_id = $uid;
$connected_account_id = get_user_meta( $user_id, 'stripe_connect_id', true );
// Set your secret key. Remember to switch to your live secret key in production!
\Stripe\Stripe::setApiKey('sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$balance = \Stripe\Balance::retrieve(
['stripe_account' => $connected_account_id]
);
echo "Current Balance: ".$balance;
}
Echoing$balance返回以下 JSON 格式的字符串:
Current Balance: Stripe\Balance JSON: { "object": "balance", "available": [ { "amount": 0, "currency": "usd", "source_types": { "card": 0 } } ], "instant_available": [ { "amount": 0, "currency": "usd", "source_types": { "card": 0 } } ], "livemode": false, "pending": [ { "amount": 0, "currency": "usd", "source_types": { "card": 0 } } ] }
我想回显可用余额的金额。我已经尝试使用json_decode设置为 true 的函数。它返回一个对象数组,我已经尝试了这两种方法,print_r但var_dump没有成功的结果。
有什么建议么?
蝴蝶不菲