.NET Örnek Kodları
3Dsiz Ödeme Sayfası
public class DealerPaymentServicePaymentRequest
{
public PaymentDealerAuthentication PaymentDealerAuthentication { get; set; }
public PaymentDealerRequest PaymentDealerRequest { get; set; }
}
public class PaymentDealerAuthentication
{
public string DealerCode { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string CheckKey { get; set; }
}
public class PaymentDealerRequest
{
public string CardHolderFullName { get; set; }
public string CardNumber { get; set; }
public string ExpMonth { get; set; }
public string ExpYear { get; set; }
public string CvcNumber { get; set; }
public decimal Amount { get; set; }
public string Currency { get; set; }
public int InstallmentNumber { get; set; }
public string VirtualPosOrderId { get; set; }
public int VoidRefundReason { get; set; }
public string ClientIP { get; set; }
public string RedirectUrl { get; set; }
public int UtilityCompanyBillId { get; set; }
public int DealerStaffId { get; set; }
}
public class DealerPaymentServiceDirectPaymentResult
{
public DealerPaymentServiceDirectPaymentResultData Data { get; set; }
public string ResultCode { get; set; }
public string ResultMessage { get; set; }
public string Exception { get; set; }
}
public class DealerPaymentServiceDirectPaymentResultData
{
public bool IsSuccessful { get; set; }
public string ResultCode { get; set; }
public string ResultMessage { get; set; }
}
DealerPaymentServicePaymentRequest request = new DealerPaymentServicePaymentRequest();
request.PaymentDealerAuthentication = new PaymentDealerAuthentication();
request.PaymentDealerAuthentication.DealerCode = "250";
request.PaymentDealerAuthentication.Username = "testuser";
request.PaymentDealerAuthentication.Password = "KFNHLRMGHMD";
request.PaymentDealerAuthentication.CheckKey = SHA256Hash(request.DealerCode+"MK"+request.Username+"PD"+request.Password);
request.PaymentDealerRequest = new PaymentDealerRequest();
request.PaymentDealerRequest.CardHolderFullName = "Ahmet Yılmaz";
request.PaymentDealerRequest.CardNumber = "5555666677778888";
request.PaymentDealerRequest.ExpYear = "2017";
request.PaymentDealerRequest.ExpMonth = "12";
request.PaymentDealerRequest.CvcNumber = "123";
request.PaymentDealerRequest.Amount = 0.1m;
request.PaymentDealerRequest.Currency = "TL";
request.PaymentDealerRequest.InstallmentNumber = 1;
request.PaymentDealerRequest.ClientIP = "10.10.10.10";
string postUrl = "https://service.moka.com/PaymentDealer/DoDirectPayment";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(postUrl);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(request);
streamWriter.Write(json);
}
DealerPaymentServiceDirectPaymentResult dealerPaymentServicePaymentResult;
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
string result = streamReader.ReadToEnd();
dealerPaymentServicePaymentResult = new JavaScriptSerializer().Deserialize<DealerPaymentServiceDirectPaymentResult>(result);
}
3D Ödeme Sayfası
public class DealerPaymentServicePaymentRequest
{
public PaymentDealerAuthentication PaymentDealerAuthentication { get; set; }
public PaymentDealerRequest PaymentDealerRequest { get; set; }
}
public class PaymentDealerAuthentication
{
public string DealerCode { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string CheckKey { get; set; }
}
public class PaymentDealerRequest
{
public string CardHolderFullName { get; set; }
public string CardNumber { get; set; }
public string ExpMonth { get; set; }
public string ExpYear { get; set; }
public string CvcNumber { get; set; }
public decimal Amount { get; set; }
public string Currency { get; set; }
public int InstallmentNumber { get; set; }
public string VirtualPosOrderId { get; set; }
public int VoidRefundReason { get; set; }
public string ClientIP { get; set; }
public string RedirectUrl { get; set; }
public int UtilityCompanyBillId { get; set; }
public int DealerStaffId { get; set; }
}
public class DealerPaymentServiceDirectPaymentResult
{
public DealerPaymentServiceDirectPaymentResultData Data { get; set; }
public string ResultCode { get; set; }
public string ResultMessage { get; set; }
public string Exception { get; set; }
}
public class DealerPaymentServiceDirectPaymentResultData
{
public bool IsSuccessful { get; set; }
public string ResultCode { get; set; }
public string ResultMessage { get; set; }
}
public class DealerPaymentServicePaymentResult
{
public string Data { get; set; }
public string ResultCode { get; set; }
public string ResultMessage { get; set; }
public string Exception { get; set; }
}
DealerPaymentServicePaymentRequest request = new DealerPaymentServicePaymentRequest();
request.PaymentDealerAuthentication = new PaymentDealerAuthentication();
request.PaymentDealerAuthentication.DealerCode = "250";
request.PaymentDealerAuthentication.Username = "testuser";
request.PaymentDealerAuthentication.Password = "KLRSMGLSX";
request.PaymentDealerAuthentication.CheckKey = SHA256Hash(request.DealerCode+"MK"+request.Username+"PD"+request.Password);
request.PaymentDealerRequest = new PaymentDealerRequest();
request.PaymentDealerRequest.CardHolderFullName = "Ahmet Yılmaz";
request.PaymentDealerRequest.CardNumber = "5555666677778888";
request.PaymentDealerRequest.ExpMonth = "2017";
request.PaymentDealerRequest.ExpYear = "12";
request.PaymentDealerRequest.CvcNumber = "123";
request.PaymentDealerRequest.Amount = 0.1m;
request.PaymentDealerRequest.Currency = "TL";
request.PaymentDealerRequest.InstallmentNumber = 1;
request.PaymentDealerRequest.ClientIP = "10.10.10.10";
request.PaymentDealerRequest.RedirectUrl = "https://www.abcasdf.com/PayResult?MyTrxId=123456";
string postUrl = "https://service.moka.com/PaymentDealer/DoDirectPaymentThreeD";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(postUrl);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(request);
streamWriter.Write(json);
}
DealerPaymentServicePaymentResult dealerPaymentServicePaymentResult;
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
string result = streamReader.ReadToEnd();
dealerPaymentServicePaymentResult = new JavaScriptSerializer().Deserialize<DealerPaymentServicePaymentResult>(result);
}
if (dealerPaymentServicePaymentResult.ResultCode.Equals("Success"))
{
string redirectUrl = dealerPaymentServicePaymentResult.Data;
return Redirect(redirectUrl);
}
else
{
if (dealerPaymentServicePaymentResult.ResultCode.Equals("PaymentDealer.DoDirectPayment3dRequest.InstallmentNotAvailableForForeignCurrencyTransaction"))
{
ErrorMessage = "Yabancı para işlemlerinde taksit işlemi uygulanamaz!";
}
else if (dealerPaymentServicePaymentResult.ResultCode.Equals("PaymentDealer.DoDirectPayment3dRequest.ThisInstallmentNumberNotAvailableForDealer"))
{
ErrorMessage = "Seçtiğiniz taksit bayi hesabınızda tanımlı değildir!";
}
else if (dealerPaymentServicePaymentResult.ResultCode.Equals("PaymentDealer.DoDirectPayment3dRequest.ForeignCurrencyNotAvailableForThisDealer"))
{
ErrorMessage = "Yabancı para işlemleri bayi tanımınızda tanımlı değildir!";
}
else if (dealerPaymentServicePaymentResult.ResultCode.Equals("PaymentDealer.DoDirectPayment3dRequest.ThisInstallmentNumberNotAvailableForVirtualPos"))
{
ErrorMessage = "Bu taksit sayısı seçili sanal pos için kullanılamaz!";
}
else if (dealerPaymentServicePaymentResult.ResultCode.Equals("PaymentDealer.CheckDealerPaymentLimits.DailyDealerLimitExceeded"))
{
WarningMessage = "Bayi limit aşımı nedeniyle işleminizi gerçekleştiremiyoruz. Lütfen ilgili birimimizle irtibata geçiniz.";
}
}
[HttpPost]
public ActionResult PayResult(bool isSuccessful, string resultCode, string resultMessage, string trxCode)
{
if (isSuccessful)
{
NotificationHelper.SuccessMessage = "Ödeme başarıyla tamamlandı! Trx Code: " + trxCode;
}
else
{
NotificationHelper.ErrorMessage = "Ödeme sırasında bir hata oluştu! ResultCode: " + resultCode + ", Result Message: " + resultMessage + "";
}
return Redirect("/DealerPayment/Pay3d");
}
SHA256 Çevirme Sayfası
string hashKey = dealerCode + "MK" + username + "PD" + password;
System.Text.Encoding encoding = Encoding.UTF8;
byte[] plainBytes = encoding.GetBytes(hashKey);
System.Security.Cryptography.SHA256Managed sha256Engine = new SHA256Managed();
string hashedData = String.Empty;
byte[] hashedBytes = sha256Engine.ComputeHash(plainBytes, 0, encoding.GetByteCount(hashKey));
foreach (byte bit in hashedBytes)
{
hashedData += bit.ToString("x2");
}
return hashedData;
TLS 1.1 ve 1.2 yi Force Etme
Global.asax.cs dosyasının içerisinde,protected void Application_Start() metodunun içine
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
Örnek Projeyi İndirmek İçin Tıklayınız.