Objective-C Stripe: List all Invoices

Back to Index

Attempts payment on an invoice out of the normal collection schedule.

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

CURL Command

curl https://api.stripe.com/v1/invoices?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

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/invoices?limit=3
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/invoices?limit=3" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

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

NSString *object = 0;
NSString *url = 0;
BOOL has_more;
int i;
int count_i;
NSString *id = 0;
int amount_due;
BOOL application_fee;
int attempt_count;
BOOL attempted;
NSString *billing = 0;
BOOL charge;
BOOL closed;
NSString *currency = 0;
NSString *customer = 0;
int date;
BOOL description;
BOOL discount;
BOOL due_date;
BOOL ending_balance;
BOOL forgiven;
BOOL linesHas_more;
NSString *linesObject = 0;
NSString *linesUrl = 0;
BOOL livemode;
int next_payment_attempt;
NSString *number = 0;
BOOL paid;
int period_end;
int period_start;
BOOL receipt_number;
int starting_balance;
BOOL statement_descriptor;
BOOL subscription;
int subtotal;
BOOL tax;
BOOL tax_percent;
int total;
BOOL webhooks_delivered_at;
int j;
int count_j;
int amount;
NSString *description_str = 0;
BOOL discountable;
int periodStart;
int periodEnd;
NSString *planId = 0;
NSString *planObject = 0;
int planAmount;
int planCreated;
NSString *planCurrency = 0;
NSString *planInterval = 0;
int planInterval_count;
BOOL planLivemode;
NSString *planName = 0;
BOOL planStatement_descriptor;
BOOL planTrial_period_days;
BOOL proration;
int quantity;
NSString *subscription_item = 0;
NSString *type = 0;

