Delphi Stripe 클라이언트 생성

Stripe는 공개 인터넷에서 가장 완전한 OpenAPI 사양 중 하나를 게시해요 — 결제, 청구, 신원, 터미널 및 Connect를 다루는 500개 이상의 엔드포인트. sgcOpenAPI에 입력하면 사양을 반영하는 강력하게 타입이 지정된 Delphi 유닛이 만들어져요. 요청 및 응답 클래스가 이미 채워져 있고, 인증이 연결되어 있으며, 페이지 매김이 처리돼요.

Stripe + sgcOpenAPI

Stripe는 공식 OpenAPI 3 사양을 출시하고 유지 관리해요. sgcOpenAPI의 파서와 코드 생성기는 이를 Delphi 7부터 RAD Studio 13까지 컴파일되는 Pascal로 직접 변환해요.

인증

Bearer 시크릿 키 + 멱등성 키

생성된 유닛

sgcOpenAPI_Stripe

플랫폼

Windows, macOS, Linux, iOS, Android

파서에 사양 입력하기

Stripe의 공개 저장소에서 최신 spec3.json을 다운로드하고 TsgcOpenAPIParser로 로드하세요. 파서는 $ref 포인터, 컴포지션 키워드 및 공유 오류 모델을 해석하므로 코드 생성기는 완전히 역참조된 API 모델을 보게 돼요.

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;

생성기는 사양의 태그마다 강력하게 타입이 지정된 클래스 하나가 있는 sgcOpenAPI_Stripe.pas라는 단일 Pascal 유닛을 작성해요 — TsgcStripe_Charges, TsgcStripe_Customers, TsgcStripe_Subscriptions, TsgcStripe_PaymentIntents 등 — 그리고 공유 HTTP 클라이언트와 인증 상태를 소유하는 최상위 TsgcStripe 파사드도 함께요.

결제 생성하기

파사드에 베어러 토큰을 한 번 설정한 다음 타입이 지정된 하위 객체에서 메서드를 호출하세요. 요청 본문은 fluent 속성을 통해 채워져요; 응답은 강력하게 타입이 지정된 객체로 돌아와요.

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;

고객 및 구독

페이지 매김은 생성된 커서 객체에 의해 처리돼요. 멱등성 키는 모든 변경 메서드의 선택적 IdempotencyKey 매개변수를 통해 전달돼요.

// 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;

생성된 유닛이 제공하는 것

유닛이 공식 사양에서 생성되기 때문에 문서화된 모든 엔드포인트와 모든 필드가 수동 바인딩 작업 없이 사용 가능해요.

결제 & 환불

Charges, PaymentIntents, PaymentMethods, Refunds, Disputes, Sources, Tokens — 전체 클래식 Charges API와 강력한 고객 인증이 있는 최신 PaymentIntents 흐름.

청구 & 구독

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

Connect & 지급

Accounts, AccountLinks, Transfers, Payouts, BalanceTransactions — Delphi 백오피스에서 Stripe Connect 플랫폼을 운영하는 데 필요한 모든 것.

Identity & Terminal

Identity VerificationSession 객체와 Terminal Reader/Location 객체가 모두 있어요. Stripe가 KYC 결과에 사용하는 다형성 last_verification_report 스키마 포함.

웹훅 이벤트

구별된 data.object 페이로드가 있는 전체 Event 스키마가 포함되어 있어요. 원본 요청을 보내는 데 사용한 것과 동일한 타입으로 들어오는 웹훅 본문을 파싱하세요.

파일 & 보고

Files, FileLinks, Reporting — 사양이 해당 엔드포인트를 multipart/form-data로 표시하기 때문에 멀티파트 업로드 헬퍼가 자동으로 생성돼요.

주의할 두 가지

사양 버전 드리프트

Stripe는 매월 새로운 API 버전을 출시해요. 계정이 사용하는 버전에 사양 파일을 고정하고(모든 요청에 Stripe-Version 설정) 업그레이드할 때 Delphi 유닛을 재생성하세요. 생성기는 결정론적이에요 — 같은 사양, 같은 출력.

다형성 응답

여러 Stripe 스키마(payment_method_details, source, balance_transaction.source)는 디스크리미네이터와 함께 oneOf를 사용해요. 생성된 유닛은 기본 클래스와 변형당 하나의 자손을 내보내요 — Type 속성을 기반으로 다운캐스트하세요.

블로그에서

OpenAPI Delphi 파서

기본 파서가 까다로운 컴포지션 키워드를 포함하여 실제 OpenAPI 3.x 사양을 처리하는 방법.

게시물 읽기 →

OpenAPI 파서: 스키마 번들

다중 파일 사양 및 외부 $ref 포인터 작업 — Stripe 하위 사양이 분할될 때 유용해요.

게시물 읽기 →

sgcOpenAPI 2026.6

sgcOpenAPI의 최신 릴리스 노트 — 새로운 생성기 옵션 및 파서 개선 사항.

게시물 읽기 →

오늘 Stripe 클라이언트를 생성하세요

sgcOpenAPI는 파서, 코드 생성기, OpenAPI 서버 및 Google, Amazon, Microsoft 및 Azure SDK 번들과 함께 제공돼요 — 하나의 제품, 세 가지 등급.