Objective-C Stripe: List all Charges

Back to Index

Returns a list of charges you’ve previously created. The charges are returned in sorted order, with the most recent charges appearing first.

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

CURL Command

curl https://api.stripe.com/v1/charges?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/charges?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/charges?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;
int amount_refunded;
BOOL application;
BOOL application_fee;
NSString *balance_transaction = 0;
BOOL captured;
int created;
NSString *currency = 0;
BOOL customer;
NSString *description = 0;
BOOL destination;
BOOL dispute;
BOOL failure_code;
BOOL failure_message;
BOOL invoice;
BOOL livemode;
BOOL on_behalf_of;
BOOL order;
BOOL outcome;
BOOL paid;
BOOL receipt_email;
BOOL receipt_number;
BOOL refunded;
NSString *refundsObject = 0;
BOOL refundsHas_more;
int refundsTotal_count;
NSString *refundsUrl = 0;
BOOL review;
BOOL shipping;
NSString *sourceId = 0;
NSString *sourceObject = 0;
BOOL sourceAddress_city;
BOOL sourceAddress_country;
BOOL sourceAddress_line1;
BOOL sourceAddress_line1_check;
BOOL sourceAddress_line2;
BOOL sourceAddress_state;
BOOL sourceAddress_zip;
BOOL sourceAddress_zip_check;
NSString *sourceBrand = 0;
NSString *sourceCountry = 0;
BOOL sourceCustomer;
BOOL sourceCvc_check;
BOOL sourceDynamic_last4;
int sourceExp_month;
int sourceExp_year;
NSString *sourceFingerprint = 0;
NSString *sourceFunding = 0;
NSString *sourceLast4 = 0;
BOOL sourceName;
BOOL sourceTokenization_method;
BOOL source_transfer;
BOOL statement_descriptor;
NSString *status = 0;
BOOL transfer_group;
int j;
int count_j;

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 = [[jsonResponse IntOf: @"data[i].amount"] intValue];
    amount_refunded = [[jsonResponse IntOf: @"data[i].amount_refunded"] intValue];
    application = [jsonResponse IsNullOf: @"data[i].application"];
    application_fee = [jsonResponse IsNullOf: @"data[i].application_fee"];
    balance_transaction = [jsonResponse StringOf: @"data[i].balance_transaction"];
    captured = [jsonResponse BoolOf: @"data[i].captured"];
    created = [[jsonResponse IntOf: @"data[i].created"] intValue];
    currency = [jsonResponse StringOf: @"data[i].currency"];
    customer = [jsonResponse IsNullOf: @"data[i].customer"];
    description = [jsonResponse StringOf: @"data[i].description"];
    destination = [jsonResponse IsNullOf: @"data[i].destination"];
    dispute = [jsonResponse IsNullOf: @"data[i].dispute"];
    failure_code = [jsonResponse IsNullOf: @"data[i].failure_code"];
    failure_message = [jsonResponse IsNullOf: @"data[i].failure_message"];
    invoice = [jsonResponse IsNullOf: @"data[i].invoice"];
    livemode = [jsonResponse BoolOf: @"data[i].livemode"];
    on_behalf_of = [jsonResponse IsNullOf: @"data[i].on_behalf_of"];
    order = [jsonResponse IsNullOf: @"data[i].order"];
    outcome = [jsonResponse IsNullOf: @"data[i].outcome"];
    paid = [jsonResponse BoolOf: @"data[i].paid"];
    receipt_email = [jsonResponse IsNullOf: @"data[i].receipt_email"];
    receipt_number = [jsonResponse IsNullOf: @"data[i].receipt_number"];
    refunded = [jsonResponse BoolOf: @"data[i].refunded"];
    refundsObject = [jsonResponse StringOf: @"data[i].refunds.object"];
    refundsHas_more = [jsonResponse BoolOf: @"data[i].refunds.has_more"];
    refundsTotal_count = [[jsonResponse IntOf: @"data[i].refunds.total_count"] intValue];
    refundsUrl = [jsonResponse StringOf: @"data[i].refunds.url"];
    review = [jsonResponse IsNullOf: @"data[i].review"];
    shipping = [jsonResponse IsNullOf: @"data[i].shipping"];
    sourceId = [jsonResponse StringOf: @"data[i].source.id"];
    sourceObject = [jsonResponse StringOf: @"data[i].source.object"];
    sourceAddress_city = [jsonResponse IsNullOf: @"data[i].source.address_city"];
    sourceAddress_country = [jsonResponse IsNullOf: @"data[i].source.address_country"];
    sourceAddress_line1 = [jsonResponse IsNullOf: @"data[i].source.address_line1"];
    sourceAddress_line1_check = [jsonResponse IsNullOf: @"data[i].source.address_line1_check"];
    sourceAddress_line2 = [jsonResponse IsNullOf: @"data[i].source.address_line2"];
    sourceAddress_state = [jsonResponse IsNullOf: @"data[i].source.address_state"];
    sourceAddress_zip = [jsonResponse IsNullOf: @"data[i].source.address_zip"];
    sourceAddress_zip_check = [jsonResponse IsNullOf: @"data[i].source.address_zip_check"];
    sourceBrand = [jsonResponse StringOf: @"data[i].source.brand"];
    sourceCountry = [jsonResponse StringOf: @"data[i].source.country"];
    sourceCustomer = [jsonResponse IsNullOf: @"data[i].source.customer"];
    sourceCvc_check = [jsonResponse IsNullOf: @"data[i].source.cvc_check"];
    sourceDynamic_last4 = [jsonResponse IsNullOf: @"data[i].source.dynamic_last4"];
    sourceExp_month = [[jsonResponse IntOf: @"data[i].source.exp_month"] intValue];
    sourceExp_year = [[jsonResponse IntOf: @"data[i].source.exp_year"] intValue];
    sourceFingerprint = [jsonResponse StringOf: @"data[i].source.fingerprint"];
    sourceFunding = [jsonResponse StringOf: @"data[i].source.funding"];
    sourceLast4 = [jsonResponse StringOf: @"data[i].source.last4"];
    sourceName = [jsonResponse IsNullOf: @"data[i].source.name"];
    sourceTokenization_method = [jsonResponse IsNullOf: @"data[i].source.tokenization_method"];
    source_transfer = [jsonResponse IsNullOf: @"data[i].source_transfer"];
    statement_descriptor = [jsonResponse IsNullOf: @"data[i].statement_descriptor"];
    status = [jsonResponse StringOf: @"data[i].status"];
    transfer_group = [jsonResponse IsNullOf: @"data[i].transfer_group"];
    j = 0;
    count_j = [[jsonResponse SizeOfArray: @"data[i].refunds.data"] intValue];
    while (j < count_j) {
        jsonResponse.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    i = i + 1;
}

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/charges",
  "has_more": false,
  "data": [
    {
      "id": "ch_1BnETJGswQrCoh0XTs0EERBj",
      "object": "charge",
      "amount": 100,
      "amount_refunded": 0,
      "application": null,
      "application_fee": null,
      "balance_transaction": "txn_1BnETJGswQrCoh0XxO2tGYr7",
      "captured": false,
      "created": 1516662781,
      "currency": "usd",
      "customer": null,
      "description": "My First Test Charge (created for API docs)",
      "destination": null,
      "dispute": null,
      "failure_code": null,
      "failure_message": null,
      "fraud_details": {},
      "invoice": null,
      "livemode": false,
      "metadata": {},
      "on_behalf_of": null,
      "order": null,
      "outcome": null,
      "paid": true,
      "receipt_email": null,
      "receipt_number": null,
      "refunded": false,
      "refunds": {
        "object": "list",
        "data": [
        ],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/refunds"
      },
      "review": null,
      "shipping": null,
      "source": {
        "id": "card_18ropuGswQrCoh0XjCJ5Zvma",
        "object": "card",
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": null,
        "address_zip_check": null,
        "brand": "Visa",
        "country": "US",
        "customer": null,
        "cvc_check": null,
        "dynamic_last4": null,
        "exp_month": 8,
        "exp_year": 2017,
        "fingerprint": "F9mANtIt1TaukpRJ",
        "funding": "credit",
        "last4": "4242",
        "metadata": {},
        "name": null,
        "tokenization_method": null
      },
      "source_transfer": null,
      "statement_descriptor": null,
      "status": "succeeded",
      "transfer_group": null
    }
  ]
}