Docs
Checking Raims account
Integrations

Delphi SDK

Add the source to your Delphi project and configure services, pagination, and webhooks in your backend.

The Delphi SDK connects a backend to the Raims public API through source units with typed services, parameters, and responses. The distribution is source code to compile on your application's target. Check the platform requirements when setting up the installation. Do not embed API keys in distributed desktop or mobile binaries.

The SDK reference lists each resource's methods and parameters.

Install the SDK

Download the source ZIP and SHA256SUMS. Verify the hash, extract the archive, and keep the complete src directory. The base source requires Delphi 10.4; some targets require later versions. Check the platform requirements and use an edition that includes your compiler and required native SDKs.

In the IDE, open Project, Options, and Delphi Compiler. Add the src location to the project's Search path for each target and configuration you use. For global configuration, the Delphi Library options let you add it to the selected platform's Library path. The IDE library documentation explains this selection. Keep compiled files in your application's output directory, separate from the source.

Use Raims.Client, Raims.Core, Raims.Params, and Raims.Models; add Raims.Webhooks for events. The SDK uses the standard System.JSON and System.Net.HttpClient libraries without a UI framework. The first read below is a complete console program; the later examples are procedure snippets.

Configure the client

  1. Prepare the credential

    Obtain a credential through API keys and keep it in your backend. Company, environment, and permissions come from the validated key. Sandbox and Production use https://api.raims.com.

    For this first read, use a Sandbox key with View customers permission. The request only reads one page; it does not create customers or request emails.

  2. Save the read example

    Create a backend Console Application project and replace its .dpr with the file below. Use the Search path configured during installation.

    ReadCustomers.dpr
    pascal
    program ReadCustomers;
    
    {$APPTYPE CONSOLE}
    
    uses
      System.SysUtils, System.JSON,
      Raims.Client, Raims.Core, Raims.Params, Raims.Models;
    
    var
      Client: TRaimsClient;
      Options: TRaimsClientOptions;
      Params: TListCustomersParams;
      Customers: TCustomerListResponse;
      Items: TJSONArray;
    begin
      Options := TRaimsClientOptions.Default;
      Options.TimeoutMilliseconds := 80000;
      Options.MaxNetworkRetries := 0;
      Client := TRaimsClient.Create(GetEnvironmentVariable('RAIMS_API_KEY'), Options);
      try
        Params := TListCustomersParams.Create;
        try
          Params.SetPageSize(10);
          Customers := Client.Customers.List(Params);
          try
            Items := Customers.GetArray('list');
            Writeln('HTTP status: ', Customers.LastResponse.StatusCode,
              '; items: ', Items.Count);
          finally
            Customers.Free;
          end;
        finally
          Params.Free;
        end;
      finally
        Client.Free;
      end;
    end.
  3. Run and check the result

    Compile and run the console project in the IDE on your backend machine. Items is borrowed from the response: do not free it separately. The finally blocks release the owned resources.

    A successful read prints HTTP status: 200 and the number of items in this page. items: 0 is a valid empty result for the key’s company and environment. It is not an authentication failure.

What to check

The SDK reads the list and page envelope below. In an empty page, has_next: false means there is no next page. A nonempty page also returns customer records; the program prints only their count.

HTTP 200 response example excerptGET /v1/customers

No customers found

JSON
{
  "list": [],
  "page": {
    "page_size": 10,
    "has_next": false,
    "has_previous": false,
    "next_after": null,
    "previous_before": null
  }
}

Initialize options through Default. Timeouts use milliseconds and apply to native transport phases rather than a total operation deadline. Calls are synchronous; visual applications should run network work outside the UI thread. The next snippets use an open Client. It owns its services; your application frees the client, parameters, and returned resources using try/finally.

Create a customer and a charge

This is a backend snippet, after loading the order from your application’s storage. Keep the customer key separate from the charge key. Save the entire request payload, including the amount and title, before sending; read it again on retries instead of generating new values. The snippet uses the already open Client; declare the saved text inputs as string, DueDateUnix as Int64, and RequestId as string.

Input from the saved orderSource and purpose
CustomerTaxIdCustomer tax ID already authorized and saved by your application.
CustomerKeyIdempotency key for creating this customer; saved before the first request.
ChargeKeyA different idempotency key for this charge; saved with the order.
DueDateUnixChosen due date, saved in UTC Unix seconds.
pascal
var
  CustomerParams: TCreateCustomerParams;
  ChargeParams: TCreateChargeParams;
  Customer: TCustomerCreated;
  Charge: TChargeCreated;
  RequestOptions: TRaimsRequestOptions;
  CustomerId, ChargeId: string;
  HttpStatus: Integer;
  Pending: Boolean;
