An open API service indexing awesome lists of open source software.

https://github.com/payabli/sdk-csharp

Payabli's official server SDK for C#
https://github.com/payabli/sdk-csharp

csharp dotnet embedded-payments payabli-api sdk

Last synced: 3 months ago
JSON representation

Payabli's official server SDK for C#

Awesome Lists containing this project

README

          

# Payabli C# Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fpayabli%2Fsdk-csharp)
[![nuget shield](https://img.shields.io/nuget/v/Payabli.SDK)](https://nuget.org/packages/Payabli.SDK)

The Payabli C# library provides convenient access to the Payabli APIs from C#.

## Table of Contents

- [Documentation](#documentation)
- [Requirements](#requirements)
- [Installation](#installation)
- [Changelog](#changelog)
- [Getting Started](#getting-started)
- [Passing Query Parameters](#passing-query-parameters)
- [Usage](#usage)
- [Environments](#environments)
- [Exception Handling](#exception-handling)
- [Advanced](#advanced)
- [Retries](#retries)
- [Timeouts](#timeouts)
- [Raw Response](#raw-response)
- [Additional Headers](#additional-headers)
- [Additional Query Parameters](#additional-query-parameters)
- [Forward Compatible Enums](#forward-compatible-enums)
- [Contributing](#contributing)
- [Reference](#reference)

## Documentation

API reference documentation is available [here](https://docs.payabli.com).

## Requirements

This SDK requires:

## Installation

```sh
dotnet add package Payabli.SDK
```

## Changelog

The changelog for the official Payabli C# SDK is available on the Payabli Docs site. See [C# SDK Changelog](https://docs.payabli.com/changelog/csharp-sdk) for more information.

## Getting Started

Visit the Payabli Docs site to get started with the official Payabli C# SDK. See [Use the C# SDK](https://docs.payabli.com/developers/platform-sdk-csharp-guide) for more information.

## Passing Query Parameters

```csharp
var client = new PayabliApiClient("API_KEY");

var queryParams = new Dictionary();

queryParams.Add("email(ct)", "test@example.com");

var result = await client.Query.ListCustomersAsync(
"ENTRYPOINT",
new ListCustomersRequest {},
new RequestOptions
{
AdditionalQueryParameters = queryParams
}
);

Console.WriteLine($"Response: {result}");
```

## Usage

Instantiate and use the client with the following:

```csharp
using PayabliApi;

var client = new PayabliApiClient("API_KEY");
await client.MoneyIn.GetpaidAsync(
new RequestPayment
{
Body = new TransRequestBody
{
CustomerData = new PayorDataRequest { CustomerId = 4440 },
EntryPoint = "f743aed24a",
Ipaddress = "255.255.255.255",
PaymentDetails = new PaymentDetail { ServiceFee = 0, TotalAmount = 100 },
PaymentMethod = new PayMethodCredit
{
Cardcvv = "999",
Cardexp = "02/27",
CardHolder = "John Cassian",
Cardnumber = "4111111111111111",
Cardzip = "12345",
Initiator = "payor",
Method = "card",
},
},
}
);
```

## Environments

This SDK allows you to configure different environments for API requests.

```csharp
using PayabliApi;

var client = new PayabliApiClient(new ClientOptions
{
BaseUrl = PayabliApiEnvironment.Sandbox
});
```

## Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.

```csharp
using PayabliApi;

try {
var response = await client.MoneyIn.GetpaidAsync(...);
} catch (PayabliApiApiException e) {
System.Console.WriteLine(e.Body);
System.Console.WriteLine(e.StatusCode);
}
```

## Advanced

### Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)

Use the `MaxRetries` request option to configure this behavior.

```csharp
var response = await client.MoneyIn.GetpaidAsync(
...,
new RequestOptions {
MaxRetries: 0 // Override MaxRetries at the request level
}
);
```

### Timeouts

The SDK defaults to a 30 second timeout. Use the `Timeout` option to configure this behavior.

```csharp
var response = await client.MoneyIn.GetpaidAsync(
...,
new RequestOptions {
Timeout: TimeSpan.FromSeconds(3) // Override timeout to 3s
}
);
```

### Raw Response

Access raw HTTP response data (status code, headers, URL) alongside parsed response data using the `.WithRawResponse()` method.

```csharp
using PayabliApi;

// Access raw response data (status code, headers, etc.) alongside the parsed response
var result = await client.MoneyIn.GetpaidAsync(...).WithRawResponse();

// Access the parsed data
var data = result.Data;

// Access raw response metadata
var statusCode = result.RawResponse.StatusCode;
var headers = result.RawResponse.Headers;
var url = result.RawResponse.Url;

// Access specific headers (case-insensitive)
if (headers.TryGetValue("X-Request-Id", out var requestId))
{
System.Console.WriteLine($"Request ID: {requestId}");
}

// For the default behavior, simply await without .WithRawResponse()
var data = await client.MoneyIn.GetpaidAsync(...);
```

### Additional Headers

If you would like to send additional headers as part of the request, use the `AdditionalHeaders` request option.

```csharp
var response = await client.MoneyIn.GetpaidAsync(
...,
new RequestOptions {
AdditionalHeaders = new Dictionary
{
{ "X-Custom-Header", "custom-value" }
}
}
);
```

### Additional Query Parameters

If you would like to send additional query parameters as part of the request, use the `AdditionalQueryParameters` request option.

```csharp
var response = await client.MoneyIn.GetpaidAsync(
...,
new RequestOptions {
AdditionalQueryParameters = new Dictionary
{
{ "custom_param", "custom-value" }
}
}
);
```

### Forward Compatible Enums

This SDK uses forward-compatible enums that can handle unknown values gracefully.

```csharp
using PayabliApi;

// Using a built-in value
var achaccounttype = Achaccounttype.Checking;

// Using a custom value
var customAchaccounttype = Achaccounttype.FromCustom("custom-value");

// Using in a switch statement
switch (achaccounttype.Value)
{
case Achaccounttype.Values.Checking:
Console.WriteLine("Checking");
break;
default:
Console.WriteLine($"Unknown value: {achaccounttype.Value}");
break;
}

// Explicit casting
string achaccounttypeString = (string)Achaccounttype.Checking;
Achaccounttype achaccounttypeFromString = (Achaccounttype)"Checking";
```

## Contributing

While we value open-source contributions to this SDK, this library is generated programmatically.
Additions made directly to this library would have to be moved over to our generation code,
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!
## Reference

A full reference for this library is available [here](https://github.com/payabli/sdk-csharp/blob/HEAD/./reference.md).