PureBasic 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

PureBasic Example

IncludeFile "CkRest.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"api.stripe.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"STRIPE_SECRET_KEY","")

    CkRest::ckAddQueryParam(rest,"closed","true")

    strResponseBody.s = CkRest::ckFullRequestFormUrlEncoded(rest,"POST","/v1/invoices/in_1BnETLGswQrCoh0X6M67Qy9c")
    If CkRest::ckLastMethodSuccess(rest) <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(jsonResponse,strResponseBody)

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

    id = CkJsonObject::ckStringOf(jsonResponse,"id")
    object = CkJsonObject::ckStringOf(jsonResponse,"object")
    amount_due = CkJsonObject::ckIntOf(jsonResponse,"amount_due")
    application_fee = CkJsonObject::ckIsNullOf(jsonResponse,"application_fee")
    attempt_count = CkJsonObject::ckIntOf(jsonResponse,"attempt_count")
    attempted = CkJsonObject::ckBoolOf(jsonResponse,"attempted")
    billing = CkJsonObject::ckStringOf(jsonResponse,"billing")
    charge = CkJsonObject::ckIsNullOf(jsonResponse,"charge")
    closed = CkJsonObject::ckBoolOf(jsonResponse,"closed")
    currency = CkJsonObject::ckStringOf(jsonResponse,"currency")
    customer = CkJsonObject::ckStringOf(jsonResponse,"customer")
    date = CkJsonObject::ckIntOf(jsonResponse,"date")
    description = CkJsonObject::ckIsNullOf(jsonResponse,"description")
    discount = CkJsonObject::ckIsNullOf(jsonResponse,"discount")
    due_date = CkJsonObject::ckIsNullOf(jsonResponse,"due_date")
    ending_balance = CkJsonObject::ckIsNullOf(jsonResponse,"ending_balance")
    forgiven = CkJsonObject::ckBoolOf(jsonResponse,"forgiven")
    linesHas_more = CkJsonObject::ckBoolOf(jsonResponse,"lines.has_more")
    linesObject = CkJsonObject::ckStringOf(jsonResponse,"lines.object")
    linesUrl = CkJsonObject::ckStringOf(jsonResponse,"lines.url")
    livemode = CkJsonObject::ckBoolOf(jsonResponse,"livemode")
    next_payment_attempt = CkJsonObject::ckIntOf(jsonResponse,"next_payment_attempt")
    number = CkJsonObject::ckStringOf(jsonResponse,"number")
    paid = CkJsonObject::ckBoolOf(jsonResponse,"paid")
    period_end = CkJsonObject::ckIntOf(jsonResponse,"period_end")
    period_start = CkJsonObject::ckIntOf(jsonResponse,"period_start")
    receipt_number = CkJsonObject::ckIsNullOf(jsonResponse,"receipt_number")
    starting_balance = CkJsonObject::ckIntOf(jsonResponse,"starting_balance")
    statement_descriptor = CkJsonObject::ckIsNullOf(jsonResponse,"statement_descriptor")
    subscription = CkJsonObject::ckIsNullOf(jsonResponse,"subscription")
    subtotal = CkJsonObject::ckIntOf(jsonResponse,"subtotal")
    tax = CkJsonObject::ckIsNullOf(jsonResponse,"tax")
    tax_percent = CkJsonObject::ckIsNullOf(jsonResponse,"tax_percent")
    total = CkJsonObject::ckIntOf(jsonResponse,"total")
    webhooks_delivered_at = CkJsonObject::ckIsNullOf(jsonResponse,"webhooks_delivered_at")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"lines.data")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        id = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].id")
        object = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].object")
        amount = CkJsonObject::ckIntOf(jsonResponse,"lines.data[i].amount")
        currency = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].currency")
        description_str = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].description")
        discountable = CkJsonObject::ckBoolOf(jsonResponse,"lines.data[i].discountable")
        livemode = CkJsonObject::ckBoolOf(jsonResponse,"lines.data[i].livemode")
        periodStart = CkJsonObject::ckIntOf(jsonResponse,"lines.data[i].period.start")
        periodEnd = CkJsonObject::ckIntOf(jsonResponse,"lines.data[i].period.end")
        planId = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].plan.id")
        planObject = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].plan.object")
        planAmount = CkJsonObject::ckIntOf(jsonResponse,"lines.data[i].plan.amount")
        planCreated = CkJsonObject::ckIntOf(jsonResponse,"lines.data[i].plan.created")
        planCurrency = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].plan.currency")
        planInterval = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].plan.interval")
        planInterval_count = CkJsonObject::ckIntOf(jsonResponse,"lines.data[i].plan.interval_count")
        planLivemode = CkJsonObject::ckBoolOf(jsonResponse,"lines.data[i].plan.livemode")
        planName = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].plan.name")
        planStatement_descriptor = CkJsonObject::ckIsNullOf(jsonResponse,"lines.data[i].plan.statement_descriptor")
        planTrial_period_days = CkJsonObject::ckIsNullOf(jsonResponse,"lines.data[i].plan.trial_period_days")
        proration = CkJsonObject::ckBoolOf(jsonResponse,"lines.data[i].proration")
        quantity = CkJsonObject::ckIntOf(jsonResponse,"lines.data[i].quantity")
        subscription = CkJsonObject::ckIsNullOf(jsonResponse,"lines.data[i].subscription")
        subscription_item = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].subscription_item")
        type = CkJsonObject::ckStringOf(jsonResponse,"lines.data[i].type")
        i = i + 1
    Wend


    CkRest::ckDispose(rest)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

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
}