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

Stripe: Preview a plan or seat change

See more Stripe Examples

Preview a seat or plan change and display its proration lines, total, and the timestamp to retain with the quote.

Stripe documentation and cURL example

Chilkat Objective-C Downloads

Objective-C
#import <NSString.h>
#import <CkoHttpCurl.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <CkoDateTime.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 *subscriptionId = @"sub_FROM_ACCOUNT";

NSString *itemId = @"si_SELECTED_ITEM";

NSString *priceId = @"price_FROM_CATALOG";

CkoDateTime *now = [[CkoDateTime alloc] init];
[now SetFromCurrentSystemTime];
NSString *prorationDate = [now GetAsUnixTimeStr: NO];

//  curl -X POST "https://api.stripe.com/v1/invoices/create_preview" \
//    -u "$STRIPE_API_KEY:" \
//    -H "Stripe-Version: 2026-10-28.endive" \
//    -d "subscription={subscriptionId}" \
//    -d "subscription_details[items][0][id]={itemId}" \
//    -d "subscription_details[items][0][price]={priceId}" \
//    -d "subscription_details[items][0][quantity]=5" \
//    -d "subscription_details[proration_behavior]=create_prorations" \
//    -d "subscription_details[proration_date]={prorationDate}"
[cmd SetString: @"curl -X POST \"https://api.stripe.com/v1/invoices/create_preview\""];
[cmd Append: @" -u \"@KEY@:\""];
[cmd Append: @" -H \"Stripe-Version: 2026-10-28.endive\""];
[cmd Append: @" -d \"subscription=@SUB@\""];
[cmd Append: @" -d \"subscription_details[items][0][id]=@ITEM@\""];
[cmd Append: @" -d \"subscription_details[items][0][price]=@PRICE@\""];
[cmd Append: @" -d \"subscription_details[items][0][quantity]=5\""];
[cmd Append: @" -d \"subscription_details[proration_behavior]=create_prorations\""];
[cmd Append: @" -d \"subscription_details[proration_date]=@DATE@\""];
replaced = [[cmd Replace: @"@SUB@" replacement: subscriptionId] intValue];
replaced = [[cmd Replace: @"@ITEM@" replacement: itemId] intValue];
replaced = [[cmd Replace: @"@PRICE@" replacement: priceId] intValue];
replaced = [[cmd Replace: @"@DATE@" replacement: prorationDate] 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(@"%@%@",@"total = ",[json StringOf: @"total"]);
NSLog(@"%@%@",@"currency = ",[json StringOf: @"currency"]);

NSLog(@"%@%@",@"Save this preview time with the selected changes: ",prorationDate);
int i = 0;
while ((i < [[json SizeOfArray: @"lines.data"] intValue])) {
    json.I = [NSNumber numberWithInt: i];
    if ([json BoolOf: @"lines.data[i].parent.subscription_item_details.proration"] == YES) {
        NSLog(@"%@%@%@",[json StringOf: @"lines.data[i].description"],@"  ",[json StringOf: @"lines.data[i].amount"]);
    }

    i = i + 1;
}

if ([json BoolOf: @"lines.has_more"] == YES) {
    NSLog(@"%@",@"Only the first page of preview lines is shown. The total covers all lines.");
}