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

PowerBuilder Example

integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
string ls_StrResponseBody
oleobject loo_JsonResponse
string ls_Id
string ls_Object
integer li_Account_balance
integer li_Created
string ls_Currency
integer li_Default_source
integer li_Delinquent
string ls_Description
integer li_Discount
integer li_Email
integer li_Livemode
integer li_Shipping
string ls_SourcesObject
integer li_SourcesHas_more
integer li_SourcesTotal_count
string ls_SourcesUrl
string ls_SubscriptionsObject
integer li_SubscriptionsHas_more
integer li_SubscriptionsTotal_count
string ls_SubscriptionsUrl
integer i
integer li_Count_i

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  URL: https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("api.stripe.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_Rest.SetAuthBasic("STRIPE_SECRET_KEY","")

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

ls_StrResponseBody = loo_Rest.FullRequestFormUrlEncoded("POST","/v1/customers/cus_CBbgVLJqv487Oq")
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResponse.Load(ls_StrResponseBody)

ls_Id = loo_JsonResponse.StringOf("id")
ls_Object = loo_JsonResponse.StringOf("object")
li_Account_balance = loo_JsonResponse.IntOf("account_balance")
li_Created = loo_JsonResponse.IntOf("created")
ls_Currency = loo_JsonResponse.StringOf("currency")
li_Default_source = loo_JsonResponse.IsNullOf("default_source")
li_Delinquent = loo_JsonResponse.BoolOf("delinquent")
ls_Description = loo_JsonResponse.StringOf("description")
li_Discount = loo_JsonResponse.IsNullOf("discount")
li_Email = loo_JsonResponse.IsNullOf("email")
li_Livemode = loo_JsonResponse.BoolOf("livemode")
li_Shipping = loo_JsonResponse.IsNullOf("shipping")
ls_SourcesObject = loo_JsonResponse.StringOf("sources.object")
li_SourcesHas_more = loo_JsonResponse.BoolOf("sources.has_more")
li_SourcesTotal_count = loo_JsonResponse.IntOf("sources.total_count")
ls_SourcesUrl = loo_JsonResponse.StringOf("sources.url")
ls_SubscriptionsObject = loo_JsonResponse.StringOf("subscriptions.object")
li_SubscriptionsHas_more = loo_JsonResponse.BoolOf("subscriptions.has_more")
li_SubscriptionsTotal_count = loo_JsonResponse.IntOf("subscriptions.total_count")
ls_SubscriptionsUrl = loo_JsonResponse.StringOf("subscriptions.url")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("sources.data")
do while i < li_Count_i
    loo_JsonResponse.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("subscriptions.data")
do while i < li_Count_i
    loo_JsonResponse.I = i
    i = i + 1
loop


destroy loo_Rest
destroy loo_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"
  }
}