Tcl 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

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "api.stripe.com" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

CkRest_SetAuthBasic $rest "STRIPE_SECRET_KEY" ""

CkRest_AddQueryParam $rest "closed" "true"

set strResponseBody [CkRest_fullRequestFormUrlEncoded $rest "POST" "/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c"]
if {[expr [CkRest_LastMethodSuccess $rest] != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_Load $jsonResponse $strResponseBody

set id [CkJsonObject_stringOf $jsonResponse "id"]
set object [CkJsonObject_stringOf $jsonResponse "object"]
set amount_due [CkJsonObject_IntOf $jsonResponse "amount_due"]
set application_fee [CkJsonObject_IsNullOf $jsonResponse "application_fee"]
set attempt_count [CkJsonObject_IntOf $jsonResponse "attempt_count"]
set attempted [CkJsonObject_BoolOf $jsonResponse "attempted"]
set billing [CkJsonObject_stringOf $jsonResponse "billing"]
set charge [CkJsonObject_IsNullOf $jsonResponse "charge"]
set closed [CkJsonObject_BoolOf $jsonResponse "closed"]
set currency [CkJsonObject_stringOf $jsonResponse "currency"]
set customer [CkJsonObject_stringOf $jsonResponse "customer"]
set date [CkJsonObject_IntOf $jsonResponse "date"]
set description [CkJsonObject_IsNullOf $jsonResponse "description"]
set discount [CkJsonObject_IsNullOf $jsonResponse "discount"]
set due_date [CkJsonObject_IsNullOf $jsonResponse "due_date"]
set ending_balance [CkJsonObject_IsNullOf $jsonResponse "ending_balance"]
set forgiven [CkJsonObject_BoolOf $jsonResponse "forgiven"]
set linesHas_more [CkJsonObject_BoolOf $jsonResponse "lines.has_more"]
set linesObject [CkJsonObject_stringOf $jsonResponse "lines.object"]
set linesUrl [CkJsonObject_stringOf $jsonResponse "lines.url"]
set livemode [CkJsonObject_BoolOf $jsonResponse "livemode"]
set next_payment_attempt [CkJsonObject_IntOf $jsonResponse "next_payment_attempt"]
set number [CkJsonObject_stringOf $jsonResponse "number"]
set paid [CkJsonObject_BoolOf $jsonResponse "paid"]
set period_end [CkJsonObject_IntOf $jsonResponse "period_end"]
set period_start [CkJsonObject_IntOf $jsonResponse "period_start"]
set receipt_number [CkJsonObject_IsNullOf $jsonResponse "receipt_number"]
set starting_balance [CkJsonObject_IntOf $jsonResponse "starting_balance"]
set statement_descriptor [CkJsonObject_IsNullOf $jsonResponse "statement_descriptor"]
set subscription [CkJsonObject_IsNullOf $jsonResponse "subscription"]
set subtotal [CkJsonObject_IntOf $jsonResponse "subtotal"]
set tax [CkJsonObject_IsNullOf $jsonResponse "tax"]
set tax_percent [CkJsonObject_IsNullOf $jsonResponse "tax_percent"]
set total [CkJsonObject_IntOf $jsonResponse "total"]
set webhooks_delivered_at [CkJsonObject_IsNullOf $jsonResponse "webhooks_delivered_at"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "lines.data"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set id [CkJsonObject_stringOf $jsonResponse "lines.data[i].id"]
    set object [CkJsonObject_stringOf $jsonResponse "lines.data[i].object"]
    set amount [CkJsonObject_IntOf $jsonResponse "lines.data[i].amount"]
    set currency [CkJsonObject_stringOf $jsonResponse "lines.data[i].currency"]
    set description_str [CkJsonObject_stringOf $jsonResponse "lines.data[i].description"]
    set discountable [CkJsonObject_BoolOf $jsonResponse "lines.data[i].discountable"]
    set livemode [CkJsonObject_BoolOf $jsonResponse "lines.data[i].livemode"]
    set periodStart [CkJsonObject_IntOf $jsonResponse "lines.data[i].period.start"]
    set periodEnd [CkJsonObject_IntOf $jsonResponse "lines.data[i].period.end"]
    set planId [CkJsonObject_stringOf $jsonResponse "lines.data[i].plan.id"]
    set planObject [CkJsonObject_stringOf $jsonResponse "lines.data[i].plan.object"]
    set planAmount [CkJsonObject_IntOf $jsonResponse "lines.data[i].plan.amount"]
    set planCreated [CkJsonObject_IntOf $jsonResponse "lines.data[i].plan.created"]
    set planCurrency [CkJsonObject_stringOf $jsonResponse "lines.data[i].plan.currency"]
    set planInterval [CkJsonObject_stringOf $jsonResponse "lines.data[i].plan.interval"]
    set planInterval_count [CkJsonObject_IntOf $jsonResponse "lines.data[i].plan.interval_count"]
    set planLivemode [CkJsonObject_BoolOf $jsonResponse "lines.data[i].plan.livemode"]
    set planName [CkJsonObject_stringOf $jsonResponse "lines.data[i].plan.name"]
    set planStatement_descriptor [CkJsonObject_IsNullOf $jsonResponse "lines.data[i].plan.statement_descriptor"]
    set planTrial_period_days [CkJsonObject_IsNullOf $jsonResponse "lines.data[i].plan.trial_period_days"]
    set proration [CkJsonObject_BoolOf $jsonResponse "lines.data[i].proration"]
    set quantity [CkJsonObject_IntOf $jsonResponse "lines.data[i].quantity"]
    set subscription [CkJsonObject_IsNullOf $jsonResponse "lines.data[i].subscription"]
    set subscription_item [CkJsonObject_stringOf $jsonResponse "lines.data[i].subscription_item"]
    set type [CkJsonObject_stringOf $jsonResponse "lines.data[i].type"]
    set i [expr $i + 1]
}

delete_CkRest $rest
delete_CkJsonObject $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
}