Sample code for 30+ languages & platforms
DataFlex 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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String sApiKey
    String sOperationId
    Handle hoCurl
    Handle hoCmd
    Variant vJson
    Handle hoJson
    Integer iReplaced
    Handle hoBusinessName
    Handle hoEmail
    String sAccountRef
    String sCustomerId
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttpCurl)) To hoCurl
    If (Not(IsComObjectCreated(hoCurl))) Begin
        Send CreateComObject of hoCurl
    End
    Get Create (RefClass(cComChilkatStringBuilder)) To hoCmd
    If (Not(IsComObjectCreated(hoCmd))) Begin
        Send CreateComObject of hoCmd
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End

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

    Get Create (RefClass(cComChilkatStringBuilder)) To hoBusinessName
    If (Not(IsComObjectCreated(hoBusinessName))) Begin
        Send CreateComObject of hoBusinessName
    End
    Get ComSetString Of hoBusinessName "Acme & Sons" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Get ComSetString Of hoEmail "billing+east@example.com" To iSuccess

    Move "ACME-1042" To sAccountRef

    //  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}"
    Get ComSetString Of hoCmd 'curl -X POST "https://api.stripe.com/v1/customers"' To iSuccess
    Get ComAppend Of hoCmd ' -u "@KEY@:"' To iSuccess
    Get ComAppend Of hoCmd ' -H "Stripe-Version: 2026-10-28.endive"' To iSuccess
    Get ComAppend Of hoCmd ' -H "Idempotency-Key: @OP@-customer"' To iSuccess
    Get ComAppend Of hoCmd ' -d "name=@NAME@"' To iSuccess
    Get ComAppend Of hoCmd ' -d "email=@EMAIL@"' To iSuccess
    Get ComAppend Of hoCmd ' -d "metadata[account_ref]=@REF@"' To iSuccess
    Get ComGetEncoded Of hoBusinessName "url_rfc3986" "utf-8" To sTemp1
    Get ComReplace Of hoCmd "@NAME@" sTemp1 To iReplaced
    Get ComGetEncoded Of hoEmail "url_rfc3986" "utf-8" To sTemp1
    Get ComReplace Of hoCmd "@EMAIL@" sTemp1 To iReplaced
    Get ComReplace Of hoCmd "@REF@" sAccountRef To iReplaced
    Get ComReplace Of hoCmd "@OP@" sOperationId To iReplaced
    Get ComReplace Of hoCmd "@KEY@" sApiKey To iReplaced
    Get ComGetAsString Of hoCmd To sTemp1
    Get ComDoYourThing Of hoCurl sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Get ComFailReason Of hoCurl To iTemp1
        Showln "No HTTP response. Chilkat failure code: " iTemp1
        Procedure_Return
    End

    Get pvComObject of hoJson to vJson
    Get ComGetResponseJson Of hoCurl vJson To iSuccess
    Get ComStatusCode Of hoCurl To iTemp1
    If ((iTemp1 <> 200) Or (iSuccess <> True)) Begin
        Get ComStatusCode Of hoCurl To iTemp1
        Get ComGetResponseHeaderField Of hoCurl "Request-Id" To sTemp1
        Showln "Stripe HTTP " iTemp1 "  Request-Id: " sTemp1
        If (iSuccess = True) Begin
            Get ComStringOf Of hoJson "error.message" To sTemp1
            Showln sTemp1
        End

        Procedure_Return
    End

    //  Save this string on the existing billing account after a successful create.
    Get ComStringOf Of hoJson "id" To sCustomerId
    Showln "Stripe customer: " sCustomerId


End_Procedure