Tcl Stripe: Retrieve a charge

Back to Index

Retrieves the details of a charge that has previously been created.

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

CURL Command

curl https://api.stripe.com/v1/charges/ch_1BnETJGswQrCoh0XTs0EERBj \
   -u STRIPE_SECRET_KEY:

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

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

delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse

Sample JSON Response Body

{
  "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
}