Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.7.0+

Stripe: Match an automatic bank payout to its transactions

See more Stripe Examples

Reconcile a selected automatic payout by comparing its amount with the sum of its settlement entries across all result pages.

Stripe documentation and cURL example

Chilkat Objective-C Downloads

Objective-C
#import <NSString.h>
#import <CkoHttpCurl.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>

BOOL success = NO;

//  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
//  Supply a restricted sandbox key from merchant-controlled configuration.
NSString *apiKey = @"YOUR_STRIPE_TEST_KEY";

CkoHttpCurl *curl = [[CkoHttpCurl alloc] init];
CkoStringBuilder *cmd = [[CkoStringBuilder alloc] init];
CkoJsonObject *json = [[CkoJsonObject alloc] init];

int replaced;

//  Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
NSString *fromTime = @"1790812800";
NSString *untilTime = @"1793491200";

NSString *selectedPayout = @"po_SELECTED_BANK_DEPOSIT";

NSString *expectedAmount = @"";
NSString *currency = @"";

CkoStringBuilder *pageSuffix = [[CkoStringBuilder alloc] init];
BOOL more = YES;
NSString *cursor = @"";
while ((more == YES)) {
    //  curl -X GET "https://api.stripe.com/v1/payouts?created%5Bgte%5D={fromTime}&created%5Blt%5D={untilTime}&limit=100" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive"
    [cmd SetString: @"curl -X GET \"https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@\""];
    [cmd Append: @" -u \"@KEY@:\""];
    [cmd Append: @" -H \"Stripe-Version: 2026-10-28.endive\""];
    replaced = [[cmd Replace: @"@CURSOR@" replacement: [pageSuffix GetAsString]] intValue];
    replaced = [[cmd Replace: @"@FROM@" replacement: fromTime] intValue];
    replaced = [[cmd Replace: @"@UNTIL@" replacement: untilTime] intValue];
    replaced = [[cmd Replace: @"@KEY@" replacement: apiKey] intValue];
    success = [curl DoYourThing: [cmd GetAsString]];
    if (success != YES) {
        NSLog(@"%@%d",@"No HTTP response. Chilkat failure code: ",[curl.FailReason intValue]);
        return;
    }

    success = [curl GetResponseJson: json];
    if (([curl.StatusCode intValue] != 200) || (success != YES)) {
        NSLog(@"%@%d%@%@",@"Stripe HTTP ",[curl.StatusCode intValue],@"  Request-Id: ",[curl GetResponseHeaderField: @"Request-Id"]);
        if (success == YES) {
            NSLog(@"%@",[json StringOf: @"error.message"]);
        }

        return;
    }

    int i = 0;
    int count = [[json SizeOfArray: @"data"] intValue];
    while ((i < count)) {
        json.I = [NSNumber numberWithInt: i];
        NSLog(@"%@%@%@%@%@%@%@",[json StringOf: @"data[i].id"],@" | ",[json StringOf: @"data[i].amount"],@" | ",[json StringOf: @"data[i].currency"],@" | ",[json StringOf: @"data[i].reconciliation_status"]);
        if ([json StringOf: @"data[i].id"] == selectedPayout) {
            if (([json BoolOf: @"data[i].automatic"] != YES) || ([json StringOf: @"data[i].reconciliation_status"] != @"completed")) {
                NSLog(@"%@",@"Select an automatic payout with completed reconciliation.");
                return;
            }

            expectedAmount = [json StringOf: @"data[i].amount"];
            currency = [json StringOf: @"data[i].currency"];
        }

        i = i + 1;
    }

    more = [json BoolOf: @"has_more"];
    if (more == YES) {
        NSString *next = [json StringOf: @"data[i].id"];
        if ((count < 1) || (next == @"") || (next == cursor)) {
            NSLog(@"%@",@"Invalid pagination cursor.");
            return;
        }

        cursor = next;
        [pageSuffix SetString: @"&starting_after="];
        [pageSuffix Append: cursor];
    }

}

if (expectedAmount == @"") {
    NSLog(@"%@",@"The selected payout was not in this date range.");
    return;
}

