Generate a Delphi Stripe Client

Stripe publishes one of the most complete OpenAPI specifications on the public internet — over 500 endpoints covering payments, billing, identity, terminal and Connect. Feed it into sgcOpenAPI and you get a strongly typed Delphi unit that mirrors the spec, with request and response classes already populated, authentication wired up and pagination handled for you.

Stripe + sgcOpenAPI

Stripe ships and maintains an official OpenAPI 3 specification. sgcOpenAPI's parser and code generator convert it directly into Pascal that compiles on Delphi 7 through RAD Studio 13.

Auth

Bearer secret key + idempotency keys

Generated unit

sgcOpenAPI_Stripe

Platforms

Windows, macOS, Linux, iOS, Android

Feed the spec to the parser

Download the latest spec3.json from Stripe's public repository and load it with TsgcOpenAPIParser. The parser resolves $ref pointers, composition keywords and the shared error model so the code generator sees a fully dereferenced API model.

uses
  sgcOpenAPI_Parser, sgcOpenAPI_Generator;

var
  vParser: TsgcOpenAPIParser;
  vGen: TsgcOpenAPIGenerator;
begin
  vParser := TsgcOpenAPIParser.Create(nil);
  try
    vParser.LoadFromFile('C:\specs\stripe\spec3.json');
    Memo1.Lines.Add(Format('Loaded Stripe spec: %d paths, %d schemas',
      [vParser.Paths.Count, vParser.Schemas.Count]));

    vGen := TsgcOpenAPIGenerator.Create(nil);
    try
      vGen.Parser := vParser;
      vGen.OutputUnit := 'sgcOpenAPI_Stripe';
      vGen.OutputFolder := 'C:\Generated\Stripe';
      vGen.Generate;
    finally
      vGen.Free;
    end;
  finally
    vParser.Free;
  end;
end;

The generator writes a single Pascal unit named sgcOpenAPI_Stripe.pas with one strongly typed class per tag in the spec — TsgcStripe_Charges, TsgcStripe_Customers, TsgcStripe_Subscriptions, TsgcStripe_PaymentIntents and so on — plus a top-level TsgcStripe facade that owns the shared HTTP client and authentication state.

Create a charge

Set the bearer token once on the facade, then call methods on the typed sub-objects. Request bodies are populated through fluent properties; responses come back as strongly typed objects.

uses sgcOpenAPI_Stripe;

var
  vStripe: TsgcStripe;
  vCharge: TsgcStripeCharge;
begin
  vStripe := TsgcStripe.Create(nil);
  try
    vStripe.ApiKey := 'sk_test_4eC39HqLyjWDarjtT1zdp7dc';

    vCharge := vStripe.Charges.Create(
      Amount   := 2000,                  // cents
      Currency := 'usd',
      Source   := 'tok_visa',             // test token
      Description := 'Order 1234');
    try
      Memo1.Lines.Add('Charge id: ' + vCharge.Id);
      Memo1.Lines.Add('Status:    ' + vCharge.Status);
      Memo1.Lines.Add('Paid:      ' + BoolToStr(vCharge.Paid, True));
    finally
      vCharge.Free;
    end;
  finally
    vStripe.Free;
  end;
end;

Customers and subscriptions

Pagination is handled by the generated cursor objects. Idempotency keys are passed via the optional IdempotencyKey parameter on every mutating method.

// Create a customer + attach a subscription
var
  vCustomer: TsgcStripeCustomer;
  vSub: TsgcStripeSubscription;
  vItems: TsgcStripeSubscriptionItemList;
begin
  vCustomer := vStripe.Customers.Create(
    Email := 'jane@example.com',
    PaymentMethod := 'pm_card_visa');

  vItems := TsgcStripeSubscriptionItemList.Create;
  vItems.Add(Price := 'price_1JxYzZAbCdEfGhIj');

  vSub := vStripe.Subscriptions.Create(
    Customer := vCustomer.Id,
    Items := vItems,
    IdempotencyKey := TGUID.NewGuid.ToString);

  // Page through invoices for this customer
  for vInvoice in vStripe.Invoices.List(Customer := vCustomer.Id) do
    Memo1.Lines.Add(Format('%s — %d %s',
      [vInvoice.Id, vInvoice.AmountDue, vInvoice.Currency]));
end;

What the generated unit gives you

Because the unit is generated from the official spec, every documented endpoint and every documented field is available without manual binding work.

Payments & refunds

Charges, PaymentIntents, PaymentMethods, Refunds, Disputes, Sources, Tokens — the full classic Charges API plus the modern PaymentIntents flow with Strong Customer Authentication.

Billing & subscriptions

Customers, Invoices, InvoiceItems, Subscriptions, SubscriptionItems, Prices, Products, Coupons, PromotionCodes, TaxRates.

Connect & payouts

Accounts, AccountLinks, Transfers, Payouts, BalanceTransactions — everything needed to operate a Stripe Connect platform from a Delphi back-office.

Identity & Terminal

Identity VerificationSession objects and Terminal Reader/Location objects are all present, including the polymorphic last_verification_report schemas that Stripe uses for KYC results.

Webhook events

The full Event schema with discriminated data.object payloads is included. Parse incoming webhook bodies with the same types you use to send the original request.

Files & reporting

Files, FileLinks, Reporting — multipart upload helpers are emitted automatically because the spec marks those endpoints with multipart/form-data.

Two things to watch for

Spec version drift

Stripe ships new API versions monthly. Pin the spec file to the version your account uses (set Stripe-Version on every request) and regenerate the Delphi unit when you upgrade. The generator is deterministic — same spec, same output.

Polymorphic responses

Several Stripe schemas (payment_method_details, source, balance_transaction.source) use oneOf with a discriminator. The generated unit emits a base class plus one descendant per variant — downcast based on the Type property.

From the blog

OpenAPI Delphi parser

How the underlying parser handles real-world OpenAPI 3.x specifications, including the tricky composition keywords.

Read post →

OpenAPI parser: bundle schemas

Working with multi-file specs and external $ref pointers — useful when Stripe sub-specs are split.

Read post →

sgcOpenAPI 2026.6

Latest release notes for sgcOpenAPI — new generator options and parser improvements.

Read post →

Generate your Stripe client today

sgcOpenAPI ships with the parser, code generator, OpenAPI server and the Google, Amazon, Microsoft and Azure SDK bundles — one product, three tiers.