namespace ProtectPayApi_AuthorizePaymentMethodTransaction
{
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 AuthorizePaymentMethodTransactionProgram
{
public static void Main(string[] args)
{
var authorizePaymentMethodTransactionResponse = AuthorizePaymentMethodTransaction();
}
private static CreateTransactionResult AuthorizePaymentMethodTransaction()
{
var baseUrl = "https://xmltestapi.propay.com/ProtectPay";
var request = BuildAuthorizePaymentMethodTransactionRequest();
var restRequest = CreateRestRequest("/AuthorizedTransactions/", RestSharp.Method.PUT);
restRequest.AddBody(request);
return Execute<CreateTransactionResult>(restRequest, baseUrl);
}
private static AuthorizePaymentMethodTransactionRequest BuildAuthorizePaymentMethodTransactionRequest()
{
return new AuthorizePaymentMethodTransactionRequest
{
PaymentMethodId = "de1ae2bd-c194-437c-ba9a-cb0730bd92d1",
IsRecurringPayment = false,
ExpirationDate = "0323",
MerchantProfileId = 123456,
PayerAccountId = "5823760912097888",
Amount = 1000,
CurrencyCode = "USD",
Invoice = "abc123",
};
}
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 AuthorizePaymentMethodTransactionRequest
{
public string PaymentMethodId { get; set; }
public bool IsRecurringPayment { get; set; }
public CCOverrides CreditCardOverrides { get; set; }
public long MerchantProfileId { get; set; }
public string PayerAccountId { get; set; }
public long Amount { get; set; }
public string CurrencyCode { get; set; }
public string Invoice { get; set; }
}
public class CCOverrides
{
public string ExpirationDate { get; set; }
public string CVV { 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; }
}
}