C# SDK
Install, configure, and use the SpareApi .NET package.
The .NET SDK targets .NET 6.0+ and exposes an async client surface aligned with the API.
Coming soon, under review
This SDK is under review and not yet published, so the package is not installable yet. The steps below show the intended usage. Until release, integrate over the REST API.
Installation
Install
dotnet add package SpareApiThe package is published on NuGet.
Configuration
Create a Configuration with your credentials, then pass it to the client. Token exchange, caching, and refresh are handled automatically, you never manage tokens directly.
using SpareApi;
var config = new Configuration(new ConfigurationOptions
{
AppId = Environment.GetEnvironmentVariable("SPARE_APP_ID")!,
ApiKey = Environment.GetEnvironmentVariable("SPARE_API_KEY")!,
Tenant = Environment.GetEnvironmentVariable("SPARE_TENANT")!,
});
var client = new SpareApiClient(config);The X-Tenant header is injected on every request. Set SPARE_TENANT to the tenant for your market, see Coverage.
Common operations
// List providers
var providers = await client.Providers.ListAsync(
new ProvidersListRequest { CountryCode = "AE" }
);
foreach (var provider in providers.Data)
{
Console.WriteLine($"{provider.Id} {provider.Name}");
}
// Create a payment request, requires an ES256 detached-JWS signature
var body = new Dictionary<string, object>
{
["type"] = "SingleInstantPayment",
["purpose"] = "ACM",
["creditorType"] = "MERCHANT",
["creditorReference"] = "INV-10042",
["creditorAccount"] = new Dictionary<string, object>
{
["identification"] = "AE070331234567890123456",
["name"] = "Acme Corp",
["schemeName"] = "IBAN",
},
["instructions"] = new Dictionary<string, object>
{
["amount"] = new Dictionary<string, object>
{
["amount"] = "250.00",
["currency"] = "AED",
},
},
};
var xSignature = client.Crypto.SignPayload(
Environment.GetEnvironmentVariable("SPARE_PRIVATE_KEY_PEM")!, body);
var paymentRequest = await client.PaymentRequests.CreateAsync(
new CreatePaymentRequestRequest
{
CreditorReference = "INV-10042",
Purpose = "ACM",
XSignature = xSignature,
}
);Error handling
All non-2xx responses throw SpareApiApiException. Inspect StatusCode and Body to handle specific errors:
using SpareApi;
try
{
var consent = await client.PaymentConsents.GetAsync("consent-id");
}
catch (SpareApiApiException e)
{
Console.Error.WriteLine(e.StatusCode); // HTTP status, e.g. 404
Console.Error.WriteLine(e.Body); // raw response body
throw;
}Resources
- Quickstart
- API Reference
- NuGet:
SpareApi - Source repository: published when the SDK is released.