SQL Server Stripe: Retrieve an Invoice

Back to Index

Retrieves the invoice with the given ID.

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

CURL Command

curl https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0XR7p1RCtV \
   -u STRIPE_SECRET_KEY:

SQL Server Example

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  URL: https://api.stripe.com/v1/invoices/in_1BnETLGswQrCoh0XR7p1RCtV
    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @port int
    SELECT @port = 443
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'api.stripe.com', STR(@port), STR(@bTls), STR(@bAutoReconnect)
    IF STR(@success) <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    EXEC sp_OAMethod @rest, 'SetAuthBasic', @success OUT, 'STRIPE_SECRET_KEY', ''

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/v1/invoices/in_1BnETLGswQrCoh0XR7p1RCtV', STR(@sbResponseBody)
    IF STR(@success) <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jsonResponse int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonResponse OUT

    EXEC sp_OAMethod @jsonResponse, 'LoadSb', @success OUT, STR(@sbResponseBody)

    DECLARE @id nvarchar(4000)

    DECLARE @object nvarchar(4000)

    DECLARE @amount_due int

    DECLARE @application_fee int

    DECLARE @attempt_count int

    DECLARE @attempted int

    DECLARE @billing nvarchar(4000)

    DECLARE @charge int

    DECLARE @closed int

    DECLARE @currency nvarchar(4000)

    DECLARE @customer nvarchar(4000)

    DECLARE @date int

    DECLARE @description int

    DECLARE @discount int

    DECLARE @due_date int

    DECLARE @ending_balance int

    DECLARE @forgiven int

    DECLARE @linesHas_more int

    DECLARE @linesObject nvarchar(4000)

    DECLARE @linesUrl nvarchar(4000)

    DECLARE @livemode int

    DECLARE @next_payment_attempt int

    DECLARE @number nvarchar(4000)

    DECLARE @paid int

    DECLARE @period_end int

    DECLARE @period_start int

    DECLARE @receipt_number int

    DECLARE @starting_balance int

    DECLARE @statement_descriptor int

    DECLARE @subscription int

    DECLARE @subtotal int

    DECLARE @tax int

    DECLARE @tax_percent int

    DECLARE @total int

    DECLARE @webhooks_delivered_at int

    DECLARE @i int

    DECLARE @count_i int

    DECLARE @amount int

    DECLARE @description_str nvarchar(4000)

    DECLARE @discountable int

    DECLARE @periodStart int

    DECLARE @periodEnd int

    DECLARE @planId nvarchar(4000)

    DECLARE @planObject nvarchar(4000)

    DECLARE @planAmount int

    DECLARE @planCreated int

    DECLARE @planCurrency nvarchar(4000)

    DECLARE @planInterval nvarchar(4000)

    DECLARE @planInterval_count int

    DECLARE @planLivemode int

    DECLARE @planName nvarchar(4000)

    DECLARE @planStatement_descriptor int

    DECLARE @planTrial_period_days int

    DECLARE @proration int

    DECLARE @quantity int

    DECLARE @subscription_item nvarchar(4000)

    DECLARE @type nvarchar(4000)

    EXEC sp_OAMethod @jsonResponse, 'StringOf', @id OUT, 'id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @object OUT, 'object'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @amount_due OUT, 'amount_due'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @application_fee OUT, 'application_fee'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @attempt_count OUT, 'attempt_count'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @attempted OUT, 'attempted'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @billing OUT, 'billing'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @charge OUT, 'charge'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @closed OUT, 'closed'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @currency OUT, 'currency'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @customer OUT, 'customer'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @date OUT, 'date'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @description OUT, 'description'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @discount OUT, 'discount'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @due_date OUT, 'due_date'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @ending_balance OUT, 'ending_balance'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @forgiven OUT, 'forgiven'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @linesHas_more OUT, 'lines.has_more'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @linesObject OUT, 'lines.object'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @linesUrl OUT, 'lines.url'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @livemode OUT, 'livemode'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @next_payment_attempt OUT, 'next_payment_attempt'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @number OUT, 'number'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @paid OUT, 'paid'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @period_end OUT, 'period_end'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @period_start OUT, 'period_start'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @receipt_number OUT, 'receipt_number'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @starting_balance OUT, 'starting_balance'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @statement_descriptor OUT, 'statement_descriptor'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @subscription OUT, 'subscription'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @subtotal OUT, 'subtotal'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @tax OUT, 'tax'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @tax_percent OUT, 'tax_percent'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @total OUT, 'total'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @webhooks_delivered_at OUT, 'webhooks_delivered_at'
    SELECT @i = 0
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'lines.data'
    WHILE STR(@i) < STR(@count_i)
      BEGIN
        EXEC sp_OASetProperty @jsonResponse, 'I', STR(@i)
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @id OUT, 'lines.data[i].id'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @object OUT, 'lines.data[i].object'
        EXEC sp_OAMethod @jsonResponse, 'IntOf', @amount OUT, 'lines.data[i].amount'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @currency OUT, 'lines.data[i].currency'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @description_str OUT, 'lines.data[i].description'
        EXEC sp_OAMethod @jsonResponse, 'BoolOf', @discountable OUT, 'lines.data[i].discountable'
        EXEC sp_OAMethod @jsonResponse, 'BoolOf', @livemode OUT, 'lines.data[i].livemode'
        EXEC sp_OAMethod @jsonResponse, 'IntOf', @periodStart OUT, 'lines.data[i].period.start'
        EXEC sp_OAMethod @jsonResponse, 'IntOf', @periodEnd OUT, 'lines.data[i].period.end'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @planId OUT, 'lines.data[i].plan.id'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @planObject OUT, 'lines.data[i].plan.object'
        EXEC sp_OAMethod @jsonResponse, 'IntOf', @planAmount OUT, 'lines.data[i].plan.amount'
        EXEC sp_OAMethod @jsonResponse, 'IntOf', @planCreated OUT, 'lines.data[i].plan.created'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @planCurrency OUT, 'lines.data[i].plan.currency'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @planInterval OUT, 'lines.data[i].plan.interval'
        EXEC sp_OAMethod @jsonResponse, 'IntOf', @planInterval_count OUT, 'lines.data[i].plan.interval_count'
        EXEC sp_OAMethod @jsonResponse, 'BoolOf', @planLivemode OUT, 'lines.data[i].plan.livemode'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @planName OUT, 'lines.data[i].plan.name'
        EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @planStatement_descriptor OUT, 'lines.data[i].plan.statement_descriptor'
        EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @planTrial_period_days OUT, 'lines.data[i].plan.trial_period_days'
        EXEC sp_OAMethod @jsonResponse, 'BoolOf', @proration OUT, 'lines.data[i].proration'
        EXEC sp_OAMethod @jsonResponse, 'IntOf', @quantity OUT, 'lines.data[i].quantity'
        EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @subscription OUT, 'lines.data[i].subscription'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @subscription_item OUT, 'lines.data[i].subscription_item'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @type OUT, 'lines.data[i].type'
        SELECT @i = STR(@i) + 1
      END

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jsonResponse


END
GO

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": "sub_CBbgnZGMJwa9ta",
        "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_CBbgiJ7hAAGzMF",
        "type": "subscription"
      }
    ],
    "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
}