From e4816c8e323d33e448a9b83b7a3f8e8312488ff0 Mon Sep 17 00:00:00 2001 From: c1982 Date: Mon, 31 Mar 2014 23:09:35 +0300 Subject: [PATCH] First Commit Yeah! --- .gitattributes | 22 ++ .gitignore | 215 +++++++++++++ GarantiVP.sln | 26 ++ GarantiVP/Client.cs | 371 ++++++++++++++++++++++ GarantiVP/GVPSRequest.cs | 147 +++++++++ GarantiVP/GVPSResponse.cs | 84 +++++ GarantiVP/GarantiVP.csproj | 56 ++++ GarantiVP/IGarantiVPBuilder.cs | 136 ++++++++ GarantiVP/Properties/AssemblyInfo.cs | 36 +++ GarantiVp.Test/GarantiVp.Test.csproj | 89 ++++++ GarantiVp.Test/Properties/AssemblyInfo.cs | 36 +++ GarantiVp.Test/VPTests.cs | 295 +++++++++++++++++ 12 files changed, 1513 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 GarantiVP.sln create mode 100644 GarantiVP/Client.cs create mode 100644 GarantiVP/GVPSRequest.cs create mode 100644 GarantiVP/GVPSResponse.cs create mode 100644 GarantiVP/GarantiVP.csproj create mode 100644 GarantiVP/IGarantiVPBuilder.cs create mode 100644 GarantiVP/Properties/AssemblyInfo.cs create mode 100644 GarantiVp.Test/GarantiVp.Test.csproj create mode 100644 GarantiVp.Test/Properties/AssemblyInfo.cs create mode 100644 GarantiVp.Test/VPTests.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/GarantiVP.sln b/GarantiVP.sln new file mode 100644 index 0000000..a903713 --- /dev/null +++ b/GarantiVP.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarantiVP", "GarantiVP\GarantiVP.csproj", "{C51ED10F-F4FD-4B08-B9F9-B4C917724E46}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarantiVp.Test", "GarantiVp.Test\GarantiVp.Test.csproj", "{D4EB1D47-4FE8-41DF-8326-D2EAF460A778}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C51ED10F-F4FD-4B08-B9F9-B4C917724E46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C51ED10F-F4FD-4B08-B9F9-B4C917724E46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C51ED10F-F4FD-4B08-B9F9-B4C917724E46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C51ED10F-F4FD-4B08-B9F9-B4C917724E46}.Release|Any CPU.Build.0 = Release|Any CPU + {D4EB1D47-4FE8-41DF-8326-D2EAF460A778}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4EB1D47-4FE8-41DF-8326-D2EAF460A778}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4EB1D47-4FE8-41DF-8326-D2EAF460A778}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4EB1D47-4FE8-41DF-8326-D2EAF460A778}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/GarantiVP/Client.cs b/GarantiVP/Client.cs new file mode 100644 index 0000000..4ca9961 --- /dev/null +++ b/GarantiVP/Client.cs @@ -0,0 +1,371 @@ +namespace GarantiVP +{ + using System; + using System.IO; + using System.Net; + using System.Net.Security; + using System.Security.Cryptography; + using System.Security.Cryptography.X509Certificates; + using System.Text; + using System.Xml; + using System.Xml.Serialization; + + public class Client : IGarantiVPBuilder + { + private GVPSRequest request; + + private readonly string REQUEST_TEST_MODE = "TEST"; + private readonly string REQUEST_PROD_MODE = "PROD"; + private readonly string REQUEST_USER_PROVAUT = "PROVAUT"; //Provizyon kullanıcısı + private readonly string REQUEST_USER_PROVRFN = "PROVRFN"; //İptal ve İade işlemlerinde kullanılır + + private string REQUEST_URL; + private string _secureString; + + public Client(bool test = false) + { + request = new GVPSRequest(); + + request.Mode = REQUEST_PROD_MODE; + request.Version = "v0.01"; + + request.Terminal = new Terminal(); + request.Terminal.ProvUserID = REQUEST_USER_PROVAUT; + + request.Transaction = new Transaction(); + request.Transaction.Type = TransactionType.sales.ToString(); + request.Transaction.MotoInd = "N"; + request.Transaction.CurrencyCode = String.Format("{0}", (int)CurrencyCode.TRL); + + this.REQUEST_URL = "https://sanalposprov.garanti.com.tr/VPServlet"; ; + } + + public IGarantiVPBuilder Server(string posUrl) + { + if (!String.IsNullOrEmpty(posUrl)) + REQUEST_URL = posUrl; + + return this; + } + + public IGarantiVPBuilder Test(bool test = false) + { + if (test) + { + this.REQUEST_URL = "https://sanalposprovtest.garanti.com.tr/VPServlet"; + request.Mode = REQUEST_TEST_MODE; + } + + return this; + } + + + public IGarantiVPBuilder Company(string terminalId, string MerchantID, string userID, string userPassword) + { + request.Terminal.ID = terminalId; //isRequireZero(terminalId, 9); + request.Terminal.MerchantID = MerchantID; + request.Terminal.UserID = userID; + + this._secureString = GetSHA1(userPassword + isRequireZero(terminalId, 9)).ToUpper(); + + return this; + } + + public IGarantiVPBuilder Customer(string customerMail, string customerIP) + { + request.Customer = request.Customer ?? new Customer(); + + request.Customer.EmailAddress = customerMail; + request.Customer.IPAddress = customerIP; + + return this; + } + + public IGarantiVPBuilder CreditCard(string number, string cvv2, int month, int year) + { + request.Card = request.Card ?? new Card(); + + request.Card.Number = number; + request.Card.CVV2 = cvv2.ToString(); + request.Card.ExpireDate = String.Format("{0}{1}", isRequireZero(month), isRequireZero(year)); + + return this; + } + + public IGarantiVPBuilder Order(string orderID, string groupID = "") + { + request.Order = request.Order ?? new Order(); + request.Order.OrderID = orderID; + request.Order.GroupID = groupID; + + return this; + } + + public IGarantiVPBuilder Amount(double totalAmount, CurrencyCode currencyCode = CurrencyCode.TRL) + { + request.Transaction.Amount = (Math.Round(totalAmount, 2) * 100).ToString(); + request.Transaction.CurrencyCode = String.Format("{0}", (int)currencyCode); + + return this; + } + + public IGarantiVPBuilder Installment(int installment) + { + request.Transaction.InstallmentCnt = installment <= 0 ? String.Empty : installment.ToString(); + + return this; + } + + public IGarantiVPBuilder Delay(int day) + { + request.Transaction.DelayDayCount = day.ToString(); + + return this; + } + + public IGarantiVPBuilder DownPaymentRate(int rate) + { + request.Transaction.DownPaymentRate = rate.ToString(); + return this; + } + + public GVPSResponse Sales() + { + request.Transaction.Type = TransactionType.sales.ToString(); + request.Transaction.CardholderPresentCode = "0"; + + request.Terminal.HashData = GetSHA1(request.Order.OrderID + + request.Terminal.ID + + request.Card.Number + + request.Transaction.Amount + + this._secureString).ToUpper(); + + return Send(); + } + + public GVPSResponse Refund() + { + request.Transaction.Type = TransactionType.refund.ToString(); + request.Terminal.ProvUserID = REQUEST_USER_PROVRFN; + request.Transaction.CardholderPresentCode = "0"; + request.Transaction.MotoInd = "H"; + + request.Terminal.HashData = GetSHA1(request.Order.OrderID + + request.Terminal.ID + + request.Transaction.Amount + + this._secureString).ToUpper(); + + return Send(); + } + + public GVPSResponse RefundCancel(string RefundRetrefNum) + { + return Cancel(RefundRetrefNum); + } + + public GVPSResponse Cancel(string RetrefNum) + { + request.Transaction.Type = TransactionType.@void.ToString(); + request.Terminal.ProvUserID = REQUEST_USER_PROVRFN; + request.Transaction.OriginalRetrefNum = RetrefNum; + + request.Terminal.HashData = GetSHA1(request.Order.OrderID + + request.Terminal.ID + + request.Transaction.Amount + + this._secureString).ToUpper(); + + return Send(); + } + + public GVPSResponse Preauth() + { + request.Transaction.Type = TransactionType.preauth.ToString(); + request.Transaction.MotoInd = "N"; + request.Transaction.CardholderPresentCode = "0"; + + request.Terminal.HashData = GetSHA1(request.Order.OrderID + + request.Terminal.ID + + request.Card.Number + + request.Transaction.Amount + + this._secureString).ToUpper(); + + return Send(); + } + + public GVPSResponse PostauthCancel(string RetrefNum) + { + return Cancel(RetrefNum); + } + + public GVPSResponse Postauth(string RetrefNum) + { + request.Transaction.Type = TransactionType.postauth.ToString(); + request.Transaction.CardholderPresentCode = "0"; + request.Transaction.OriginalRetrefNum = RetrefNum; + + return Send(); + } + + public GVPSResponse Verification(string TCKN) + { + request.Transaction.Verification = request.Transaction.Verification ?? new Verification(); + + request.Transaction.Type = TransactionType.identifyinq.ToString(); + request.Transaction.Verification.Identity = TCKN; + + request.Terminal.HashData = GetSHA1(request.Order.OrderID + + request.Terminal.ID + + request.Card.Number + + request.Transaction.Amount + + this._secureString).ToUpper(); + + return Send(); + } + + #region Privates + private string isRequireZero(int time) + { + return time < 10 ? String.Format("0{0}", time) : + time > 2000 ? + isRequireZero(time - 2000) : time.ToString(); + } + + static string isRequireZero(string id, int complete) + { + var _tmp = id.Trim(); + + if (_tmp.Length < complete) + for (int i = 0; (i < (complete - _tmp.Length)); i++) + id = id.Insert(0, "0"); + + return id; + } + + private string GetSHA1(string SHA1Data) + { + var sha = new SHA1CryptoServiceProvider(); + var HashedPassword = SHA1Data; + + byte[] hashbytes = Encoding.GetEncoding("iso-8859-9").GetBytes(HashedPassword); + byte[] inputbytes = sha.ComputeHash(hashbytes); + + return GetHexaDecimal(inputbytes); + } + + private string GetHexaDecimal(byte[] bytes) + { + var s = new StringBuilder(); + var length = bytes.Length; + + for (int n = 0; n <= length - 1; n++) + s.Append(String.Format("{0,2:x}", bytes[n]).Replace(" ", "0")); + + return s.ToString(); + } + + private string SerializeObjectToXmlString(T TModel) + { + string xmlData = String.Empty; + + XmlSerializerNamespaces EmptyNameSpace = new XmlSerializerNamespaces(); + EmptyNameSpace.Add("", ""); + + XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); + MemoryStream memoryStream = new MemoryStream(); + XmlTextWriter xmlWriter = new XmlTextWriter(memoryStream, + Encoding.GetEncoding("iso-8859-9")); + + xmlSerializer.Serialize(xmlWriter, TModel, EmptyNameSpace); + + memoryStream = (MemoryStream)xmlWriter.BaseStream; + xmlData = UTF8ByteArrayToString(memoryStream.ToArray()); + + return xmlData; + } + + private String UTF8ByteArrayToString(Byte[] characters) + { + + UTF8Encoding encoding = new UTF8Encoding(); + String constructedString = encoding.GetString(characters); + return (constructedString); + } + + private T DeSerializeObject(string xmlData) + { + T deSerializeObject = default(T); + + XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); + StringReader stringReader = new StringReader(xmlData); + XmlReader XR = new XmlTextReader(stringReader); + + if (xmlSerializer.CanDeserialize(XR)) + { + deSerializeObject = (T)xmlSerializer.Deserialize(XR); + } + + return deSerializeObject; + } + + private string SendHttpRequest(string Host, string Method, string Params) + { + System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate + (object sender, X509Certificate certificate, X509Chain chain, + SslPolicyErrors sslPolicyErrors) + { return true; }; + + var returnSrting = String.Empty; + + var request = (HttpWebRequest)WebRequest.Create(Host); + request.Timeout = 30000; + request.Method = Method; + + var bytes = new ASCIIEncoding().GetBytes(Params); + request.ContentType = "application/x-www-form-urlencoded"; + request.ContentLength = Params.Length; + + using (var requestStream = request.GetRequestStream()) + { + requestStream.Write(bytes, 0, bytes.Length); + requestStream.Close(); + } + + using (StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream())) + { + returnSrting = sr.ReadToEnd(); + } + + return returnSrting; + } + + private GVPSResponse Send() + { + var gvpResponse = new GVPSResponse(); + var xmlString = SerializeObjectToXmlString(request); + + gvpResponse.RawRequest = xmlString; + + try + { + var responseString = SendHttpRequest(REQUEST_URL, "Post", String.Format("data={0}", xmlString)); + + gvpResponse = DeSerializeObject(responseString); + gvpResponse.RawRequest = xmlString; + gvpResponse.RawResponse = responseString; + } + catch (Exception ex) + { + gvpResponse.Transaction = new ResponseTransaction(); + gvpResponse.Order = new ResponseOrder(); + gvpResponse.Transaction.Response = new Response(); + + gvpResponse.Transaction.Response.Code = "99"; + gvpResponse.Transaction.Response.Message = ex.Message; + gvpResponse.Transaction.Response.ErrorMsg = ex.StackTrace; + } + + return gvpResponse; + } + #endregion + } +} diff --git a/GarantiVP/GVPSRequest.cs b/GarantiVP/GVPSRequest.cs new file mode 100644 index 0000000..2e88827 --- /dev/null +++ b/GarantiVP/GVPSRequest.cs @@ -0,0 +1,147 @@ +namespace GarantiVP +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Xml.Serialization; + + [Serializable] + [XmlRoot("GVPSRequest", Namespace = null)] + public class GVPSRequest + { + [XmlElement] + public string Mode { get; set; } + + [XmlElement] + public string Version { get; set; } + + [XmlElement] + public Terminal Terminal { get; set; } + + [XmlElement] + public Customer Customer { get; set; } + + [XmlElement] + public Card Card { get; set; } + + [XmlElement] + public Order Order { get; set; } + + [XmlElement] + public Transaction Transaction { get; set; } + + + } + + public class Terminal + { + [XmlElement] + public string ProvUserID { get; set; } + + [XmlElement] + public string HashData { get; set; } + + [XmlElement] + public string UserID { get; set; } + + [XmlElement] + public string ID { get; set; } + + [XmlElement] + public string MerchantID { get; set; } + + } + + public class Customer + { + [XmlElement] + public string IPAddress { get; set; } + + [XmlElement] + public string EmailAddress { get; set; } + } + + public class Card + { + + [XmlElement] + public string Number { get; set; } + + /// + /// must be MMYY format. + /// + [XmlElement] + public string ExpireDate { get; set; } + + [XmlElement] + public string CVV2 { get; set; } + + } + + public class Order + { + [XmlElement] + public string OrderID { get; set; } + + [XmlElement] + public string GroupID { get; set; } + } + + public class Transaction + { + [XmlElement] + public string Type { get; set; } + + [XmlElement] + public string InstallmentCnt { get; set; } + + [XmlElement] + public string Amount { get; set; } + + [XmlElement] + public string CurrencyCode { get; set; } + + [XmlElement] + public string CardholderPresentCode { get; set; } + + [XmlElement] + public string MotoInd { get; set; } + + [XmlElement] + public string OriginalRetrefNum { get; set; } + + [XmlElement] + public string DelayDayCount { get; set; } + + [XmlElement] + public string DownPaymentRate { get; set; } + + [XmlElement] + public Verification Verification { get; set; } + } + + public class Verification + { + public string Identity { get; set; } + } + + public enum CurrencyCode : int + { + TRL = 949, + USD = 840, + EURO = 978, + GBP = 826, + JPY = 392 + } + + public enum TransactionType + { + sales, + @void, + refund, + preauth, + postauth, + identifyinq + } +} diff --git a/GarantiVP/GVPSResponse.cs b/GarantiVP/GVPSResponse.cs new file mode 100644 index 0000000..8ef7668 --- /dev/null +++ b/GarantiVP/GVPSResponse.cs @@ -0,0 +1,84 @@ +namespace GarantiVP +{ + using System; + using System.Xml.Serialization; + + [Serializable] + [XmlRoot("GVPSResponse", Namespace = null)] + public class GVPSResponse + { + [XmlElement("Order")] + public ResponseOrder Order { get; set; } + + [XmlElement(ElementName = "Transaction")] + public ResponseTransaction Transaction { get; set; } + + public string RawRequest { get; set; } + + public string RawResponse { get; set; } + } + + public class ResponseOrder + { + [XmlElement] + public string OrderID { get; set; } + } + + public class ResponseTransaction + { + [XmlElement] + public Response Response { get; set; } + + [XmlElement] + public string RetrefNum { get; set; } + + [XmlElement] + public string AuthCode { get; set; } + + [XmlElement] + public string BatchNum { get; set; } + + [XmlElement] + public string SequenceNum { get; set; } + + [XmlElement] + public string ProvDate { get; set; } + + [XmlElement] + public string HostMsgList { get; set; } + + [XmlElement] + public RewardInqResult RewardInqResult { get; set; } + } + + public class Response + { + + [XmlElement] + public string Source { get; set; } + + [XmlElement] + public string Code { get; set; } + + [XmlElement] + public string ReasonCode { get; set; } + + [XmlElement] + public string Message { get; set; } + + [XmlElement] + public string ErrorMsg { get; set; } + + [XmlElement] + public string SysErrMsg { get; set; } + } + + public class RewardInqResult + { + [XmlElement] + public string RewardList { get; set; } + + [XmlElement] + public string ChequeList { get; set; } + } +} diff --git a/GarantiVP/GarantiVP.csproj b/GarantiVP/GarantiVP.csproj new file mode 100644 index 0000000..ac876e2 --- /dev/null +++ b/GarantiVP/GarantiVP.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {C51ED10F-F4FD-4B08-B9F9-B4C917724E46} + Library + Properties + GarantiVP + GarantiVP + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GarantiVP/IGarantiVPBuilder.cs b/GarantiVP/IGarantiVPBuilder.cs new file mode 100644 index 0000000..3084d64 --- /dev/null +++ b/GarantiVP/IGarantiVPBuilder.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarantiVP +{ + public interface IGarantiVPBuilder + { + /// + /// + /// + /// + /// TEST, PROD + /// + IGarantiVPBuilder Server(string posUrl); + + /// + /// İşlemler Test sunucusuna yönlendirilir. + /// + /// + IGarantiVPBuilder Test(bool test = true); + + /// + /// Firma bilgileri + /// + /// + /// + /// + /// + /// + IGarantiVPBuilder Company(string terminalId, string MerchantID, string userID, string userPassword); + + /// + /// Müşteri Bilgileri + /// + /// Müşteri eposta adresi + /// Müşterinin IP adresi + /// + IGarantiVPBuilder Customer(string customerMail, string customerIP); + + + IGarantiVPBuilder CreditCard(string number, string cvv2, int month, int year); + + /// + /// Sipariş Numarası. Boş bırakılırsa sistem otomatik bir numara belirler + /// + /// + /// + /// + IGarantiVPBuilder Order(string orderID, string groupID = ""); + + /// + /// Kredi Kartından çekilecek tutar + /// + /// Tutar + /// Para Birimi. Varsayılan: TRL + /// + IGarantiVPBuilder Amount(double totalAmount, CurrencyCode currencyCode = CurrencyCode.TRL); + + /// + /// Taksitli işlemlerde işlem tutarının üzerinden belli bir oranda peşinat alınmasının sağlanması için kullanılan işlemdir. + /// + /// Peşinat oranı yüzde olarak belirlenir. %10 ise 10 girilir + /// + IGarantiVPBuilder DownPaymentRate(int rate); + + /// + /// Taksitli İşlem + /// + /// Taksit Sayısı + /// + IGarantiVPBuilder Installment(int installment); + + /// + /// Ötelemeli Satış + /// + /// Ötelenecek gün sayısı. + /// + IGarantiVPBuilder Delay(int day); + + /// + /// Satış + /// + /// + GVPSResponse Sales(); + + /// + /// Geri İade + /// + /// + GVPSResponse Refund(); + + /// + /// Geri İade İptali + /// + /// + /// + GVPSResponse RefundCancel(string RefundRetrefNum); + + /// + /// İptal + /// + /// + /// + GVPSResponse Cancel(string RetrefNum); + + /// + /// Önotorizasyon + /// + /// + GVPSResponse Preauth(); + + /// + /// Önotorizasyon Tamamlama/Onaylama + /// + /// Önotorizasyon Numarası + /// + GVPSResponse Postauth(string RetrefNum); + + /// + /// Önotorizasyon Tamamlama/Onaylama İptali + /// + /// Önotorizasyon Numarası + /// + GVPSResponse PostauthCancel(string RetrefNum); + + /// + /// Kredi Kartı TC Kimlik No Doğrulaması. + /// + /// TC Kimlik No + /// + GVPSResponse Verification(string TCKN); + } +} diff --git a/GarantiVP/Properties/AssemblyInfo.cs b/GarantiVP/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c2c584c --- /dev/null +++ b/GarantiVP/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GarantiVP")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GarantiVP")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("db36ea65-b3bf-474c-9b05-20a123b12bb3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GarantiVp.Test/GarantiVp.Test.csproj b/GarantiVp.Test/GarantiVp.Test.csproj new file mode 100644 index 0000000..10b3232 --- /dev/null +++ b/GarantiVp.Test/GarantiVp.Test.csproj @@ -0,0 +1,89 @@ + + + + Debug + AnyCPU + {D4EB1D47-4FE8-41DF-8326-D2EAF460A778} + Library + Properties + GarantiVp.Test + GarantiVp.Test + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {c51ed10f-f4fd-4b08-b9f9-b4c917724e46} + GarantiVP + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file diff --git a/GarantiVp.Test/Properties/AssemblyInfo.cs b/GarantiVp.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..10a1f99 --- /dev/null +++ b/GarantiVp.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GarantiVp.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GarantiVp.Test")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("eb31e49f-effc-4577-93fe-066f71d23967")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GarantiVp.Test/VPTests.cs b/GarantiVp.Test/VPTests.cs new file mode 100644 index 0000000..a0e0009 --- /dev/null +++ b/GarantiVp.Test/VPTests.cs @@ -0,0 +1,295 @@ +namespace GarantiVp.Test +{ + using System; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using GarantiVP; + using System.Diagnostics; + + [TestClass] + public class VPTests + { + private readonly string terminalId = "30691297"; + private readonly string merchandId = "7000679"; + private readonly string Password = "123qweASD"; + + private readonly string orderId = "cc5f63d899e64f39b996b1e9156a270e"; + private readonly string OrderRefNumber = "000014610000"; + + private readonly string credit_card_number = "0000209000008010"; + private readonly string credit_card_cvv2 = "123"; + private readonly int credit_card_month = 2; + private readonly int credit_card_year = 15; + + [TestMethod] + public void SalesTest() + { + var _pay = new Client().Test().Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Order(Guid.NewGuid().ToString("N")) + .Amount(95, CurrencyCode.TRL) + .Sales(); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void Sales_USD_Test() + { + var _pay = new Client().Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Order(Guid.NewGuid().ToString("N")) + .Amount(95, CurrencyCode.USD) + .Sales(); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void SalesWithInstallmentTest() + { + var _pay = new Client().Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Order(Guid.NewGuid().ToString("N")) + .Amount(95) + .Installment(2) + .Sales(); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void Delay_SalesTest() + { + var _pay = new Client().Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Order(Guid.NewGuid().ToString("N")) + .Delay(10) + .Amount(95) + .Sales(); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void DownPaymentRate_SalesTest() + { + var _pay = new Client().Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Order(Guid.NewGuid().ToString("N")) + .DownPaymentRate(5) + .Amount(95) + .Sales(); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + + [TestMethod] + public void CancelTest() + { + var _pay = new Client() + .Test() + .Company(terminalId, merchandId, "PROVRFN", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .Order(orderId) + .Amount(95) + .Cancel(OrderRefNumber); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void RefundTest() + { + var _pay = new Client() + .Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .Order(orderId) + .Amount(95) + .Refund(); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void RefundCancelTest() + { + var _pay = new Client() + .Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .Order(orderId) + .Amount(95) + .RefundCancel(OrderRefNumber); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void PreauthSalesTest() + { + var _pay = new Client() + .Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Order(Guid.NewGuid().ToString("N")) + .Amount(95) + .Preauth(); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void PostauthSalesTest() + { + var _pay = new Client() + .Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Order(orderId) + .Amount(95) + .Postauth(OrderRefNumber); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void PostauthSalesCancelTest() + { + var _pay = new Client() + .Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .Order(orderId) + .Amount(95) + .PostauthCancel(OrderRefNumber); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + + [TestMethod] + public void TCKNVerificationTest() + { + var tc_kimlik_no = "000000000000"; + + var _pay = new Client() + .Test() + .Company(terminalId, merchandId, "PROVAUT", Password) + .Customer("apsrc@gmail.com", "192.168.0.1") + .Order(Guid.NewGuid().ToString("N")) + .CreditCard(credit_card_number, credit_card_cvv2, credit_card_month, credit_card_year) + .Amount(1) + .Verification(tc_kimlik_no); + + Debug.WriteLine("Request: " + _pay.RawRequest); + Debug.WriteLine("Response: " + _pay.RawResponse); + + Debug.WriteLine(_pay.Transaction.Response.Message); + Debug.WriteLine(_pay.Transaction.Response.ErrorMsg); + Debug.WriteLine(_pay.Transaction.Response.SysErrMsg); + + Assert.AreEqual("00", _pay.Transaction.Response.Code); + Assert.AreEqual("Approved", _pay.Transaction.Response.Message); + } + } +}