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

Stripe: Identify the payment for a paid invoice

See more Stripe Examples

List the payments allocated to an invoice and identify a paid charge or PaymentIntent for refund.

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;

NSString *invoiceId = @"in_FROM_BILLING_RECORD";

CkoStringBuilder *pageSuffix = [[CkoStringBuilder alloc] init];
BOOL more = YES;
NSString *cursor = @"";
while ((more == YES)) {
    //  curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice={invoiceId}&limit=100" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive"
    [cmd SetString: @"curl -X GET \"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&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: @"@ID@" replacement: invoiceId] 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].status"],@" | ",[json StringOf: @"data[i].amount_paid"],@" | "
            ,[json StringOf: @"data[i].currency"],@" | ",[json StringOf: @"data[i].payment.type"]);
        if ([json StringOf: @"data[i].payment.type"] == @"payment_intent") {
            NSLog(@"%@%@",@"  PaymentIntent: ",[json StringOf: @"data[i].payment.payment_intent"]);
        }

        if ([json StringOf: @"data[i].payment.type"] == @"charge") {
            NSLog(@"%@%@",@"  Charge: ",[json StringOf: @"data[i].payment.charge"]);
        }

        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];
    }

}

//  Select the paid allocation belonging to the order before issuing its refund.