> For the complete documentation index, see [llms.txt](https://docs.ecommerce.seb.ee/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ecommerce.seb.ee/integration/api-client-sdk/quickstarts/c-.net.md).

# C# / .NET

Set up the C# / .NET SDK, initiate a sandbox payment, and configure client adapters.

## Prerequisites

* .NET 8 SDK.
* Sandbox API credentials: **client ID** and **client secret**, plus your **participant ID** and **shop agreement ID**. Register and generate these yourself at the **Merchant Portal**: <https://merchantportal.ecommerce.sebgroup.com>.
* The SDK **distribution ZIP**, downloaded from this documentation site.

## Install

Download `egw-csharp-sdk-<version>.zip` and its matching `.sha256` file, verify the download, then unzip it next to your project:

```bash
sha256sum -c egw-csharp-sdk-<version>.zip.sha256

unzip egw-csharp-sdk-<version>.zip -d egw-sdk
```

That gives you `Egw.Sdk.<version>.nupkg` and its matching `Egw.Sdk.<version>.snupkg` (debug symbols), alongside a `README.txt` and a `SHA256SUMS` manifest. Add that directory as a package source and install from it:

```bash
dotnet add package Egw.Sdk --version <version> --source ./egw-sdk
```

Or register the source once in `nuget.config` instead of passing `--source` every time:

```xml
<configuration>
  <packageSources>
    <add key="egw-local" value="./egw-sdk" />
  </packageSources>
</configuration>
```

The package name is `Egw.Sdk`, and its runtime dependencies are `jose-jwt` and `System.Text.Json`. NuGet restores those from your normal package sources, so the install needs network access to them.

## Create a client and make your first call

In this example, the credentials are retrieved from environment variables — never commit or log real credentials. All operations are **async-only**.

```csharp
using Egw.Sdk.Application;
using Egw.Sdk.Application.Bootstrap;
using Egw.Sdk.Application.Dto;

using EgwClient client = new DefaultEgwClientFactory()
    .ConnectingTo("https://sandbox.api.ecommerce.sebgroup.com")
    .TokenEndpoint("https://api.ecommerce.sebgroup.com/auth/realms/participants-seb/protocol/openid-connect/token")
    .AuthorizingAs(
        Environment.GetEnvironmentVariable("EGW_CLIENT_ID")!,
        Environment.GetEnvironmentVariable("EGW_CLIENT_SECRET")!)
    .EncryptingWith("https://checkout.ecommerce.sebgroup.com/api/keys/card-encryption.jwk") // required for card sessions
    .CreateEgwClient();

InitiatePaymentResponse response = await client.Payments().InitiateCitPaymentAsync(
    Guid.NewGuid(),
    b => b.Channel(CitPaymentChannel.BROWSER)
          .InstructedAmount(a => a.VarAmount("100.00").Currency("EUR"))
          .OrderNumber("ORD-001")
          .ParticipantId(Environment.GetEnvironmentVariable("EGW_PARTICIPANT_ID")!)
          .ShopAgreementId(Environment.GetEnvironmentVariable("EGW_SHOP_AGREEMENT_ID")!)
          .ShopRedirectUrl("https://shop.example.com/return")
          .Description("First sandbox payment"));

Console.WriteLine($"Payment created: {response.PaymentId}");
```

Notes:

* `TokenEndpoint(...)` is **required**; omitting it fails at `CreateEgwClient()` with `EgwBootstrapException`.
* `EncryptingWith(...)` is optional, but without it any card-encryption call throws — configure it if you use card checkout sessions.
* The amount setter is `VarAmount(...)` (the JSON field is still `amount`); amounts are **decimal strings**, currencies ISO 4217 alpha-3. For test cards and magic values, see [Sandbox test data](/guides/sandbox.md).
* `EgwClient` is `IDisposable`; disposing stops the webhook listener if one was started. The client is safe to share across requests.

## Customizing the client

* Using `ConnectingWith()`, you may supply your own HTTP client implementation.
* Logging: implement `IEgwLoggerProvider`; the default logger is silent. See [Security mechanics](/integration/api-client-sdk/guides/security-mechanics.md#logging).
* Webhooks: `ListeningOn(uri)` + `client.Notifications().ReceiveNotifications(...)` — see [Security mechanics](/integration/api-client-sdk/guides/security-mechanics.md#webhook-notifications).
* See [Overriding SDK adapters](/integration/api-client-sdk/guides/overriding-sdk-adapters.md) for a full walkthrough of replacing adapters application-wide.

## Next steps

* [Security mechanics](/integration/api-client-sdk/guides/security-mechanics.md) — card encryption for card checkout sessions, webhooks.
* [Error handling](/integration/api-client-sdk/guides/error-handling.md) — the exception hierarchy and retry guidance.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ecommerce.seb.ee/integration/api-client-sdk/quickstarts/c-.net.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
