Integrating with .NET – Trustist Ecommerce SDK

In this section, we will guide you through integrating the Trustist Ecommerce Payments API using our .NET SDK. We have designed the SDK to simplify the process of integrating the API into your .NET applications. Follow the steps below to get started.

1. Installation #

To begin, ensure you have the Trustist Ecommerce SDK installed in your .NET project. You can download it from our official repository.

2. Configuration #

In your application’s Startup.cs or another suitable location, you will need to add and configure the Trustist Ecommerce Client. Use the `AddTrustistEcommerceClient` method to register the client, passing your API credentials (Client ID and Private Key) and the desired environment (sandbox or production). Here’s an example:

services.AddTrustistEcommerceClient(
    clientId: "your-client-id",
    privateKey: "your-private-key",
    environment: TrustistEcommerceEnvironment.Sandbox);

3. Using the ITrustistEcommerceClient #

After configuring the Trustist Ecommerce Client, you can access it in your application by injecting the `ITrustistEcommerceClient` interface into your classes. Here’s an example of how to use the client in a controller:

public class PaymentsController : ControllerBase
{
    private readonly ITrustistEcommerceClient _trustistEcommerceClient;

    public PaymentsController(ITrustistEcommerceClient trustistEcommerceClient)
    {
        _trustistEcommerceClient = trustistEcommerceClient;
    }

    // Your controller actions here...
}

4. Creating a Payment #

To create a new payment, call the `CreateAsync` method on the `Payments` property of the `ITrustistEcommerceClient` instance. You will need to pass a `TrustistEcommercePaymentCreateRequest` object containing the necessary payment details.

Example:

var paymentRequest = new TrustistEcommercePaymentCreateRequest
{
    Amount = 100.00m,
    Reference = "your-order-reference", // optional
    Description == "Short description", // advisable
    ReturnUrl = "https://your-return-url.com", // once payment is complete
    CustomerDetails = "Name and/or address", // optional
};

var paymentResponse = await _trustistEcommerceClient.Payments.CreateAsync(paymentRequest, cancellationToken);

5. Retrieving a Payment #

To retrieve the details of an existing payment, call the `GetAsync` method on the `Payments` property of the `ITrustistEcommerceClient` instance. Pass the payment ID as a parameter.

Example:

var paymentId = "your-payment-id";
var payment = await _trustistEcommerceClient.Payments.GetAsync(paymentId, cancellationToken);

By following these steps, you should now be able to integrate the Trustist Ecommerce Payments API into your .NET application using our SDK. For further information or assistance, please consult our comprehensive API documentation or contact our support team.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *