PHP ActiveX Stripe: Retrieve Balance

Back to Index

Retrieves the current account balance, based on the authentication that was used to make the request.

Documentation: https://stripe.com/docs/api/curl#retrieve_balance

CURL Command

curl https://api.stripe.com/v1/balance \
   -u STRIPE_SECRET_KEY:

PHP ActiveX Example

<?php

$rest = new COM("Chilkat_9_5_0.Rest");

//  URL: https://api.stripe.com/v1/balance
$bTls = 1;
$port = 443;
$bAutoReconnect = 1;
$success = $rest->Connect('api.stripe.com',$port,$bTls,$bAutoReconnect);
if ($success != 1) {
    print 'ConnectFailReason: ' . $rest->ConnectFailReason . "\n";
    print $rest->LastErrorText . "\n";
    exit;
}

$rest->SetAuthBasic('STRIPE_SECRET_KEY','');

$sbResponseBody = new COM("Chilkat_9_5_0.StringBuilder");
$success = $rest->FullRequestNoBodySb('GET','/v1/balance',$sbResponseBody);
if ($success != 1) {
    print $rest->LastErrorText . "\n";
    exit;
}

$jsonResponse = new COM("Chilkat_9_5_0.JsonObject");
$jsonResponse->LoadSb($sbResponseBody);

$object = $jsonResponse->stringOf('object');
$livemode = $jsonResponse->BoolOf('livemode');
$i = 0;
$count_i = $jsonResponse->SizeOfArray('available');
while ($i < $count_i) {
    $jsonResponse->I = $i;
    $currency = $jsonResponse->stringOf('available[i].currency');
    $amount = $jsonResponse->IntOf('available[i].amount');
    $source_typesCard = $jsonResponse->IntOf('available[i].source_types.card');
    $i = $i + 1;
}

$i = 0;
$count_i = $jsonResponse->SizeOfArray('pending');
while ($i < $count_i) {
    $jsonResponse->I = $i;
    $currency = $jsonResponse->stringOf('pending[i].currency');
    $amount = $jsonResponse->IntOf('pending[i].amount');
    $source_typesCard = $jsonResponse->IntOf('pending[i].source_types.card');
    $i = $i + 1;
}


?>

Sample JSON Response Body

{
  "object": "balance",
  "available": [
    {
      "currency": "usd",
      "amount": 0,
      "source_types": {
        "card": 0
      }
    }
  ],
  "livemode": false,
  "pending": [
    {
      "currency": "usd",
      "amount": 0,
      "source_types": {
        "card": 0
      }
    }
  ]
}