> 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/seb-docs-draft/seb-docs-public-lv/integracija/api-klienta-sdk/atrie-sakumi/c-.net.md).

# C# / .NET

Iestatiet C# / .NET SDK, uzsāciet smilškastes maksājumu un konfigurējiet klienta adapterus.

## Priekšnosacījumi

* .NET 8 SDK.
* Sandbox API akreditācijas dati: **klienta ID** un **klienta noslēpums**, kā arī jūsu **dalībnieka ID** un **veikala līguma ID**. Reģistrējieties un ģenerējiet tos paši sadaļā **Tirgotāja portālā**: <https://merchantportal.ecommerce.sebgroup.com>.
* SDK **izplatīšanas ZIP fails**, kas lejupielādēts no šīs dokumentācijas vietnes.

## Instalēt

Lejupielādēt `egw-csharp-sdk-<version>.zip` un tam atbilstošo `.sha256` failu, pārbaudiet lejupielādi, pēc tam atarhivējiet to blakus savam projektam:

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

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

Tas jums dod `Egw.Sdk.<version>.nupkg` un tam atbilstošo `Egw.Sdk.<version>.snupkg` (atkļūdošanas simboli), kopā ar `README.txt` un `SHA256SUMS` manifestu. Pievienojiet šo direktoriju kā pakotnes avotu un instalējiet no tā:

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

Vai reģistrējiet avotu vienreiz `nuget.config` nevis nododot `--source` katru reizi:

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

Pakotnes nosaukums ir `Egw.Sdk`, un tās izpildlaika atkarības ir `jose-jwt` un `System.Text.Json`. NuGet tos atjauno no jūsu parastajiem pakotņu avotiem, tāpēc instalēšanai ir nepieciešama tīkla piekļuve tiem.

## Izveidojiet klientu un veiciet savu pirmo izsaukumu

Šajā piemērā akreditācijas dati tiek iegūti no vides mainīgajiem — nekad neielieciet repozitorijā un nelogojiet īstus akreditācijas datus. Visas darbības ir **tikai asinhronas**.

```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") // nepieciešams karšu sesijām
    .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("Pirmais testa maksājums"));

Console.WriteLine($"Maksājums izveidots: {response.PaymentId}");
```

Piezīmes:

* `TokenEndpoint(...)` ir **nepieciešams**; to izlaižot, kļūda rodas pie `CreateEgwClient()` ar `EgwBootstrapException`.
* `EncryptingWith(...)` nav obligāts, bet bez tā jebkurš karšu šifrēšanas izsaukums radīs izņēmumu — konfigurējiet to, ja izmantojat karšu norēķinu sesijas.
* Summas iestatītājs ir `VarAmount(...)` (JSON lauks joprojām ir `amount`); summas ir **decimālās virknes**, valūtas — ISO 4217 alfa-3. Testa kartēm un maģiskajām vērtībām skatiet [Sandbox testa datus](/seb-docs-draft/seb-docs-public-lv/celvezi/smilskaste.md).
* `EgwClient` ir `IDisposable`; atbrīvošana aptur webhook klausītāju, ja tas ir palaists. Klientu var droši koplietot starp pieprasījumiem.

## Klienta pielāgošana

* Izmantojot `ConnectingWith()`, jūs varat norādīt savu HTTP klienta implementāciju.
* Žurnālfiksēšana: implementējiet `IEgwLoggerProvider`; noklusējuma žurnālfiksētājs ir kluss. Skatiet [Drošības mehānismi](/seb-docs-draft/seb-docs-public-lv/integracija/api-klienta-sdk/celvezi/drosibas-mehanismi.md#logging).
* Webhooki: `ListeningOn(uri)` + `client.Notifications().ReceiveNotifications(...)` — skatiet [Drošības mehānismi](/seb-docs-draft/seb-docs-public-lv/integracija/api-klienta-sdk/celvezi/drosibas-mehanismi.md#webhook-notifications).
* Skatiet [SDK adapteru pārrakstīšana](/seb-docs-draft/seb-docs-public-lv/integracija/api-klienta-sdk/celvezi/sdk-adapteru-aizstasana.md) lai iegūtu pilnu pārskatu par adapteru aizstāšanu visā lietotnē.

## Nākamie soļi

* [Drošības mehānismi](/seb-docs-draft/seb-docs-public-lv/integracija/api-klienta-sdk/celvezi/drosibas-mehanismi.md) — karšu šifrēšana karšu norēķinu sesijām, webhooks.
* [Kļūdu apstrāde](/seb-docs-draft/seb-docs-public-lv/integracija/api-klienta-sdk/celvezi/kludu-apstrade.md) — izņēmumu hierarhija un atkārtotu mēģinājumu ieteikumi.


---

# 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/seb-docs-draft/seb-docs-public-lv/integracija/api-klienta-sdk/atrie-sakumi/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.
