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

Delphi DLL
var
success: Boolean;
apiKey: PWideChar;
operationId: PWideChar;
curl: HCkHttpCurl;
cmd: HCkStringBuilder;
json: HCkJsonObject;
replaced: Integer;
businessName: HCkStringBuilder;
email: HCkStringBuilder;
accountRef: PWideChar;
customerId: PWideChar;

begin
success := False;

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

curl := CkHttpCurl_Create();
cmd := CkStringBuilder_Create();
json := CkJsonObject_Create();

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

businessName := CkStringBuilder_Create();
CkStringBuilder_SetString(businessName,'Acme & Sons');

email := CkStringBuilder_Create();
CkStringBuilder_SetString(email,'billing+east@example.com');

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}"
CkStringBuilder_SetString(cmd,'curl -X POST "https://api.stripe.com/v1/customers"');
CkStringBuilder_Append(cmd,' -u "@KEY@:"');
CkStringBuilder_Append(cmd,' -H "Stripe-Version: 2026-10-28.endive"');
CkStringBuilder_Append(cmd,' -H "Idempotency-Key: @OP@-customer"');
CkStringBuilder_Append(cmd,' -d "name=@NAME@"');
CkStringBuilder_Append(cmd,' -d "email=@EMAIL@"');
CkStringBuilder_Append(cmd,' -d "metadata[account_ref]=@REF@"');
replaced := CkStringBuilder_Replace(cmd,'@NAME@',CkStringBuilder__getEncoded(businessName,'url_rfc3986','utf-8'));
replaced := CkStringBuilder_Replace(cmd,'@EMAIL@',CkStringBuilder__getEncoded(email,'url_rfc3986','utf-8'));
replaced := CkStringBuilder_Replace(cmd,'@REF@',accountRef);
replaced := CkStringBuilder_Replace(cmd,'@OP@',operationId);
replaced := CkStringBuilder_Replace(cmd,'@KEY@',apiKey);
success := CkHttpCurl_DoYourThing(curl,CkStringBuilder__getAsString(cmd));
if (success <> True) then
  begin
    Memo1.Lines.Add('No HTTP response. Chilkat failure code: ' + IntToStr(CkHttpCurl_getFailReason(curl)));
    Exit;
  end;
success := CkHttpCurl_GetResponseJson(curl,json);
if ((CkHttpCurl_getStatusCode(curl) <> 200) or (success <> True)) then
  begin
    Memo1.Lines.Add('Stripe HTTP ' + IntToStr(CkHttpCurl_getStatusCode(curl)) + '  Request-Id: ' + CkHttpCurl__getResponseHeaderField(curl,'Request-Id'));
    if (success = True) then
      begin
        Memo1.Lines.Add(CkJsonObject__stringOf(json,'error.message'));
      end;
    Exit;
  end;

//  Save this string on the existing billing account after a successful create.
customerId := CkJsonObject__stringOf(json,'id');
Memo1.Lines.Add('Stripe customer: ' + customerId);

CkHttpCurl_Dispose(curl);
CkStringBuilder_Dispose(cmd);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(businessName);
CkStringBuilder_Dispose(email);