namespace ProtectPayApi_CaptureTransaction
{
using System;
using System.Text;
using RestSharp;
/*
ProPay provides the following code “AS IS.”
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/
public class CaptureTransactionProgram
{
public static void Main(string[] args)
{
var CaptureTransactionResponse = CaptureTransaction();
}
private static CreateTransactionResult CaptureTransaction()
{
var baseUrl = "https://xmltestapi.propay.com/ProtectPay";
var request = BuildCaptureTransactionRequest();
var restRequest = CreateRestRequest("/CapturedTransactions/", RestSharp.Method.PUT);
restRequest.AddBody(request);
return Execute<CreateTransactionResult>(restRequest, baseUrl);
}
private static CaptureTransactionRequest BuildCaptureTransactionRequest()
{
return new CaptureTransactionRequest
{
MerchantProfileId = 123456,
TransactionHistoryId = 6091209,
Amount = 1000,
CurrencyCode = "USD",
};
}
private static RestRequest CreateRestRequest(string resource, Method method)
{
var restRequest = new RestRequest { Resource = resource, Method = method, RequestFormat = DataFormat.Json, };
var credentials = GetCredentials();
restRequest.AddHeader("accept", "application/json");
restRequest.AddHeader("Authorization", credentials);
return restRequest;
}
private static string GetCredentials()
{
var billerAccountId = "5114248593164903"; // biller account id
var authToken = "9d506d3e-b5f7-4474-adb1-76423e113c85"; // authentication token of biller
var encodedCredentials = Convert.ToBase64String(Encoding.Default.GetBytes(billerAccountId + ":" + authToken));
var credentials = string.Format("Basic {0}", encodedCredentials);
return credentials;
}
private static T Execute<T>(IRestRequest request, string baseUrl) where T : class, new()
{
var client = new RestClient(baseUrl);
var response = client.Execute<T>(request);
if (response.ErrorException != null)
{
Console.WriteLine(
"Error: Exception: {0}, Headers: {1}, Content: {2}, Status Code: {3}",
response.ErrorException,
response.Headers,
response.Content,
response.StatusCode);
}
return response.Data;
}
public class CaptureTransactionRequest
{
public long MerchantProfileId { get; set; }
public long TransactionHistoryId { get; set; }
public long Amount { get; set; }
public string CurrencyCode { get; set; }
}
public class CreateTransactionResult
{
public Trans Transaction { get; set; }
}
public class Trans
{
public string AVSCode { get; set; }
public string AuthorizationCode { get; set; }
public decimal CurrencyConversionRate { get; set; }
public long CurrencyConvertedAmount { get; set; }
public resultc ResultCode { get; set; }
public long TransactionHistoryId { get; set; }
public long TransactionId { get; set; }
public string TransactionResult { get; set; }
public string CVVResponseCode { get; set; }
public long GrossAmt { get; set; }
public long NetAmt { get; set; }
public long PerTransFee { get; set; }
public decimal Rate { get; set; }
public long GrossAmtLessNetAmt { get; set; }
public result RequestResult { get; set; }
}
public class resultc
{
public string ResultValue { get; set; }
public string ResultCode { get; set; }
public string ResultMessage { get; set; }
}
public class result
{
public string ResultValue { get; set; }
public string ResultCode { get; set; }
public string ResultMessage { get; set; }
}
}