Tcl Stripe: Update a Customer

Back to Index

Updates the specified customer by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

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

CURL Command

curl -X POST https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq \
   -u STRIPE_SECRET_KEY: \
   -d description="Customer for isabella.williams@example.com"

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq
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 "description" "Customer for isabella.williams@example.com"

set strResponseBody [CkRest_fullRequestFormUrlEncoded $rest "POST" "/v1/customers/cus_CBbgVLJqv487Oq"]
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 account_balance [CkJsonObject_IntOf $jsonResponse "account_balance"]
set created [CkJsonObject_IntOf $jsonResponse "created"]
set currency [CkJsonObject_stringOf $jsonResponse "currency"]
set default_source [CkJsonObject_IsNullOf $jsonResponse "default_source"]
set delinquent [CkJsonObject_BoolOf $jsonResponse "delinquent"]
set description [CkJsonObject_stringOf $jsonResponse "description"]
set discount [CkJsonObject_IsNullOf $jsonResponse "discount"]
set email [CkJsonObject_IsNullOf $jsonResponse "email"]
set livemode [CkJsonObject_BoolOf $jsonResponse "livemode"]
set shipping [CkJsonObject_IsNullOf $jsonResponse "shipping"]
set sourcesObject [CkJsonObject_stringOf $jsonResponse "sources.object"]
set sourcesHas_more [CkJsonObject_BoolOf $jsonResponse "sources.has_more"]
set sourcesTotal_count [CkJsonObject_IntOf $jsonResponse "sources.total_count"]
set sourcesUrl [CkJsonObject_stringOf $jsonResponse "sources.url"]
set subscriptionsObject [CkJsonObject_stringOf $jsonResponse "subscriptions.object"]
set subscriptionsHas_more [CkJsonObject_BoolOf $jsonResponse "subscriptions.has_more"]
set subscriptionsTotal_count [CkJsonObject_IntOf $jsonResponse "subscriptions.total_count"]
set subscriptionsUrl [CkJsonObject_stringOf $jsonResponse "subscriptions.url"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "sources.data"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "subscriptions.data"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set i [expr $i + 1]
}

delete_CkRest $rest
delete_CkJsonObject $jsonResponse

Sample JSON Response Body

{
  "id": "cus_CBbgVLJqv487Oq",
  "object": "customer",
  "account_balance": 0,
  "created": 1516662781,
  "currency": "usd",
  "default_source": null,
  "delinquent": false,
  "description": "Customer for isabella.williams@example.com",
  "discount": null,
  "email": null,
  "livemode": false,
  "metadata": {},
  "shipping": null,
  "sources": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/sources"
  },
  "subscriptions": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/subscriptions"
  }
}