int totalNet = 0;
//  This portable example uses int for arithmetic. Reject an out-of-range entry
//  or sum before adding. A larger ledger can sum the exact strings using decimal arithmetic.
CkoStringBuilder *number = [[CkoStringBuilder alloc] init];

CkoStringBuilder *pageSuffixTxn = [[CkoStringBuilder alloc] init];
BOOL moreTxn = YES;
NSString *cursorTxn = @"";
while ((moreTxn == YES)) {
    //  curl -X GET "https://api.stripe.com/v1/balance_transactions?payout={selectedPayout}&limit=100" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive"
    [cmd SetString: @"curl -X GET \"https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&limit=100@CURSOR@\""];
    [cmd Append: @" -u \"@KEY@:\""];
    [cmd Append: @" -H \"Stripe-Version: 2026-10-28.endive\""];
    replaced = [[cmd Replace: @"@CURSOR@" replacement: [pageSuffixTxn GetAsString]] intValue];
    replaced = [[cmd Replace: @"@PAYOUT@" replacement: selectedPayout] intValue];
    replaced = [[cmd Replace: @"@KEY@" replacement: apiKey] intValue];
    success = [curl DoYourThing: [cmd GetAsString]];
    if (success != YES) {
        NSLog(@"%@%d",@"No HTTP response. Chilkat failure code: ",[curl.FailReason intValue]);
        return;
    }

    success = [curl GetResponseJson: json];
    if (([curl.StatusCode intValue] != 200) || (success != YES)) {
        NSLog(@"%@%d%@%@",@"Stripe HTTP ",[curl.StatusCode intValue],@"  Request-Id: ",[curl GetResponseHeaderField: @"Request-Id"]);
        if (success == YES) {
            NSLog(@"%@",[json StringOf: @"error.message"]);
        }

        return;
    }

    int iTxn = 0;
    int countTxn = [[json SizeOfArray: @"data"] intValue];
    while ((iTxn < countTxn)) {
        json.I = [NSNumber numberWithInt: iTxn];
        NSLog(@"%@%@%@",[json StringOf: @"data[i].id"],@"  ",[json StringOf: @"data[i].net"]);
        if ([json StringOf: @"data[i].currency"] != currency) {
            NSLog(@"%@",@"Currency mismatch.");
            return;
        }

        //  Exclude the bank withdrawal itself if it appears in this batch.
        if ([json StringOf: @"data[i].source"] != selectedPayout) {
            NSString *netText = [json StringOf: @"data[i].net"];
            int entryNet = [[json IntOf: @"data[i].net"] intValue];
            number.IntValue = [NSNumber numberWithInt: entryNet];
            if ([number GetAsString] != netText) {
                NSLog(@"%@%@",@"Entry exceeds the supported int range: ",netText);
                return;
            }

            if (entryNet > 0) {
                if (totalNet > (2147483647 - entryNet)) {
                    NSLog(@"%@",@"Total exceeds the supported int range.");
                    return;
                }

            }

            if (entryNet < 0) {
                if (totalNet < ((0 - 2147483647) - (entryNet + 1))) {
                    NSLog(@"%@",@"Total exceeds the supported int range.");
                    return;
                }

            }

            totalNet = totalNet + entryNet;
        }

        iTxn = iTxn + 1;
    }

    moreTxn = [json BoolOf: @"has_more"];
    if (moreTxn == YES) {
        NSString *nextTxn = [json StringOf: @"data[i].id"];
        if ((countTxn < 1) || (nextTxn == @"") || (nextTxn == cursorTxn)) {
            NSLog(@"%@",@"Invalid pagination cursor.");
            return;
        }

        cursorTxn = nextTxn;
        [pageSuffixTxn SetString: @"&starting_after="];
        [pageSuffixTxn Append: cursorTxn];
    }

}

number.IntValue = [NSNumber numberWithInt: totalNet];
NSLog(@"%@%d%@%@%@%@",@"Settlement net: ",totalNet,@"  Bank payout: ",expectedAmount,@" ",currency);
if ([number GetAsString] == expectedAmount) {
    NSLog(@"%@",@"Payout reconciled.");
}
else {
    NSLog(@"%@",@"Investigate the difference.");
}