c#

Parent Previous Next

When using c#, the easiest way to use the PayGate DDMS API is by using the excellent RestSharp package.  You can get this via NuGet by searching for RestSharp.



       string baseUrl = "http://enterprise.paygate.cloud/";

       string username = "myusername";

       string password = "mypassword";

       string apiKey = "myapikey";


           NewAmount newAmount = new NewAmount()

           {

               Username = username,

               Password = password,

               ApiKey = apiKey,

               PayerReference = "00001000",

              Amount   = 123.45M

           };


           // PayGate DDMS API URL for the CreatePayer function

           string paygateApiUrl = $"{baseUrl}/api/Payer/UpdateFinalAmount";


           // REST call to PayGate DDMS API: CreatePayer

           var client = new RestClient(paygateApiUrl);

           var request = new RestRequest(Method.POST);

           request.AddHeader("cache-control", "no-cache");

           request.AddHeader("content-type", "application/json");

           request.AddJsonBody(newAmount);

           IRestResponse response = client.Execute(request);


           // Deserialise the response messages from PayGate

           RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();

           Response paygateResponse = deserial.Deserialize<Response>(response);


           // Display the response

           tbLog.AppendText("Success: " + paygateResponse.Success + Environment.NewLine);

           tbLog.AppendText("Message: " + paygateResponse.Message + Environment.NewLine);

           foreach (string message in paygateResponse.ValidationMessages)

               tbLog.AppendText(message + Environment.NewLine);




Sample Visual Studio 2017 solution


We have prepared a sample Visual Studio Winforms application to get you started.  This solution contains a definition of the NewAmount class.


The solution can be download from the PayGate portal at this address: https://portal.paygate.cloud/cdn/files/paygate/enterprise/sdk/ddms/RestApi/csharp/2.1.3/DDMSRestClient.zip