Objective-C Stripe: Retrieve a Balance Transaction

Back to Index

Retrieves the balance transaction with the given ID.

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

CURL Command

curl https://api.stripe.com/v1/balance/history/txn_1BnETJGswQrCoh0XxO2tGYr7 \
   -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/history/txn_1BnETJGswQrCoh0XxO2tGYr7
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/history/txn_1BnETJGswQrCoh0XxO2tGYr7" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

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

NSString *id = 0;
NSString *object = 0;
int amount;
int available_on;
int created;
NSString *currency = 0;
BOOL description;
BOOL exchange_rate;
int fee;
int net;
NSString *source = 0;
NSString *status = 0;
NSString *type = 0;
int i;
int count_i;

id = [jsonResponse StringOf: @"id"];
object = [jsonResponse StringOf: @"object"];
amount = [[jsonResponse IntOf: @"amount"] intValue];
available_on = [[jsonResponse IntOf: @"available_on"] intValue];
created = [[jsonResponse IntOf: @"created"] intValue];
currency = [jsonResponse StringOf: @"currency"];
description = [jsonResponse IsNullOf: @"description"];
exchange_rate = [jsonResponse IsNullOf: @"exchange_rate"];
fee = [[jsonResponse IntOf: @"fee"] intValue];
net = [[jsonResponse IntOf: @"net"] intValue];
source = [jsonResponse StringOf: @"source"];
status = [jsonResponse StringOf: @"status"];
type = [jsonResponse StringOf: @"type"];
i = 0;
count_i = [[jsonResponse SizeOfArray: @"fee_details"] intValue];
while (i < count_i) {
    jsonResponse.I = [NSNumber numberWithInt: i];
    i = i + 1;
}

Sample JSON Response Body

{
  "id": "txn_1BnETJGswQrCoh0XxO2tGYr7",
  "object": "balance_transaction",
  "amount": 100,
  "available_on": 1516662781,
  "created": 1516662781,
  "currency": "usd",
  "description": null,
  "exchange_rate": null,
  "fee": 0,
  "fee_details": [
  ],
  "net": 100,
  "source": "ch_1BnETJGswQrCoh0XTs0EERBj",
  "status": "pending",
  "type": "charge"
}