SDK (c#)

The easiest way to integrate with the Payment API is with the SDK, which is a nuget package called LinkMobility.PaymentCore.Sdk.

 Your nuget.config file should be updated like below in order for your project to connect Payment API nuget feed. Contact the support team for package access.

<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="link-internal" value="https://pkgs.dev.azure.com/linkmobilitygroup/_packaging/link-internal/nuget/v3/index.json" protocolVersion="3" /> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> </packageSources> <packageSourceCredentials> <link-internal> <add key="Username" value="nugetfeeds" /> <add key="ClearTextPassword" value="q35ma*******************5a" /> </link-internal> </packageSourceCredentials> <activePackageSource> <add key="All" value="(Aggregate source)" /> </activePackageSource> </configuration>

 

Once you modified your nuget.config, your build pipeline will be able to fetch the required packages.

Fetching packages to your local environment

There are 2 ways of doing this. 1st one is using the command below via Nuget Package Manager Console

Install-Package LinkMobility.PaymentCore.Sdk -version 8.0.0

Another way to achieve this is to use Visual Studio’s UI features.

 

image-20240605-074247.png

 

Code example snippets:

 

First create a client:

IPaymentCoreClient _paymentCoreClient = ClientFactory.Create(_partnerId, _sharedKey, _baseUri, ClientFactory.DefaultTimeout, RetryPolicy.DefaultExponential);

Example 1: Creating a Pre-Transaction

The CreatePretransaction method creates a pre-transaction, which is an initial step in the payment process. This method constructs a PreTransactionRequest object with necessary details such as PartnerId, Msisdn, SmsNotificationText, Currency, Amount, and ReturnUrl. It then calls the SDK's CreatePreTransactionAsync method to initiate the pre-transaction and returns the preTransactionId.

public static async Task<string> CreatePretransaction() { var request = new PreTransactionRequest { PartnerId = _partnerId, ViewTemplateName = null, CorrelationId = Guid.NewGuid().ToString(), ExpiryUtc = DateTime.UtcNow.AddDays(1), Msisdn = "+47********", SmsNotificationOriginator = "2012", SmsNotificationText = "Betal her: {{paymentSelectionPageUrl}}", Currency = "DKK", Amount = 1, ReturnUrl = $"{_baseUri}/receipts/10295/{{transactionId}}", PaymentProviders = new List<string> { "dibs" }.ToArray(), Description = "SDK Console Test", CustomProperties = new Dictionary<string, string> { { "kravtil", "Qliro AB" }, { "saksnr", "33206733" } } }; var preTransactionId = await _paymentCoreClient.CreatePreTransactionAsync(request); return preTransactionId; }

Example 2: Capturing a Transaction

The CaptureTransaction method captures a previously initiated transaction. This step is usually performed after the transaction has been authorized. The method requires a transactionId and uses the SDK's CaptureTransactionAsync method to complete the capture.

 

Example 3: Refunding a Transaction

The RefundTransaction method refunds a captured transaction. This is useful in scenarios where the customer needs to be reimbursed. The method requires a transactionId and calls the SDK's RefundTransactionAsync method to process the refund.

Feeling lost? Click on this link! Portal page