begin
  CustomerParams := TCreateCustomerParams.Create;
  try
    CustomerParams.SetTaxId(CustomerTaxId);
    RequestOptions := TRaimsRequestOptions.Default;
    RequestOptions.IdempotencyKey := CustomerKey;
    Customer := Client.Customers.Create(CustomerParams, RequestOptions);
    try
      CustomerId := Customer.Id;
    finally
      Customer.Free;
    end;
  finally
    CustomerParams.Free;
  end;

  ChargeParams := TCreateChargeParams.Create;
  try
    ChargeParams.SetCustomerId(CustomerId).SetAmountCents(15000);
    ChargeParams.SetDueDate(DueDateUnix).SetTitle('Pedido 1234');
    RequestOptions := TRaimsRequestOptions.Default;
    RequestOptions.IdempotencyKey := ChargeKey;
    Charge := Client.Charges.Create(ChargeParams, RequestOptions);
    try
      ChargeId := Charge.Id;
      HttpStatus := Charge.LastResponse.StatusCode;
      RequestId := Charge.LastResponse.RequestId;
      Pending := HttpStatus = 202;
    finally
      Charge.Free;
    end;
  finally
    ChargeParams.Free;
  end;
end;

If the CPF or CNPJ already exists in the same company and environment, the customer record is updated and keeps its ID.

Persist the returned customer ID and charge ID on the order before returning success to your caller. The charge ID is the value used to resume the read below; the SDK variables are not durable storage.

ResultWhat to do next
HTTP 201The charge was created. Save its ID; creation does not confirm payment. This snippet does not request email or payment issuance.
HTTP 202 in a creation that requests payment issuanceSave the same returned ID and keep the order pending. Retrieve that charge; do not create another one to resolve the pending result.
Error or missing responseHandle the structured error. If execution is uncertain, keep the intent and reconcile before retrying with the original key and payload.

The canonical creation example below shows only the ID and status fields:

HTTP 201 response example excerptPOST /v1/charges

Charge without a link or email request

JSON
{
  "id": "ch_1Q2W3E4R5T6Y7U8I9O0P",
  "status": 0
}

15000 represents BRL 150.00. Not calling a setter leaves a field absent; SetExternalReferenceNull on TUpdateCustomerParams sends null where the contract permits clearing that reference. UnsetExternalReference removes the input field. In responses, HasField and IsNull distinguish presence and null before interpreting a getter that returns zero or an empty string.

Pagination and pending results

List customers and visit up to one hundred items:

The following backend snippet counts at most 100 customers across pages, without logging their records. Keep the configured client open during iteration.

pascal
var
  Page: TCustomerListResponse;
  Visited: Integer;
begin
  Page := Client.Customers.List;
  try
    Visited := Page.AutoPagingEach(
      procedure(CustomerJson: TJSONObject)
      begin
        // Count only; do not store customer data in this example.
      end,
      100);
    Writeln('Items visited: ', Visited);
  finally
    Page.Free;
  end;
end;

Items visited: 0 means the query found no customers. 100 means the chosen limit was reached; it does not prove there are no more records. A page error interrupts the count. Save progress only after processing a complete page if your job must resume later.

The callback receives a borrowed TJSONObject: do not free or mutate it, and copy it before retaining it after the callback. AutoPagingEach frees additional pages; your application frees the first one. NextPage and PreviousPage return new pages or nil; the caller owns those pages. Filters and options are preserved.

HTTP 202 keeps the result pending. It does not confirm payment and the SDK does not start polling. When resuming the saved order, load ChargeId from storage and retrieve that same charge once:

pascal
var
  Current: TCharge;
begin
  Current := Client.Charges.Retrieve(ChargeId);
  try
    Writeln('HTTP status: ', Current.LastResponse.StatusCode,
      '; charge status: ', Current.Status);
  finally
    Current.Free;
  end;
end;

HTTP 200 here confirms that the read succeeded. Interpret the returned status and payment_information using the charge reference; a successful GET does not mean the charge was paid or that issuance completed. If issuance is still pending, keep the same ID. Repeated reads do not speed up processing or issue another payment; contact support if the condition persists.

Idempotency and errors

pascal
var
  Current: TCustomerListResponse;
  Details: TJSONArray;
  Detail: TJSONObject;
  I: Integer;
