Objective-C 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:

Objective-C Example

#import <CkoRest.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

//  URL: https://api.stripe.com/v1/balance
BOOL bTls = YES;
int port = 443;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"api.stripe.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest SetAuthBasic: @"STRIPE_SECRET_KEY" password: @""];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/v1/balance" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

CkoJsonObject *jsonResponse = [[CkoJsonObject alloc] init];
[jsonResponse LoadSb: sbResponseBody];

NSString *object = 0;
BOOL livemode;
int i;
int count_i;
NSString *currency = 0;
int amount;
int source_typesCard;

object = [jsonResponse StringOf: @"object"];
livemode = [jsonResponse BoolOf: @"livemode"];
i = 0;
count_i = [[jsonResponse SizeOfArray: @"available"] intValue];
while (i < count_i) {
    jsonResponse.I = [NSNumber numberWithInt: i];
    currency = [jsonResponse StringOf: @"available[i].currency"];
    amount = [[jsonResponse IntOf: @"available[i].amount"] intValue];
    source_typesCard = [[jsonResponse IntOf: @"available[i].source_types.card"] intValue];
    i = i + 1;
}

i = 0;
count_i = [[jsonResponse SizeOfArray: @"pending"] intValue];
while (i < count_i) {
    jsonResponse.I = [NSNumber numberWithInt: i];
    currency = [jsonResponse StringOf: @"pending[i].currency"];
    amount = [[jsonResponse IntOf: @"pending[i].amount"] intValue];
    source_typesCard = [[jsonResponse IntOf: @"pending[i].source_types.card"] intValue];
    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
      }
    }
  ]
}