DJH.Knet.pipe 2.1.1

dotnet add package DJH.Knet.pipe --version 2.1.1
                    
NuGet\Install-Package DJH.Knet.pipe -Version 2.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DJH.Knet.pipe" Version="2.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DJH.Knet.pipe" Version="2.1.1" />
                    
Directory.Packages.props
<PackageReference Include="DJH.Knet.pipe" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DJH.Knet.pipe --version 2.1.1
                    
#r "nuget: DJH.Knet.pipe, 2.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DJH.Knet.pipe@2.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DJH.Knet.pipe&version=2.1.1
                    
Install as a Cake Addin
#tool nuget:?package=DJH.Knet.pipe&version=2.1.1
                    
Install as a Cake Tool

KnetPipe

Here is an example of KnetService code


using DJH.KnetPipe;

namespace KNetDemo
{
    public class KNetService
    {
        //After you get the introduction email for the Knet support ask them for "Raw method" details, and they will share the below details
        //Tran ID
        private static string TranportalId => "";
        private static string TranportalPassword => "";
        private static string TermResourceKey => "";

        public async Task<string> BuildAsync(string amount, string orderId)
        {
            //Track ID should be a unique number, it's better to use random number and store your transaction reference in udf1 for example
            var trackId = (new Random().Next(1000000, 999999999) + 1).ToString();
            var basurl = "https://xxxx.com";
            var account = new AccountConfig(TranportalId, TranportalPassword, TermResourceKey);
            //The page/API that Knet will redirect the customer
            var respUrl = $"{basurl}/knet/{orderId}";
            var respUrlGet = $"{basurl}/knet/{orderId}";

            var paymentRequest = new PaymentRequest(
                trackId,
                respUrl,
                respUrlGet,
                Convert.ToDecimal(amount),
                udf1: orderId,
                udf2: "",
                udf3: "",
                udf4: "",
                udf5: "",
                environment: DJH.KnetPipe.Environment.Test,
                pageLanguage: PageLanguage.English
            );
            var knet = new Payment(account, paymentRequest);
            var respo = knet.Generate();
            return respo.RedirectLink;
        }
    }
}

## Apple Pay Integration

Here's an example of how to process Apple Pay payments:

```csharp
using DJH.KnetPipe;

namespace KNetDemo
{
    public class ApplePayService
    {
        private static string TranportalId => "";
        private static string TranportalPassword => "";
        private static string TermResourceKey => "";

        public async Task<IActionResult> ProcessApplePayment(decimal amount, ApplePayPayload payload)
        {
            var accountConfig = new AccountConfig
            {
                TranportalId = TranportalId,
                TranportalPassword = TranportalPassword,
                TermResourceKey = TermResourceKey
            };

            var trackId = (new Random().Next(10000000) + 1).ToString();

            // Create payment request
            var paymentRequest = new PaymentRequest
            {
                Trackid = "trackid1-" + trackId,
                Amount = amount,
                PageLanguage = PageLanguage.English,
                ResponseURL = "https://example.com/api/applepay/response",
                ErrorURL = "https://example.com/api/applepay/error",
                Environment = DJH.KnetPipe.Environment.Test,
                Udf1 = payload.Name,
                Udf2 = payload.Email,
                Udf3 = "",
                Udf4 = "",
                Udf5 = ""
            };

            // Create Apple Pay specific request
            var applePayRequest = new ApplePayRequest
            {
                TransactionIdentifier = payload.PaymentResponse.Token.TransactionIdentifier,
                PaymentMethod = payload.PaymentResponse.Token.PaymentMethod.ToJson(),
                PaymentData = payload.PaymentResponse.Token.PaymentData.ToJson()
            };
            
            // Initialize payment processor
            var payment = new Payment(accountConfig, paymentRequest);
            
            // Process Apple Pay transaction
            var result = await payment.ProcessApplePayAsync(applePayRequest);
            if (result == null)
                return BadRequest("Result from K-Net is null");

            if (result.IsError)
                return BadRequest(result.ErrorMessage);

            // Handle successful payment
            var knetPaymentResponse = result.PaymentResponse.ToKnetPaymentResponse();
            
            // Process response and return appropriate result
            return Ok(knetPaymentResponse);
        }
    }
}

## Utility Extensions

The `ToJson` extension method used for Apple Pay integration:

```csharp
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace KNetDemo.Extensions
{
    public static class JsonExtensions
    {
        public static string ToJson<T>(this T? value, bool camelCase = true) where T : class
        {
            if (value == null)
                return "";

            if (camelCase)
                return JsonConvert.SerializeObject(value, new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });
            return JsonConvert.SerializeObject(value);
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 258 4/14/2025
2.1.0 198 4/14/2025
1.0.2 7,620 7/27/2020