C Stripe: Create an Invoice

Back to Index

Creates a customer invoice object.

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

CURL Command

curl https://api.stripe.com/v1/invoices \
   -u STRIPE_SECRET_KEY: \
   -d customer=cus_CBbg9PmQ9sLbmo \
   -X POST

C Example

#include <C_CkRest.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const char *strResponseBody;
    HCkJsonObject jsonResponse;
    const char *id;
    const char *object;
    int amount_due;
    BOOL application_fee;
    int attempt_count;
    BOOL attempted;
    const char *billing;
    BOOL charge;
    BOOL closed;
    const char *currency;
    const char *customer;
    int date;
    BOOL description;
    BOOL discount;
    BOOL due_date;
    BOOL ending_balance;
    BOOL forgiven;
    BOOL linesHas_more;
    const char *linesObject;
    const char *linesUrl;
    BOOL livemode;
    int next_payment_attempt;
    const char *number;
    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 i;
    int count_i;
    int amount;
    const char *description_str;
    BOOL discountable;
    int periodStart;
    int periodEnd;
    BOOL plan;
    BOOL proration;
    BOOL quantity;
    const char *type;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/invoices
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");

    CkRest_AddQueryParam(rest,"customer","cus_CBbg9PmQ9sLbmo");

    strResponseBody = CkRest_fullRequestFormUrlEncoded(rest,"POST","/v1/invoices");
    if (CkRest_getLastMethodSuccess(rest) != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_Load(jsonResponse,strResponseBody);

    id = CkJsonObject_stringOf(jsonResponse,"id");
    object = CkJsonObject_stringOf(jsonResponse,"object");
    amount_due = CkJsonObject_IntOf(jsonResponse,"amount_due");
    application_fee = CkJsonObject_IsNullOf(jsonResponse,"application_fee");
    attempt_count = CkJsonObject_IntOf(jsonResponse,"attempt_count");
    attempted = CkJsonObject_BoolOf(jsonResponse,"attempted");
    billing = CkJsonObject_stringOf(jsonResponse,"billing");
    charge = CkJsonObject_IsNullOf(jsonResponse,"charge");
    closed = CkJsonObject_BoolOf(jsonResponse,"closed");
    currency = CkJsonObject_stringOf(jsonResponse,"currency");
    customer = CkJsonObject_stringOf(jsonResponse,"customer");
    date = CkJsonObject_IntOf(jsonResponse,"date");
    description = CkJsonObject_IsNullOf(jsonResponse,"description");
    discount = CkJsonObject_IsNullOf(jsonResponse,"discount");
    due_date = CkJsonObject_IsNullOf(jsonResponse,"due_date");
    ending_balance = CkJsonObject_IsNullOf(jsonResponse,"ending_balance");
    forgiven = CkJsonObject_BoolOf(jsonResponse,"forgiven");
    linesHas_more = CkJsonObject_BoolOf(jsonResponse,"lines.has_more");
    linesObject = CkJsonObject_stringOf(jsonResponse,"lines.object");
    linesUrl = CkJsonObject_stringOf(jsonResponse,"lines.url");
    livemode = CkJsonObject_BoolOf(jsonResponse,"livemode");
    next_payment_attempt = CkJsonObject_IntOf(jsonResponse,"next_payment_attempt");
    number = CkJsonObject_stringOf(jsonResponse,"number");
    paid = CkJsonObject_BoolOf(jsonResponse,"paid");
    period_end = CkJsonObject_IntOf(jsonResponse,"period_end");
    period_start = CkJsonObject_IntOf(jsonResponse,"period_start");
    receipt_number = CkJsonObject_IsNullOf(jsonResponse,"receipt_number");
    starting_balance = CkJsonObject_IntOf(jsonResponse,"starting_balance");
    statement_descriptor = CkJsonObject_IsNullOf(jsonResponse,"statement_descriptor");
    subscription = CkJsonObject_IsNullOf(jsonResponse,"subscription");
    subtotal = CkJsonObject_IntOf(jsonResponse,"subtotal");
    tax = CkJsonObject_IsNullOf(jsonResponse,"tax");
    tax_percent = CkJsonObject_IsNullOf(jsonResponse,"tax_percent");
    total = CkJsonObject_IntOf(jsonResponse,"total");
    webhooks_delivered_at = CkJsonObject_IsNullOf(jsonResponse,"webhooks_delivered_at");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"lines.data");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        id = CkJsonObject_stringOf(jsonResponse,"lines.data[i].id");
        object = CkJsonObject_stringOf(jsonResponse,"lines.data[i].object");
        amount = CkJsonObject_IntOf(jsonResponse,"lines.data[i].amount");
        currency = CkJsonObject_stringOf(jsonResponse,"lines.data[i].currency");
        description_str = CkJsonObject_stringOf(jsonResponse,"lines.data[i].description");
        discountable = CkJsonObject_BoolOf(jsonResponse,"lines.data[i].discountable");
        livemode = CkJsonObject_BoolOf(jsonResponse,"lines.data[i].livemode");
        periodStart = CkJsonObject_IntOf(jsonResponse,"lines.data[i].period.start");
        periodEnd = CkJsonObject_IntOf(jsonResponse,"lines.data[i].period.end");
        plan = CkJsonObject_IsNullOf(jsonResponse,"lines.data[i].plan");
        proration = CkJsonObject_BoolOf(jsonResponse,"lines.data[i].proration");
        quantity = CkJsonObject_IsNullOf(jsonResponse,"lines.data[i].quantity");
        subscription = CkJsonObject_IsNullOf(jsonResponse,"lines.data[i].subscription");
        type = CkJsonObject_stringOf(jsonResponse,"lines.data[i].type");
        i = i + 1;
    }



    CkRest_Dispose(rest);
    CkJsonObject_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "id": "in_1BnETLGswQrCoh0XR7p1RCtV",
  "object": "invoice",
  "amount_due": 0,
  "application_fee": null,
  "attempt_count": 0,
  "attempted": false,
  "billing": "charge_automatically",
  "charge": null,
  "closed": false,
  "currency": "usd",
  "customer": "cus_CBbg9PmQ9sLbmo",
  "date": 1516662783,
  "description": null,
  "discount": null,
  "due_date": null,
  "ending_balance": null,
  "forgiven": false,
  "lines": {
    "data": [
      {
        "id": "ii_1BnETLGswQrCoh0XsAcSzoLf",
        "object": "line_item",
        "amount": 0,
        "currency": "usd",
        "description": "My First Invoice Item (created for API docs)",
        "discountable": true,
        "livemode": false,
        "metadata": {},
        "period": {
          "start": 1516662783,
          "end": 1516662783
        },
        "plan": null,
        "proration": false,
        "quantity": null,
        "subscription": null,
        "type": "invoiceitem"
      }
    ],
    "has_more": false,
    "object": "list",
    "url": "/v1/invoices/in_1BnETLGswQrCoh0XR7p1RCtV/lines"
  },
  "livemode": false,
  "metadata": {},
  "next_payment_attempt": 1516666383,
  "number": "36eba31eaa-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
}