Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.7.0+

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL cApiKey
LOCAL cOperationId
LOCAL oCurl
LOCAL oCmd
LOCAL oJson
LOCAL nReplaced
LOCAL oBusinessName
LOCAL oEmail
LOCAL cAccountRef
LOCAL cCustomerId

nSuccess := 0

//  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
//  Supply a restricted sandbox key from merchant-controlled configuration.
cApiKey := "YOUR_STRIPE_TEST_KEY"
//  Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
cOperationId := "YOUR_SAVED_OPERATION_UUID"

oCurl := CreateObject("Chilkat.HttpCurl")
oCmd := CreateObject("Chilkat.StringBuilder")
oJson := CreateObject("Chilkat.JsonObject")

//  For an account already linked to Stripe, reuse its saved customer ID.

oBusinessName := CreateObject("Chilkat.StringBuilder")
oBusinessName:SetString("Acme & Sons")

oEmail := CreateObject("Chilkat.StringBuilder")
oEmail:SetString("billing+east@example.com")

cAccountRef := "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}"
oCmd:SetString('curl -X POST "https://api.stripe.com/v1/customers"')
oCmd:Append(' -u "@KEY@:"')
oCmd:Append(' -H "Stripe-Version: 2026-10-28.endive"')
oCmd:Append(' -H "Idempotency-Key: @OP@-customer"')
oCmd:Append(' -d "name=@NAME@"')
oCmd:Append(' -d "email=@EMAIL@"')
oCmd:Append(' -d "metadata[account_ref]=@REF@"')
nReplaced := oCmd:Replace("@NAME@", oBusinessName:GetEncoded("url_rfc3986", "utf-8"))
nReplaced := oCmd:Replace("@EMAIL@", oEmail:GetEncoded("url_rfc3986", "utf-8"))
nReplaced := oCmd:Replace("@REF@", cAccountRef)
nReplaced := oCmd:Replace("@OP@", cOperationId)
nReplaced := oCmd:Replace("@KEY@", cApiKey)
nSuccess := oCurl:DoYourThing(oCmd:GetAsString())
IF (nSuccess != 1)
    ? "No HTTP response. Chilkat failure code: " + Str(oCurl:FailReason)
    oCurl:destroy()
    oCmd:destroy()
    oJson:destroy()
    oBusinessName:destroy()
    oEmail:destroy()
    RETURN
ENDIF

nSuccess := oCurl:GetResponseJson(oJson)
IF ((oCurl:StatusCode != 200) .OR. (nSuccess != 1))
    ? "Stripe HTTP " + Str(oCurl:StatusCode) + "  Request-Id: " + oCurl:GetResponseHeaderField("Request-Id")
    IF (nSuccess == 1)
        ? oJson:StringOf("error.message")
    ENDIF

    oCurl:destroy()
    oCmd:destroy()
    oJson:destroy()
    oBusinessName:destroy()
    oEmail:destroy()
    RETURN
ENDIF

//  Save this string on the existing billing account after a successful create.
cCustomerId := oJson:StringOf("id")
? "Stripe customer: " + cCustomerId

oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oBusinessName:destroy()
oEmail:destroy()