Objective-C Requires Chilkat v11.7.0+
Objective-C
Stripe: Finalize and email a reviewed invoice
See more Stripe Examples
Finalize a reviewed draft and send the open invoice by email. Stripe test mode returns the API result without delivering an email.
Stripe documentation and cURL example
Chilkat Objective-C Downloads
#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";
// Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
NSString *operationId = @"YOUR_SAVED_OPERATION_UUID";
CkoHttpCurl *curl = [[CkoHttpCurl alloc] init];
CkoStringBuilder *cmd = [[CkoStringBuilder alloc] init];
CkoJsonObject *json = [[CkoJsonObject alloc] init];
int replaced;
NSString *invoiceId = @"in_FROM_BILLING_RECORD";
// curl -X GET "https://api.stripe.com/v1/invoices/{invoiceId}" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive"
[cmd SetString: @"curl -X GET \"https://api.stripe.com/v1/invoices/@ID@\""];
[cmd Append: @" -u \"@KEY@:\""];
[cmd Append: @" -H \"Stripe-Version: 2026-10-28.endive\""];
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;
}
if ([json StringOf: @"collection_method"] != @"send_invoice") {
NSLog(@"%@",@"Select an invoice intended for email collection.");
return;
}
if ([json StringOf: @"status"] == @"draft") {
// curl -X POST "https://api.stripe.com/v1/invoices/{invoiceId}/finalize" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -H "Idempotency-Key: {operationId}-finalize" \
// -d "auto_advance=false"
[cmd SetString: @"curl -X POST \"https://api.stripe.com/v1/invoices/@ID@/finalize\""];
[cmd Append: @" -u \"@KEY@:\""];
[cmd Append: @" -H \"Stripe-Version: 2026-10-28.endive\""];
[cmd Append: @" -H \"Idempotency-Key: @OP@-finalize\""];
[cmd Append: @" -d \"auto_advance=false\""];
replaced = [[cmd Replace: @"@ID@" replacement: invoiceId] intValue];
replaced = [[cmd Replace: @"@OP@" replacement: operationId] 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;
}
}
if ([json StringOf: @"status"] != @"open") {
NSLog(@"%@%@",@"Invoice is not open for collection: ",[json StringOf: @"status"]);
return;
}
// Retry a send using the same saved operation UUID. Test mode sends no email.
// curl -X POST "https://api.stripe.com/v1/invoices/{invoiceId}/send" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -H "Idempotency-Key: {operationId}-send"
[cmd SetString: @"curl -X POST \"https://api.stripe.com/v1/invoices/@ID@/send\""];
[cmd Append: @" -u \"@KEY@:\""];
[cmd Append: @" -H \"Stripe-Version: 2026-10-28.endive\""];
[cmd Append: @" -H \"Idempotency-Key: @OP@-send\""];
replaced = [[cmd Replace: @"@ID@" replacement: invoiceId] intValue];
replaced = [[cmd Replace: @"@OP@" replacement: operationId] 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;
}
NSLog(@"%@%@",@"number = ",[json StringOf: @"number"]);
NSLog(@"%@%@",@"status = ",[json StringOf: @"status"]);
NSLog(@"%@%@",@"hosted_invoice_url = ",[json StringOf: @"hosted_invoice_url"]);