public String getEntriesAfterEmployeeVerification(String lastVerificationStatusUpdateThreshold, String apiKey, String apiTimeStamp, String apiSig) { DateTime lvsut; bool Error = false; StringBuilder resultBuilder = new StringBuilder(); if(apiKey!="apikey") { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"API_KEY_INVALID\" message=\"Api key {0} does not exists.\" requestMethod=\"{1}\" requestTime=\"{2}\" requestURL=\"{3}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", apiKey, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } if(!Error) { if(!Regex.IsMatch(lastVerificationStatusUpdateThreshold,@"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+01:00")) { //Błąd - data niepoprawna Response.StatusCode = 404; Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"PARAMETER_BAD_FORMAT\" message=\"Parameter lastVerificationStatusUpdateThreshold must be a proper format.\" requestMethod=\"{0}\" requestTime=\"{1}\" requestURL=\"{2}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } } if(!Error) { try { DateTime.Parse(lastVerificationStatusUpdateThreshold); } catch(Exception) { //Błąd - data niepoprawna Response.StatusCode = 404; Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"PARAMETER_BAD_FORMAT\" message=\"Parameter lastVerificationStatusUpdateThreshold must be a proper format.\" requestMethod=\"{0}\" requestTime=\"{1}\" requestURL=\"{2}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } } //DateTime lvsut; XDocument xdoc = null; if (!Error) { xdoc = new XDocument( new XDeclaration("1.0", "utf-8", null), new XElement("getEntriesForPaymentVerificationResponse", new XAttribute("time", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00")), new XAttribute("fake", "fakeValue"), new XElement("entries")) ); using(LeaderDataClassesDataContext dc = new LeaderDataClassesDataContext()) { var entries = (from entry in dc.t_leader_entries where (entry.status == 4 || entry.status == 5)// && entry.updateDate >= lvsut select entry).ToList(); foreach(t_leader_entry entry in entries) { xdoc.Descendants("entries").First().Add(new XElement("entry", new XElement("entryId", entry.entryId.ToString()), new XElement("verificationStatusId", entry.status.ToString()) ) ); } } DateTime now = DateTime.Now; #region zrezygnowałem //var lastThresholdBeforeLvsut = (from threshold in dc.t_leader_thresholds // where threshold.threshold > lvsut // orderby threshold.threshold ascending // select threshold).ToList().FirstOrDefault(); //var newestThreshold = (from threshold in dc.t_leader_thresholds // orderby threshold.threshold descending // select threshold).ToList().FirstOrDefault(); //if(lastThresholdBeforeLvsut == null) //{ // t_leader_threshold newt = new t_leader_threshold() { threshold = now }; // dc.t_leader_thresholds.InsertOnSubmit(newt); //} #endregion zrezygnowałem xdoc.Descendants("entries").First().AddAfterSelf(new XElement("lastVerificationStatusUpdateTime", now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"))); resultBuilder = new StringBuilder(xdoc.ToString()); resultBuilder.Replace("fake", "xmlns").Replace("xmlnsValue", "http://leader.raiffeisen.pl/api"); } return resultBuilder.ToString(); }
public String setVerificationStatus(String entryId, int verificationStatusId, int addressTypeId, String customerName, String customerAddress, String comment, String apiKey, String apiTimeStamp, String apiSig) { DateTime lvsut; bool Error = false; StringBuilder resultBuilder = new StringBuilder(); if(apiKey != "apikey") { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"API_KEY_INVALID\" message=\"Api key {0} does not exists.\" requestMethod=\"{1}\" requestTime=\"{2}\" requestURL=\"{3}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", apiKey, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } using(LeaderDataClassesDataContext dc = new LeaderDataClassesDataContext()) { var updatedEntry = (from entry in dc.t_leader_entries where entry.entryId.ToString().Equals(entryId) select entry).FirstOrDefault(); if(updatedEntry == null) { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"ENTRY_NOT_FOUND\" message=\"Entry {0} does not exists or is not a transfer validated entry.\" requestMethod=\"{1}\" requestTime=\"{2}\" requestURL=\"{3}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", entryId, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } if(!Error && updatedEntry.status == 1000) { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"ENTRY_STATUS_ENDING\" message=\"Entry {0} is in ending status.\" requestMethod=\"{1}\" requestTime=\"{2}\" requestURL=\"{3}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", entryId, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } if(!Error && !(verificationStatusId == 1 || verificationStatusId == 2 || verificationStatusId == 3)) { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"VERIFICATION_STATUS_NOT_FOUND\" message=\"Verification status {0} is incorrect.\" requestMethod=\"{1}\" requestTime=\"{2}\" requestURL=\"{3}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", verificationStatusId, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } if(!Error && !(addressTypeId == 1 || addressTypeId == 2)) { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"ADDRESS_TYPE_NOT_FOUND\" message=\"Address type {0} is incorrect.\" requestMethod=\"{1}\" requestTime=\"{2}\" requestURL=\"{3}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", verificationStatusId, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } if(!Error) { int newStatus = verificationStatusId; int oldStatus = updatedEntry.status; if(!(oldStatus == 0 && (newStatus == 1 || newStatus == 2 || newStatus == 3))) { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"VERIFICATION_WORKFLOW_VIOLATION\" message=\"Verification status change for entry {0} from status {1} to status {2} violates the workflow.\" requestMethod=\"{3}\" requestTime=\"{4}\" requestURL=\"{5}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", entryId, oldStatus, newStatus, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } } if(!Error) { updatedEntry.status = verificationStatusId; updatedEntry.comment = comment; updatedEntry.customerName = customerName; updatedEntry.customerAddress = customerAddress; updatedEntry.addressTypeId = addressTypeId; dc.SubmitChanges(); XDocument xdoc = new XDocument( new XDeclaration("1.0", "utf-8", null), new XElement("setVerificationStatus", new XAttribute("time", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00")), new XAttribute("fake", "fakeValue"))); resultBuilder = new StringBuilder(xdoc.ToString()); resultBuilder.Replace("fake", "xmlns").Replace("xmlnsValue", "http://leader.raiffeisen.pl/api"); } } return resultBuilder.ToString(); }
public String getEntriesForPaymentVerification(String lastVerificationStatusUpdateThreshold, String apiKey, String apiTimeStamp, String apiSig) { #region exampleXML /** <getEntriesForPaymentVerificationResponse time="2014-02-12T09:41:37.824+01:00" xmlns="http://leader.raiffeisen.pl/api"> <entries> <entry> <entryId>139332</entryId> <transactionId>XcNbNPFcru8c8wuq</transactionId> <creationTime>2014-01-08T11:17:14.671+01:00</creationTime> <firstName>testst</firstName> <lastName>etstste</lastName> <registrationAddress> <street /> <houseNumber /> <apartmentNumber /> <postCode /> <city /> </registrationAddress> <mailAddress> <street /> <houseNumber /> <apartmentNumber /> <postCode /> <city /> </mailAddress> </entry> <lastVerificationStatusUpdateTime>2014-02-05T10:22:32.112+01:00</lastVerificationStatusUpdateTime> </entries> </getEntriesForPaymentVerificationResponse> */ #endregion exampleXML //https://eapi-leader-imp-ow.ext.e-point.pl:5767/ // Test/getEntriesForPaymentVerification?lastVerificationStatusUpdateThreshold=2012-01-01T00%3a00%3a00.000%2b01%3a00&apiKey=aiW5raicohf2aeTa&apiTimestamp=2014-02-12T09%3a48%3a45.506%2b01%3a00&apiSig=718cca7d0f486bb85b4ac3cf25b0d18debbad7428b01fa0feea909bb16a3a895 bool Error = false; StringBuilder resultBuilder = new StringBuilder(); if(apiKey!="apikey") { Response.StatusCode = 404; //Nie bawię się w 401 itd, jak jest w specyfikacji, bo to i tak nie jest rozróżniane w LeaderMatch a tylko komplikuje sprawę Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"API_KEY_INVALID\" message=\"Api key {0} does not exists.\" requestMethod=\"{1}\" requestTime=\"{2}\" requestURL=\"{3}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", apiKey, Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } if(!Error) { if(!Regex.IsMatch(lastVerificationStatusUpdateThreshold,@"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+01:00")) { //Błąd - data niepoprawna Response.StatusCode = 404; Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"PARAMETER_BAD_FORMAT\" message=\"Parameter lastVerificationStatusUpdateThreshold must be a proper format.\" requestMethod=\"{0}\" requestTime=\"{1}\" requestURL=\"{2}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } } if(!Error) { try { DateTime.Parse(lastVerificationStatusUpdateThreshold); } catch(Exception) { //Błąd - data niepoprawna Response.StatusCode = 404; Error = true; resultBuilder = new StringBuilder(String.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?><error code=\"PARAMETER_BAD_FORMAT\" message=\"Parameter lastVerificationStatusUpdateThreshold must be a proper format.\" requestMethod=\"{0}\" requestTime=\"{1}\" requestURL=\"{2}\" xmlns=\"http://leader.raiffeisen.pl/api\" />", Request.HttpMethod.ToString(), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"), Request.Url.ToString().Replace("&", ";"))); } } //DateTime lvsut; XDocument xdoc = null; if(!Error) { xdoc = new XDocument( new XDeclaration("1.0", "utf-8", null), new XElement("getEntriesForPaymentVerificationResponse", new XAttribute("time",DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00")), new XAttribute("fake","fakeValue"), new XElement("entries")) ); using(LeaderDataClassesDataContext dc = new LeaderDataClassesDataContext()) { var entries = (from entry in dc.t_leader_entries where entry.status == 0 //&& entry.updateDate >= lvsut select entry).ToList(); foreach(t_leader_entry entry in entries) { xdoc.Descendants("entries").First().Add(new XElement("entry", new XElement("entryId",entry.entryId.ToString()), new XElement("transactionId",entry.transactionId), new XElement("creationTime", entry.createDate.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00")), new XElement("firstName",entry.firstName), new XElement("lastName",entry.lastName), new XElement("registrationAddress", new XElement("street", entry.street), new XElement("houseNumber", entry.houseNumber), new XElement("apartmentNumber", entry.apartmentNumber), new XElement("postCode", entry.postCode), new XElement("city", entry.city) ), new XElement("mailAddress", new XElement("street", entry.streetMail), new XElement("houseNumber", entry.houseNumberMail), new XElement("apartmentNumber", entry.apartmentNumberMail), new XElement("postCode", entry.postCodeMail), new XElement("city", entry.cityMail) ) ) ); } DateTime now = DateTime.Now; #region zrezygnowałem //Na razie rezygnuję z threshold - nie podali konkretnie algorytmu //var lastThresholdBeforeLvsut = (from threshold in dc.t_leader_thresholds // where threshold.threshold > lvsut // orderby threshold.threshold ascending // select threshold).ToList().FirstOrDefault(); //var newestThreshold = (from threshold in dc.t_leader_thresholds // orderby threshold.threshold descending // select threshold).ToList().FirstOrDefault(); //if(lastThresholdBeforeLvsut == null) //{ // t_leader_threshold newt = new t_leader_threshold() { threshold = now }; // dc.t_leader_thresholds.InsertOnSubmit(newt); //} #endregion zrezygnowałem xdoc.Descendants("entries").First().AddAfterSelf(new XElement("lastVerificationStatusUpdateTime", now.ToString("yyyy-MM-ddTHH:mm:ss.fff+01:00"))); resultBuilder = new StringBuilder(xdoc.ToString()); resultBuilder.Replace("fake", "xmlns").Replace("xmlnsValue", "http://leader.raiffeisen.pl/api"); } } return resultBuilder.ToString(); }