PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
Stripe: Create a Stripe Customer for an Existing Billing Account
See more Stripe Examples
Create a Stripe Customer for a local billing account. Send its internal reference in metadata and read the customer ID to save with that account.
Stripe documentation and cURL example
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
string ls_ApiKey
string ls_OperationId
oleobject loo_Curl
oleobject loo_Cmd
oleobject loo_Json
long li_Replaced
oleobject loo_BusinessName
oleobject loo_Email
string ls_AccountRef
string ls_CustomerId
li_Success = 0
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
ls_ApiKey = "YOUR_STRIPE_TEST_KEY"
// Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
ls_OperationId = "YOUR_SAVED_OPERATION_UUID"
loo_Curl = create oleobject
li_rc = loo_Curl.ConnectToNewObject("Chilkat.HttpCurl")
if li_rc < 0 then
destroy loo_Curl
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Cmd = create oleobject
li_rc = loo_Cmd.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
// For an account already linked to Stripe, reuse its saved customer ID.
loo_BusinessName = create oleobject
li_rc = loo_BusinessName.ConnectToNewObject("Chilkat.StringBuilder")
loo_BusinessName.SetString("Acme & Sons")
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.StringBuilder")
loo_Email.SetString("billing+east@example.com")
ls_AccountRef = "ACME-1042"
// curl -X POST "https://api.stripe.com/v1/customers" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -H "Idempotency-Key: {operationId}-customer" \
// -d "name={businessName}" \
// -d "email={email}" \
// -d "metadata[account_ref]={accountRef}"
loo_Cmd.SetString("curl -X POST ~"https://api.stripe.com/v1/customers~"")
loo_Cmd.Append(" -u ~"@KEY@:~"")
loo_Cmd.Append(" -H ~"Stripe-Version: 2026-10-28.endive~"")
loo_Cmd.Append(" -H ~"Idempotency-Key: @OP@-customer~"")
loo_Cmd.Append(" -d ~"name=@NAME@~"")
loo_Cmd.Append(" -d ~"email=@EMAIL@~"")
loo_Cmd.Append(" -d ~"metadata[account_ref]=@REF@~"")
li_Replaced = loo_Cmd.Replace("@NAME@",loo_BusinessName.GetEncoded("url_rfc3986","utf-8"))
li_Replaced = loo_Cmd.Replace("@EMAIL@",loo_Email.GetEncoded("url_rfc3986","utf-8"))
li_Replaced = loo_Cmd.Replace("@REF@",ls_AccountRef)
li_Replaced = loo_Cmd.Replace("@OP@",ls_OperationId)
li_Replaced = loo_Cmd.Replace("@KEY@",ls_ApiKey)
li_Success = loo_Curl.DoYourThing(loo_Cmd.GetAsString())
if li_Success <> 1 then
Write-Debug "No HTTP response. Chilkat failure code: " + string(loo_Curl.FailReason)
destroy loo_Curl
destroy loo_Cmd
destroy loo_Json
destroy loo_BusinessName
destroy loo_Email
return
end if
li_Success = loo_Curl.GetResponseJson(loo_Json)
if (loo_Curl.StatusCode <> 200) OR (li_Success <> 1) then
Write-Debug "Stripe HTTP " + string(loo_Curl.StatusCode) + " Request-Id: " + loo_Curl.GetResponseHeaderField("Request-Id")
if li_Success = 1 then
Write-Debug loo_Json.StringOf("error.message")
end if
destroy loo_Curl
destroy loo_Cmd
destroy loo_Json
destroy loo_BusinessName
destroy loo_Email
return
end if
// Save this string on the existing billing account after a successful create.
ls_CustomerId = loo_Json.StringOf("id")
Write-Debug "Stripe customer: " + ls_CustomerId
destroy loo_Curl
destroy loo_Cmd
destroy loo_Json
destroy loo_BusinessName
destroy loo_Email