Skip to content

C#

Setting up the Infrastructure

Install the following packages via our NuGet feed at https://baget.klogs.io/v3/index.json:

  • Klogs.PaymentGateway.Client
  • Klogs.PaymentGateway.Client.Abstraction

Then configure the services in your .NET 6+ application:

csharp
builder.Services.AddPaymentGatewayClient(opt =>
{
    opt.Endpoint = "https://test-pgw.klogs.io/";
    opt.AccessTokenFactory = sp =>
    {
        var cache = sp.GetService<IDistributedCache>();

        var act = new KlogsIdpClientSecretCredential(new Klogs.Identity.Core.ClientSecretCredentialOptions
        {
            ClientId = "klogs.api",
            Secret = "key",
            Source = new Uri("https://idp.klogs.io")
        }).GetToken().AccessToken;
        return act;
    };
});

After entering the provided key in the Secret section, your infrastructure integration is complete. Congratulations!

Redirecting to Hosted Payment Page

  1. Inject the IHostedPaymentHttpClient interface provided by Klogs.PaymentGateway.Client.Abstraction via constructor injection.

  2. Use the _hostedPaymentHttpClient.CreatePayment() method to generate the hosted payment page URL.

  3. The CreatePayment method requires the HostedPaymentRequest model from Klogs.PaymentGateway.Client.Abstraction.Model.HostedPayment.

  4. HostedPaymentRequest Fields:

  • Amount - decimal (Amount to be collected)
  • Currency - string (TRY, USD, EUR)
  • FullName - string (Customer's full name)
  • NationalNumber - string (Customer's national ID number, mandatory for some POS providers like Iyzico, Sipay)
  • Email - string (Customer's email address)
  • Explanation - string (Description)
  • Phone - string (Customer's phone number)
  • Reference - string (Unique reference number required for later inquiries)
  • ReturnURL - string (URL to redirect to after payment)
  • ChargeType - enum (Use Klogs.PaymentGateway.Abstraction.Types.SalesType, either DirectSale or Provision)
  • Products - array of Product (List of products related to payment)
  1. Product Fields (Klogs.System.Types.Product):
  • Id - string (Product ID)
  • Price - decimal (Product price)
  • Quantity - double (Product quantity)
  • Category - string (Product category)
  • Code - string (Product code)
  • Description - string (Product description)
  1. After following the above steps, a request is sent and a successful response returns the hosted payment page URL.

  2. Redirect the customer to the URL where they will enter their card details and complete the payment.

  3. After payment, the system redirects automatically to the ReturnURL provided.

  4. To check the payment status, you need to create a request using another service.

  5. Inject the IPaymentTransactionHttpClient interface via constructor injection.

  6. Use the _paymentTransactionHttpClient.DetailAsync() method to query the payment status using the reference number.

  7. The response will be a TransactionDetailResponse model from Klogs.PaymentGateway.Client.Abstraction.Model.Transaction.