object = [jsonResponse StringOf: @"object"];
url = [jsonResponse StringOf: @"url"];
has_more = [jsonResponse BoolOf: @"has_more"];
i = 0;
count_i = [[jsonResponse SizeOfArray: @"data"] intValue];
while (i < count_i) {
    jsonResponse.I = [NSNumber numberWithInt: i];
    id = [jsonResponse StringOf: @"data[i].id"];
    object = [jsonResponse StringOf: @"data[i].object"];
    amount_due = [[jsonResponse IntOf: @"data[i].amount_due"] intValue];
    application_fee = [jsonResponse IsNullOf: @"data[i].application_fee"];
    attempt_count = [[jsonResponse IntOf: @"data[i].attempt_count"] intValue];
    attempted = [jsonResponse BoolOf: @"data[i].attempted"];
    billing = [jsonResponse StringOf: @"data[i].billing"];
    charge = [jsonResponse IsNullOf: @"data[i].charge"];
    closed = [jsonResponse BoolOf: @"data[i].closed"];
    currency = [jsonResponse StringOf: @"data[i].currency"];
    customer = [jsonResponse StringOf: @"data[i].customer"];
    date = [[jsonResponse IntOf: @"data[i].date"] intValue];
    description = [jsonResponse IsNullOf: @"data[i].description"];
    discount = [jsonResponse IsNullOf: @"data[i].discount"];
    due_date = [jsonResponse IsNullOf: @"data[i].due_date"];
    ending_balance = [jsonResponse IsNullOf: @"data[i].ending_balance"];
    forgiven = [jsonResponse BoolOf: @"data[i].forgiven"];
    linesHas_more = [jsonResponse BoolOf: @"data[i].lines.has_more"];
    linesObject = [jsonResponse StringOf: @"data[i].lines.object"];
    linesUrl = [jsonResponse StringOf: @"data[i].lines.url"];
    livemode = [jsonResponse BoolOf: @"data[i].livemode"];
    next_payment_attempt = [[jsonResponse IntOf: @"data[i].next_payment_attempt"] intValue];
    number = [jsonResponse StringOf: @"data[i].number"];
    paid = [jsonResponse BoolOf: @"data[i].paid"];
    period_end = [[jsonResponse IntOf: @"data[i].period_end"] intValue];
    period_start = [[jsonResponse IntOf: @"data[i].period_start"] intValue];
    receipt_number = [jsonResponse IsNullOf: @"data[i].receipt_number"];
    starting_balance = [[jsonResponse IntOf: @"data[i].starting_balance"] intValue];
    statement_descriptor = [jsonResponse IsNullOf: @"data[i].statement_descriptor"];
    subscription = [jsonResponse IsNullOf: @"data[i].subscription"];
    subtotal = [[jsonResponse IntOf: @"data[i].subtotal"] intValue];
    tax = [jsonResponse IsNullOf: @"data[i].tax"];
    tax_percent = [jsonResponse IsNullOf: @"data[i].tax_percent"];
    total = [[jsonResponse IntOf: @"data[i].total"] intValue];
    webhooks_delivered_at = [jsonResponse IsNullOf: @"data[i].webhooks_delivered_at"];
    j = 0;
    count_j = [[jsonResponse SizeOfArray: @"data[i].lines.data"] intValue];
    while (j < count_j) {
        jsonResponse.J = [NSNumber numberWithInt: j];
        id = [jsonResponse StringOf: @"data[i].lines.data[j].id"];
        object = [jsonResponse StringOf: @"data[i].lines.data[j].object"];
        amount = [[jsonResponse IntOf: @"data[i].lines.data[j].amount"] intValue];
        currency = [jsonResponse StringOf: @"data[i].lines.data[j].currency"];
        description_str = [jsonResponse StringOf: @"data[i].lines.data[j].description"];
        discountable = [jsonResponse BoolOf: @"data[i].lines.data[j].discountable"];
        livemode = [jsonResponse BoolOf: @"data[i].lines.data[j].livemode"];
        periodStart = [[jsonResponse IntOf: @"data[i].lines.data[j].period.start"] intValue];
        periodEnd = [[jsonResponse IntOf: @"data[i].lines.data[j].period.end"] intValue];
        planId = [jsonResponse StringOf: @"data[i].lines.data[j].plan.id"];
        planObject = [jsonResponse StringOf: @"data[i].lines.data[j].plan.object"];
        planAmount = [[jsonResponse IntOf: @"data[i].lines.data[j].plan.amount"] intValue];
        planCreated = [[jsonResponse IntOf: @"data[i].lines.data[j].plan.created"] intValue];
        planCurrency = [jsonResponse StringOf: @"data[i].lines.data[j].plan.currency"];
        planInterval = [jsonResponse StringOf: @"data[i].lines.data[j].plan.interval"];
        planInterval_count = [[jsonResponse IntOf: @"data[i].lines.data[j].plan.interval_count"] intValue];
        planLivemode = [jsonResponse BoolOf: @"data[i].lines.data[j].plan.livemode"];
        planName = [jsonResponse StringOf: @"data[i].lines.data[j].plan.name"];
        planStatement_descriptor = [jsonResponse IsNullOf: @"data[i].lines.data[j].plan.statement_descriptor"];
        planTrial_period_days = [jsonResponse IsNullOf: @"data[i].lines.data[j].plan.trial_period_days"];
        proration = [jsonResponse BoolOf: @"data[i].lines.data[j].proration"];
        quantity = [[jsonResponse IntOf: @"data[i].lines.data[j].quantity"] intValue];
        subscription = [jsonResponse IsNullOf: @"data[i].lines.data[j].subscription"];
        subscription_item = [jsonResponse StringOf: @"data[i].lines.data[j].subscription_item"];
        type = [jsonResponse StringOf: @"data[i].lines.data[j].type"];
        j = j + 1;
    }

    i = i + 1;
}

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/invoices",
  "has_more": false,
  "data": [
    {
      "id": "in_1BnETLGswQrCoh0X6M67Qy9c",
      "object": "invoice",
      "amount_due": 0,
      "application_fee": null,
      "attempt_count": 0,
      "attempted": false,
      "billing": "charge_automatically",
      "charge": null,
      "closed": false,
      "currency": "usd",
      "customer": "cus_CBbggkUyLoz3pe",
      "date": 1516662783,
      "description": null,
      "discount": null,
      "due_date": null,
      "ending_balance": null,
      "forgiven": false,
      "lines": {
        "data": [
          {
            "id": "sub_CBbgC3EaFZqN3Q",
            "object": "line_item",
            "amount": 999,
            "currency": "usd",
            "description": "1x Silver Express (at $9.99)",
            "discountable": true,
            "livemode": true,
            "metadata": {},
            "period": {
              "start": 1521760383,
              "end": 1524438783
            },
            "plan": {
              "id": "gold",
              "object": "plan",
              "amount": 2000,
              "created": 1516662783,
              "currency": "usd",
              "interval": "month",
              "interval_count": 1,
              "livemode": false,
              "metadata": {},
              "name": "T-shirt",
              "statement_descriptor": null,
              "trial_period_days": null
            },
            "proration": false,
            "quantity": 1,
            "subscription": null,
            "subscription_item": "si_CBbgZxCVF3Ha7P",
            "type": "subscription"
          }
        ],
        "has_more": false,
        "object": "list",
        "url": "/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c/lines"
      },
      "livemode": false,
      "metadata": {},
      "next_payment_attempt": 1516666383,
      "number": "330a34b8d5-0001",
      "paid": false,
      "period_end": 1516662783,
      "period_start": 1516662783,
      "receipt_number": null,
      "starting_balance": 0,
      "statement_descriptor": null,
      "subscription": null,
      "subtotal": 0,
      "tax": null,
      "tax_percent": null,
      "total": 0,
      "webhooks_delivered_at": null
    }
  ]
}