Unicode C Stripe: Update an Invoice

Back to Index

Updates an invoice.

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

CURL Command

curl https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c \
   -u STRIPE_SECRET_KEY: \
   -d closed=true \
   -X POST

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const wchar_t *strResponseBody;
    HCkJsonObjectW jsonResponse;
    const wchar_t *id;
    const wchar_t *object;
    int amount_due;
    BOOL application_fee;
    int attempt_count;
    BOOL attempted;
    const wchar_t *billing;
    BOOL charge;
    BOOL closed;
    const wchar_t *currency;
    const wchar_t *customer;
    int date;
    BOOL description;
    BOOL discount;
    BOOL due_date;
    BOOL ending_balance;
    BOOL forgiven;
    BOOL linesHas_more;
    const wchar_t *linesObject;
    const wchar_t *linesUrl;
    BOOL livemode;
    int next_payment_attempt;
    const wchar_t *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 wchar_t *description_str;
    BOOL discountable;
    int periodStart;
    int periodEnd;
    const wchar_t *planId;
    const wchar_t *planObject;
    int planAmount;
    int planCreated;
    const wchar_t *planCurrency;
    const wchar_t *planInterval;
    int planInterval_count;
    BOOL planLivemode;
    const wchar_t *planName;
    BOOL planStatement_descriptor;
    BOOL planTrial_period_days;
    BOOL proration;
    int quantity;
    const wchar_t *subscription_item;
    const wchar_t *type;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"STRIPE_SECRET_KEY",L"");

    CkRestW_AddQueryParam(rest,L"closed",L"true");

    strResponseBody = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c");
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_Load(jsonResponse,strResponseBody);

    id = CkJsonObjectW_stringOf(jsonResponse,L"id");
    object = CkJsonObjectW_stringOf(jsonResponse,L"object");
    amount_due = CkJsonObjectW_IntOf(jsonResponse,L"amount_due");
    application_fee = CkJsonObjectW_IsNullOf(jsonResponse,L"application_fee");
    attempt_count = CkJsonObjectW_IntOf(jsonResponse,L"attempt_count");
    attempted = CkJsonObjectW_BoolOf(jsonResponse,L"attempted");
    billing = CkJsonObjectW_stringOf(jsonResponse,L"billing");
    charge = CkJsonObjectW_IsNullOf(jsonResponse,L"charge");
    closed = CkJsonObjectW_BoolOf(jsonResponse,L"closed");
    currency = CkJsonObjectW_stringOf(jsonResponse,L"currency");
    customer = CkJsonObjectW_stringOf(jsonResponse,L"customer");
    date = CkJsonObjectW_IntOf(jsonResponse,L"date");
    description = CkJsonObjectW_IsNullOf(jsonResponse,L"description");
    discount = CkJsonObjectW_IsNullOf(jsonResponse,L"discount");
    due_date = CkJsonObjectW_IsNullOf(jsonResponse,L"due_date");
    ending_balance = CkJsonObjectW_IsNullOf(jsonResponse,L"ending_balance");
    forgiven = CkJsonObjectW_BoolOf(jsonResponse,L"forgiven");
    linesHas_more = CkJsonObjectW_BoolOf(jsonResponse,L"lines.has_more");
    linesObject = CkJsonObjectW_stringOf(jsonResponse,L"lines.object");
    linesUrl = CkJsonObjectW_stringOf(jsonResponse,L"lines.url");
    livemode = CkJsonObjectW_BoolOf(jsonResponse,L"livemode");
    next_payment_attempt = CkJsonObjectW_IntOf(jsonResponse,L"next_payment_attempt");
    number = CkJsonObjectW_stringOf(jsonResponse,L"number");
    paid = CkJsonObjectW_BoolOf(jsonResponse,L"paid");
    period_end = CkJsonObjectW_IntOf(jsonResponse,L"period_end");
    period_start = CkJsonObjectW_IntOf(jsonResponse,L"period_start");
    receipt_number = CkJsonObjectW_IsNullOf(jsonResponse,L"receipt_number");
    starting_balance = CkJsonObjectW_IntOf(jsonResponse,L"starting_balance");
    statement_descriptor = CkJsonObjectW_IsNullOf(jsonResponse,L"statement_descriptor");
    subscription = CkJsonObjectW_IsNullOf(jsonResponse,L"subscription");
    subtotal = CkJsonObjectW_IntOf(jsonResponse,L"subtotal");
    tax = CkJsonObjectW_IsNullOf(jsonResponse,L"tax");
    tax_percent = CkJsonObjectW_IsNullOf(jsonResponse,L"tax_percent");
    total = CkJsonObjectW_IntOf(jsonResponse,L"total");
    webhooks_delivered_at = CkJsonObjectW_IsNullOf(jsonResponse,L"webhooks_delivered_at");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"lines.data");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        id = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].id");
        object = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].object");
        amount = CkJsonObjectW_IntOf(jsonResponse,L"lines.data[i].amount");
        currency = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].currency");
        description_str = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].description");
        discountable = CkJsonObjectW_BoolOf(jsonResponse,L"lines.data[i].discountable");
        livemode = CkJsonObjectW_BoolOf(jsonResponse,L"lines.data[i].livemode");
        periodStart = CkJsonObjectW_IntOf(jsonResponse,L"lines.data[i].period.start");
        periodEnd = CkJsonObjectW_IntOf(jsonResponse,L"lines.data[i].period.end");
        planId = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].plan.id");
        planObject = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].plan.object");
        planAmount = CkJsonObjectW_IntOf(jsonResponse,L"lines.data[i].plan.amount");
        planCreated = CkJsonObjectW_IntOf(jsonResponse,L"lines.data[i].plan.created");
        planCurrency = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].plan.currency");
        planInterval = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].plan.interval");
        planInterval_count = CkJsonObjectW_IntOf(jsonResponse,L"lines.data[i].plan.interval_count");
        planLivemode = CkJsonObjectW_BoolOf(jsonResponse,L"lines.data[i].plan.livemode");
        planName = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].plan.name");
        planStatement_descriptor = CkJsonObjectW_IsNullOf(jsonResponse,L"lines.data[i].plan.statement_descriptor");
        planTrial_period_days = CkJsonObjectW_IsNullOf(jsonResponse,L"lines.data[i].plan.trial_period_days");
        proration = CkJsonObjectW_BoolOf(jsonResponse,L"lines.data[i].proration");
        quantity = CkJsonObjectW_IntOf(jsonResponse,L"lines.data[i].quantity");
        subscription = CkJsonObjectW_IsNullOf(jsonResponse,L"lines.data[i].subscription");
        subscription_item = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].subscription_item");
        type = CkJsonObjectW_stringOf(jsonResponse,L"lines.data[i].type");
        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "id": "in_1BnETLGswQrCoh0X6M67Qy9c",
  "object": "invoice",
  "amount_due": 0,
  "application_fee": null,
  "attempt_count": 0,
  "attempted": false,
  "billing": "charge_automatically",
  "charge": null,
  "closed": true,
  "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
}