Tcl Stripe: List all Charges

Back to Index

Returns a list of charges you’ve previously created. The charges are returned in sorted order, with the most recent charges appearing first.

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

CURL Command

curl https://api.stripe.com/v1/charges?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.stripe.com/v1/charges?limit=3
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" ""

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/v1/charges?limit=3" $sbResponseBody]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_LoadSb $jsonResponse $sbResponseBody

set object [CkJsonObject_stringOf $jsonResponse "object"]
set url [CkJsonObject_stringOf $jsonResponse "url"]
set has_more [CkJsonObject_BoolOf $jsonResponse "has_more"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "data"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set id [CkJsonObject_stringOf $jsonResponse "data[i].id"]
    set object [CkJsonObject_stringOf $jsonResponse "data[i].object"]
    set amount [CkJsonObject_IntOf $jsonResponse "data[i].amount"]
    set amount_refunded [CkJsonObject_IntOf $jsonResponse "data[i].amount_refunded"]
    set application [CkJsonObject_IsNullOf $jsonResponse "data[i].application"]
    set application_fee [CkJsonObject_IsNullOf $jsonResponse "data[i].application_fee"]
    set balance_transaction [CkJsonObject_stringOf $jsonResponse "data[i].balance_transaction"]
    set captured [CkJsonObject_BoolOf $jsonResponse "data[i].captured"]
    set created [CkJsonObject_IntOf $jsonResponse "data[i].created"]
    set currency [CkJsonObject_stringOf $jsonResponse "data[i].currency"]
    set customer [CkJsonObject_IsNullOf $jsonResponse "data[i].customer"]
    set description [CkJsonObject_stringOf $jsonResponse "data[i].description"]
    set destination [CkJsonObject_IsNullOf $jsonResponse "data[i].destination"]
    set dispute [CkJsonObject_IsNullOf $jsonResponse "data[i].dispute"]
    set failure_code [CkJsonObject_IsNullOf $jsonResponse "data[i].failure_code"]
    set failure_message [CkJsonObject_IsNullOf $jsonResponse "data[i].failure_message"]
    set invoice [CkJsonObject_IsNullOf $jsonResponse "data[i].invoice"]
    set livemode [CkJsonObject_BoolOf $jsonResponse "data[i].livemode"]
    set on_behalf_of [CkJsonObject_IsNullOf $jsonResponse "data[i].on_behalf_of"]
    set order [CkJsonObject_IsNullOf $jsonResponse "data[i].order"]
    set outcome [CkJsonObject_IsNullOf $jsonResponse "data[i].outcome"]
    set paid [CkJsonObject_BoolOf $jsonResponse "data[i].paid"]
    set receipt_email [CkJsonObject_IsNullOf $jsonResponse "data[i].receipt_email"]
    set receipt_number [CkJsonObject_IsNullOf $jsonResponse "data[i].receipt_number"]
    set refunded [CkJsonObject_BoolOf $jsonResponse "data[i].refunded"]
    set refundsObject [CkJsonObject_stringOf $jsonResponse "data[i].refunds.object"]
    set refundsHas_more [CkJsonObject_BoolOf $jsonResponse "data[i].refunds.has_more"]
    set refundsTotal_count [CkJsonObject_IntOf $jsonResponse "data[i].refunds.total_count"]
    set refundsUrl [CkJsonObject_stringOf $jsonResponse "data[i].refunds.url"]
    set review [CkJsonObject_IsNullOf $jsonResponse "data[i].review"]
    set shipping [CkJsonObject_IsNullOf $jsonResponse "data[i].shipping"]
    set sourceId [CkJsonObject_stringOf $jsonResponse "data[i].source.id"]
    set sourceObject [CkJsonObject_stringOf $jsonResponse "data[i].source.object"]
    set sourceAddress_city [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_city"]
    set sourceAddress_country [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_country"]
    set sourceAddress_line1 [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_line1"]
    set sourceAddress_line1_check [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_line1_check"]
    set sourceAddress_line2 [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_line2"]
    set sourceAddress_state [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_state"]
    set sourceAddress_zip [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_zip"]
    set sourceAddress_zip_check [CkJsonObject_IsNullOf $jsonResponse "data[i].source.address_zip_check"]
    set sourceBrand [CkJsonObject_stringOf $jsonResponse "data[i].source.brand"]
    set sourceCountry [CkJsonObject_stringOf $jsonResponse "data[i].source.country"]
    set sourceCustomer [CkJsonObject_IsNullOf $jsonResponse "data[i].source.customer"]
    set sourceCvc_check [CkJsonObject_IsNullOf $jsonResponse "data[i].source.cvc_check"]
    set sourceDynamic_last4 [CkJsonObject_IsNullOf $jsonResponse "data[i].source.dynamic_last4"]
    set sourceExp_month [CkJsonObject_IntOf $jsonResponse "data[i].source.exp_month"]
    set sourceExp_year [CkJsonObject_IntOf $jsonResponse "data[i].source.exp_year"]
    set sourceFingerprint [CkJsonObject_stringOf $jsonResponse "data[i].source.fingerprint"]
    set sourceFunding [CkJsonObject_stringOf $jsonResponse "data[i].source.funding"]
    set sourceLast4 [CkJsonObject_stringOf $jsonResponse "data[i].source.last4"]
    set sourceName [CkJsonObject_IsNullOf $jsonResponse "data[i].source.name"]
    set sourceTokenization_method [CkJsonObject_IsNullOf $jsonResponse "data[i].source.tokenization_method"]
    set source_transfer [CkJsonObject_IsNullOf $jsonResponse "data[i].source_transfer"]
    set statement_descriptor [CkJsonObject_IsNullOf $jsonResponse "data[i].statement_descriptor"]
    set status [CkJsonObject_stringOf $jsonResponse "data[i].status"]
    set transfer_group [CkJsonObject_IsNullOf $jsonResponse "data[i].transfer_group"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jsonResponse "data[i].refunds.data"]
    while {[expr $j < $count_j]} {
        CkJsonObject_put_J $jsonResponse $j
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/charges",
  "has_more": false,
  "data": [
    {
      "id": "ch_1BnETJGswQrCoh0XTs0EERBj",
      "object": "charge",
      "amount": 100,
      "amount_refunded": 0,
      "application": null,
      "application_fee": null,
      "balance_transaction": "txn_1BnETJGswQrCoh0XxO2tGYr7",
      "captured": false,
      "created": 1516662781,
      "currency": "usd",
      "customer": null,
      "description": "My First Test Charge (created for API docs)",
      "destination": null,
      "dispute": null,
      "failure_code": null,
      "failure_message": null,
      "fraud_details": {},
      "invoice": null,
      "livemode": false,
      "metadata": {},
      "on_behalf_of": null,
      "order": null,
      "outcome": null,
      "paid": true,
      "receipt_email": null,
      "receipt_number": null,
      "refunded": false,
      "refunds": {
        "object": "list",
        "data": [
        ],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj/refunds"
      },
      "review": null,
      "shipping": null,
      "source": {
        "id": "card_18ropuGswQrCoh0XjCJ5Zvma",
        "object": "card",
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": null,
        "address_zip_check": null,
        "brand": "Visa",
        "country": "US",
        "customer": null,
        "cvc_check": null,
        "dynamic_last4": null,
        "exp_month": 8,
        "exp_year": 2017,
        "fingerprint": "F9mANtIt1TaukpRJ",
        "funding": "credit",
        "last4": "4242",
        "metadata": {},
        "name": null,
        "tokenization_method": null
      },
      "source_transfer": null,
      "statement_descriptor": null,
      "status": "succeeded",
      "transfer_group": null
    }
  ]
}