Visual FoxPro 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"

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL lcStrResponseBody
LOCAL loJsonResponse
LOCAL lcId
LOCAL lcObject
LOCAL lnAccount_balance
LOCAL lnCreated
LOCAL lcCurrency
LOCAL lnDefault_source
LOCAL lnDelinquent
LOCAL lcDescription
LOCAL lnDiscount
LOCAL lnEmail
LOCAL lnLivemode
LOCAL lnShipping
LOCAL lcSourcesObject
LOCAL lnSourcesHas_more
LOCAL lnSourcesTotal_count
LOCAL lcSourcesUrl
LOCAL lcSubscriptionsObject
LOCAL lnSubscriptionsHas_more
LOCAL lnSubscriptionsTotal_count
LOCAL lcSubscriptionsUrl
LOCAL i
LOCAL lnCount_i

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.stripe.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("STRIPE_SECRET_KEY","")

loRest.AddQueryParam("description","Customer for isabella.williams@example.com")

lcStrResponseBody = loRest.FullRequestFormUrlEncoded("POST","/v1/customers/cus_CBbgVLJqv487Oq")
IF (loRest.LastMethodSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.Load(lcStrResponseBody)

lcId = loJsonResponse.StringOf("id")
lcObject = loJsonResponse.StringOf("object")
lnAccount_balance = loJsonResponse.IntOf("account_balance")
lnCreated = loJsonResponse.IntOf("created")
lcCurrency = loJsonResponse.StringOf("currency")
lnDefault_source = loJsonResponse.IsNullOf("default_source")
lnDelinquent = loJsonResponse.BoolOf("delinquent")
lcDescription = loJsonResponse.StringOf("description")
lnDiscount = loJsonResponse.IsNullOf("discount")
lnEmail = loJsonResponse.IsNullOf("email")
lnLivemode = loJsonResponse.BoolOf("livemode")
lnShipping = loJsonResponse.IsNullOf("shipping")
lcSourcesObject = loJsonResponse.StringOf("sources.object")
lnSourcesHas_more = loJsonResponse.BoolOf("sources.has_more")
lnSourcesTotal_count = loJsonResponse.IntOf("sources.total_count")
lcSourcesUrl = loJsonResponse.StringOf("sources.url")
lcSubscriptionsObject = loJsonResponse.StringOf("subscriptions.object")
lnSubscriptionsHas_more = loJsonResponse.BoolOf("subscriptions.has_more")
lnSubscriptionsTotal_count = loJsonResponse.IntOf("subscriptions.total_count")
lcSubscriptionsUrl = loJsonResponse.StringOf("subscriptions.url")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("sources.data")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("subscriptions.data")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loJsonResponse

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