begin
  try
    Current := Client.Customers.List;
    try
      Writeln('HTTP status: ', Current.LastResponse.StatusCode,
        '; items: ', Current.GetArray('list').Count);
    finally
      Current.Free;
    end;
  except
    on E: ERaimsApiError do
    begin
      Writeln('HTTP status: ', E.LastResponse.StatusCode,
        '; code: ', E.Code, '; Request-Id: ', E.LastResponse.RequestId);
      Details := E.Details;
      try
        if Details <> nil then
          for I := 0 to Details.Count - 1 do
            if Details.Items[I] is TJSONObject then
            begin
              Detail := TJSONObject(Details.Items[I]);
              Writeln('field: ', Detail.GetValue<string>('field', ''),
                '; code: ', Detail.GetValue<string>('code', ''));
            end;
      finally
        Details.Free;
      end;
    end;
    on E: ERaimsConnectionError do
      Writeln('No conclusive response. Reconcile any uncertain write before retrying.');
  end;
end;

ERaimsApiError.Code returns error.code; use it with the HTTP status and LastResponse.RequestId to handle the failure. ApiMessage contains the API's diagnostic text, while Message is the exception's generic message. Neither message should control the integration. ERaimsConnectionError represents transport failures.

Details returns a cloned TJSONArray, or nil when field details are absent or invalid. The caller owns each returned copy: store it in a variable and free it in finally, as shown above. Use System.JSON to read field and code from each detail. ApiError also returns a copy owned by the caller. Log only necessary metadata without credentials or full bodies.

The SDK does not generate keys or retry writes automatically. After a lost response, reconcile the operation and keep its key and parameters if the endpoint permits another attempt. MaxNetworkRetries enables eligible read retries only; the default is zero. Retry-After follows the SDK's bounded wait policy. See Idempotency.

For example, if the read above returns HTTP 403 with API_KEY_PERMISSION_DENIED, the key lacks access to list customers. Enable View customers on the appropriate key and retry the read. Repeating it with the same permissions will not resolve that error.

Check HTTP response codes for other failures.

For an uncertain write, recover the saved key and the entire original payload. If the charge ID was received, retrieve that ID first. Within the idempotency retention period, a compatible retry can return the preserved result, including a pending 202. A key with different parameters can be rejected; do not change the due date or create a new key to bypass the uncertainty. After retention expires, reconcile before another write.

Use Sandbox

Use a Sandbox key and a charge created in that environment:

pascal
var
  SandboxClient: TRaimsClient;
  Simulation: TChargeSimulation;
begin
  SandboxClient := TRaimsClient.Create(GetEnvironmentVariable('RAIMS_SANDBOX_API_KEY'));
  try
    Simulation := SandboxClient.Simulations.Charges.ConfirmPayment(SandboxChargeId);
    try
      RequestId := Simulation.LastResponse.RequestId;
    finally
      Simulation.Free;
    end;
  finally
    SandboxClient.Free;
  end;
end;

SandboxChargeId and RequestId are application strings. The key determines the environment; the SDK does not change it through headers or operating system selection. Financial simulations require Sandbox. See Simulations. Email requests and webhooks may reach external destinations; use authorized ones.

Receive webhooks

Preserve RawBody as the original TBytes received by your server. Set WebhookSecret to the webhook's secret_key; the three Received... values come from the original headers. Before building the array below, reject duplicate signing-header occurrences instead of choosing one of them.

pascal
var
  Headers: TArray<TRaimsHeader>;
  Event: TJSONObject;
begin
  SetLength(Headers, 3);
  Headers[0] := TRaimsHeader.Create('webhook-id', ReceivedDeliveryId);
  Headers[1] := TRaimsHeader.Create('webhook-timestamp', ReceivedTimestamp);
  Headers[2] := TRaimsHeader.Create('webhook-signature', ReceivedSignature);
  Event := TRaimsWebhook.ConstructEvent(RawBody, Headers, WebhookSecret);
  try
    PersistEvent(Event);
  finally
    Event.Free;
  end;
end;

The types are in System.JSON, Raims.Core, and Raims.Webhooks. PersistEvent is your handler and the caller owns Event. ERaimsSignatureError identifies verification failure: do not process the event in that case. Do not reserialize the body before verification. The default tolerance is 300 seconds; keep the server clock synchronized.

After verification, check type and environment, deduplicate the event id, and store the work durably before returning success. webhook-id identifies the delivery. See Receive events.

Update the SDK

Review release notes and replace all units with source from the same revision. Preserve the selected Search path or Library path, remove old compiled units from your application's output, and rebuild every target in use. Do not mix a new unit with the rest of an older version. Check your integration with its compiler, operating system, and configuration before making the application available.