| 25 | | private readonly PlatnosciDataContext _context; |
| 26 | | private readonly IDataContext _context1; |
| 27 | | private readonly IRepository<PotwierdzeniaEcard> _rep; |
| 28 | | private readonly IRepository<PlatnosciEcard> _repPl; |
| 29 | | private FunkcjePlatnosci _func; |
| 30 | | private string weryfikacja; |
| 31 | | private string brakdanych; |
| 32 | | private string zaplacono; |
| 33 | | private string err_imie; |
| 34 | | private string err_nazwisko; |
| 35 | | private int test = 0; |
| 36 | | |
| | 15 | private readonly IRepository<vPlatnosciEcard> _repVPayment; |
| | 16 | private readonly IRepository<PlatnosciEcard> _repPayment; |
| | 17 | private readonly IRepository<PotwierdzeniaEcard> _repConfirm; |
| | 18 | private readonly ITranslateManager _translateManager; |
| | 19 | private readonly FunkcjePlatnosci _funkcjePlatnosci; |
| | 20 | |
| 39 | | _context = new PlatnosciDataContext(); |
| 40 | | _rep = new Repository<PotwierdzeniaEcard>(new DataContext1()); |
| 41 | | _repPl = new Repository<PlatnosciEcard>(new DataContext1()); |
| 42 | | _func = new FunkcjePlatnosci(); |
| 43 | | |
| 44 | | } |
| 45 | | public PlatnoscController(IDataContext datacontext, int czy_test) |
| 46 | | { |
| 47 | | _rep = new Repository<PotwierdzeniaEcard>(datacontext); |
| 48 | | _repPl = new Repository<PlatnosciEcard>(datacontext); |
| 49 | | _context1 = datacontext; |
| 50 | | _func = new FunkcjePlatnosci(); |
| 51 | | test = czy_test; |
| | 23 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext1()); |
| | 24 | _repPayment = new Repository<PlatnosciEcard>(new DataContext1()); |
| | 25 | _repConfirm = new Repository<PotwierdzeniaEcard>(new DataContext1()); |
| | 26 | _funkcjePlatnosci = new FunkcjePlatnosci(); |
| | 27 | _translateManager = new Translation(); |
| | 28 | } |
| | 29 | public PlatnoscController(IRepository<vPlatnosciEcard> repVPayment, IRepository<PlatnosciEcard> repPayment, IRepository<PotwierdzeniaEcard> repConfirm, ITranslateManager translate) |
| | 30 | { |
| | 31 | _repVPayment = repVPayment; |
| | 32 | _repPayment = repPayment; |
| | 33 | _repConfirm = repConfirm; |
| | 34 | _funkcjePlatnosci = new FunkcjePlatnosci(); |
| | 35 | _translateManager = translate; |
| 55 | | language = _func.setLanguage(language); |
| 56 | | ustawTlumaczenia(test); |
| 57 | | int id1 = ConvertId(id); |
| 58 | | |
| 59 | | vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault(); |
| 60 | | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc)); |
| 61 | | |
| 62 | | string kwota = ""; |
| 63 | | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano); |
| 64 | | var payer = InitPayer("", "", platnosc.ID_faktury); |
| | 39 | _funkcjePlatnosci.setLanguage(language); |
| | 40 | var id1 = ConvertId(id); |
| | 41 | |
| | 42 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault(); |
| | 43 | if (!String.IsNullOrEmpty(IsError(platnosc).Error)) return View("Error1", IsError(platnosc)); |
| | 44 | |
| | 45 | var kwota = _funkcjePlatnosci.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano); |
| | 46 | |
| | 47 | var payer = InitPayer(platnosc.ID_faktury); |
| | 48 | |
| 67 | | var tablica_potwierdzenia = _rep.FindItemsByIdFaktury(id1); |
| 68 | | if (tablica_potwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana |
| 69 | | { |
| 70 | | string data_zaplaty = String.Format("{0:dd-MM-yyyy}", tablica_potwierdzenia[0].AUTHTIME); |
| 71 | | invoiceDeatailsViewData.info = String.Format(zaplacono, platnosc.Faktura_Numer, data_zaplaty); |
| 72 | | invoiceDeatailsViewData.termin = data_zaplaty; |
| | 51 | var tablicaPotwierdzenia = _repConfirm.FindItemsByIdFaktury(id1); |
| | 52 | if (tablicaPotwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana |
| | 53 | { |
| | 54 | var dataZaplaty = String.Format("{0:dd-MM-yyyy}", tablicaPotwierdzenia[0].AUTHTIME); |
| | 55 | invoiceDeatailsViewData.info = String.Format(_translateManager.Translate("tlumaczenia","zaplacono"), platnosc.Faktura_Numer, dataZaplaty); |
| | 56 | invoiceDeatailsViewData.termin = dataZaplaty; |
| 99 | | return View("Show",viewData); |
| 100 | | } |
| 101 | | if (payer != null) |
| 102 | | { |
| 103 | | System.Diagnostics.Debug.WriteLine("PlatnosciController:Show"); |
| 104 | | return RedirectToAction("Merchant", "Merchant", payer); |
| 105 | | } |
| 106 | | else return View("Error"); |
| 107 | | } |
| 108 | | public ActionResult Ok(string id, string language) |
| 109 | | { |
| 110 | | language = _func.setLanguage(language); |
| 111 | | ustawTlumaczenia(test); |
| 112 | | int id1 = ConvertId(id); |
| 113 | | vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault(); |
| 114 | | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc)); |
| | 83 | return View("Show",viewData); |
| | 84 | } |
| | 85 | |
| | 86 | return RedirectToAction("Merchant", "Merchant", payer); |
| | 87 | } |
| | 88 | |
| | 89 | public ActionResult Ok(string id, string language, string o) |
| | 90 | { |
| | 91 | var order = ConvertId(o); |
| | 92 | |
| | 93 | _funkcjePlatnosci.setLanguage(language); |
| | 94 | |
| | 95 | var id1 = ConvertId(id); |
| | 96 | |
| | 97 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault(); |
| | 98 | |
| | 99 | if (!String.IsNullOrEmpty(IsError(platnosc).Error)) return View("Error1", IsError(platnosc)); |
| 132 | | string MERCHANTNUMBER = Request.Form["MERCHANTNUMBER"]; |
| 133 | | int ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]); |
| 134 | | string COMMTYPE = Request.Form["COMMTYPE"]; |
| 135 | | string CURRENTSTATE = Request.Form["CURRENTSTATE"]; |
| 136 | | string PREVIOUSSTATE = Request.Form["PREVIOUSSTATE"]; |
| 137 | | bool PAYMENTTYPE = Convert.ToBoolean(Request.Form["PAYMENTTYPE"]); |
| 138 | | bool EVENTTYPE = Convert.ToBoolean(Request.Form["EVENTTYPE"]); |
| 139 | | bool PAYMENTNUMBER = Convert.ToBoolean(Request.Form["PAYMENTNUMBER"]); |
| 140 | | string APPROVALCODE = Request.Form["APPROVALCODE"]; |
| 141 | | string VALIDATIONCODE = Request.Form["VALIDATIONCODE"]; |
| 142 | | string BIN = Request.Form["BIN"]; |
| 143 | | DateTime AUTHTIME = Convert.ToDateTime(Request.Form["AUTHTIME"]); |
| 144 | | string TYPE = Request.Form["TYPE"]; |
| 145 | | string WITHCVC = Request.Form["WITHCVC"]; |
| 146 | | DateTime DATATRANSMISJI = Convert.ToDateTime(Request.Form["DATATRANSMISJI"]); |
| 147 | | |
| 148 | | PotwierdzeniaEcard potwierdzenie = new PotwierdzeniaEcard(); |
| 149 | | potwierdzenie.APPROVALCODE = APPROVALCODE; |
| 150 | | potwierdzenie.AUTHTIME = AUTHTIME; |
| 151 | | potwierdzenie.BIN = BIN; |
| 152 | | potwierdzenie.COMMTYPE = COMMTYPE; |
| 153 | | potwierdzenie.CURRENTSTATE = CURRENTSTATE; |
| 154 | | potwierdzenie.DATATRANSMISJI = DATATRANSMISJI; |
| 155 | | potwierdzenie.EVENTTYPE = EVENTTYPE; |
| 156 | | potwierdzenie.MERCHANTNUMBER = MERCHANTNUMBER; |
| 157 | | potwierdzenie.ORDERNUMBER = ORDERNUMBER; |
| 158 | | potwierdzenie.PAYMENTNUMBER = PAYMENTNUMBER; |
| 159 | | potwierdzenie.PAYMENTTYPE = PAYMENTTYPE; |
| 160 | | potwierdzenie.PREVIOUSSTATE = PREVIOUSSTATE; |
| 161 | | potwierdzenie.TYPE = TYPE; |
| 162 | | potwierdzenie.VALIDATIONCODE = VALIDATIONCODE; |
| 163 | | potwierdzenie.WITHCVC = WITHCVC; |
| 164 | | |
| 165 | | _rep.Insert(potwierdzenie); |
| 166 | | UpdateStatus(ORDERNUMBER, CURRENTSTATE); |
| 167 | | return View(); |
| 168 | | } |
| 169 | | private Payer InitPayer(string FirstName, string LastName, int Id_faktury) |
| 170 | | { |
| 171 | | Payer payer = new Payer(); |
| 172 | | payer.FirstName = ""; |
| 173 | | payer.LastName = ""; |
| 174 | | payer.Id_faktury = Id_faktury; |
| | 135 | var potwierdzenie = new PotwierdzeniaEcard(); |
| | 136 | var content = new ContentResult(); |
| | 137 | try |
| | 138 | { |
| | 139 | if (!String.IsNullOrEmpty(Request.Form["APPROVALCODE"])) potwierdzenie.APPROVALCODE = Request.Form["APPROVALCODE"]; |
| | 140 | if (!String.IsNullOrEmpty(Request.Form["AUTHTIME"])) potwierdzenie.AUTHTIME = Convert.ToDateTime(Request.Form["AUTHTIME"]); |
| | 141 | if (!String.IsNullOrEmpty(Request.Form["BIN"])) potwierdzenie.BIN = Request.Form["BIN"]; |
| | 142 | if (!String.IsNullOrEmpty(Request.Form["COMMTYPE"])) potwierdzenie.COMMTYPE = Request.Form["COMMTYPE"]; |
| | 143 | if (!String.IsNullOrEmpty(Request.Form["CURRENTSTATE"])) potwierdzenie.CURRENTSTATE = Request.Form["CURRENTSTATE"]; |
| | 144 | if (!String.IsNullOrEmpty(Request.Form["DATATRANSMISJI"])) potwierdzenie.DATATRANSMISJI = Convert.ToDateTime(Request.Form["DATATRANSMISJI"]); |
| | 145 | if (!String.IsNullOrEmpty(Request.Form["EVENTTYPE"])) potwierdzenie.EVENTTYPE = Convert.ToBoolean(Request.Form["EVENTTYPE"]); |
| | 146 | if (!String.IsNullOrEmpty(Request.Form["MERCHANTNUMBER"])) potwierdzenie.MERCHANTNUMBER = Request.Form["MERCHANTNUMBER"]; |
| | 147 | if (!String.IsNullOrEmpty(Request.Form["ORDERNUMBER"])) potwierdzenie.ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]); |
| | 148 | if (!String.IsNullOrEmpty(Request.Form["PAYMENTNUMBER"])) potwierdzenie.PAYMENTNUMBER = Convert.ToBoolean(Request.Form["PAYMENTNUMBER"]); |
| | 149 | if (!String.IsNullOrEmpty(Request.Form["PAYMENTTYPE"])) potwierdzenie.PAYMENTTYPE = Convert.ToBoolean(Request.Form["PAYMENTTYPE"]); |
| | 150 | if (!String.IsNullOrEmpty(Request.Form["PREVIOUSSTATE"])) potwierdzenie.PREVIOUSSTATE = Request.Form["PREVIOUSSTATE"]; |
| | 151 | if (!String.IsNullOrEmpty(Request.Form["TYPE"])) potwierdzenie.TYPE = Request.Form["TYPE"]; |
| | 152 | if (!String.IsNullOrEmpty(Request.Form["VALIDATIONCODE"])) potwierdzenie.VALIDATIONCODE = Request.Form["VALIDATIONCODE"]; |
| | 153 | if (!String.IsNullOrEmpty(Request.Form["WITHCVC"])) potwierdzenie.WITHCVC = Request.Form["WITHCVC"]; |
| | 154 | |
| | 155 | _repConfirm.Insert(potwierdzenie); |
| | 156 | |
| | 157 | if (potwierdzenie.ORDERNUMBER.HasValue) |
| | 158 | UpdateStatus(potwierdzenie.ORDERNUMBER.Value, potwierdzenie.CURRENTSTATE); |
| | 159 | |
| | 160 | content.Content = "OK"; |
| | 161 | } |
| | 162 | catch(Exception ex) |
| | 163 | { |
| | 164 | content.Content = "FALSE " + ex.Message + " " + ex.GetType(); |
| | 165 | } |
| | 166 | |
| | 167 | return content; |
| | 168 | } |
| | 169 | |
| | 170 | private static Payer InitPayer(int idFaktury) |
| | 171 | { |
| | 172 | var payer = new Payer {Id_faktury = idFaktury}; |
| 211 | | int id1 = 0; |
| 212 | | try |
| 213 | | { |
| 214 | | id1 = (id != null) ? Convert.ToInt32(id) : 0; |
| 215 | | } |
| 216 | | catch |
| 217 | | { |
| 218 | | } |
| 219 | | return id1; |
| 220 | | } |
| 221 | | public ErrorViewData Iserror(vPlatnosciEcard platnosc) |
| 222 | | { |
| 223 | | string errortxt = ""; |
| 224 | | if (platnosc == null) errortxt = brakdanych; |
| 225 | | else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) errortxt = weryfikacja; |
| 226 | | ErrorViewData errorViewData = _func.InitErrorViewData(errortxt); |
| 227 | | return errorViewData; |
| 228 | | } |
| | 188 | int id1; |
| | 189 | return Int32.TryParse(id, out id1) ? id1 : 0; |
| | 190 | } |
| | 191 | |
| | 192 | public ErrorViewData IsError(vPlatnosciEcard platnosc) |
| | 193 | { |
| | 194 | var errortxt = ""; |
| | 195 | |
| | 196 | if (platnosc == null) |
| | 197 | errortxt = _translateManager.Translate("tlumaczenia", "brakdanych"); |
| | 198 | else if (!_funkcjePlatnosci.UserIdentity(platnosc, HttpContext.User.Identity.Name)) |
| | 199 | errortxt = _translateManager.Translate("tlumaczenia","weryfikacja"); |
| | 200 | |
| | 201 | return _funkcjePlatnosci.InitErrorViewData(errortxt,0); |
| | 202 | } |
| | 203 | |
| 231 | | PlatnosciEcard platnosc = _repPl.FindOne(ordernumber); |
| 232 | | if (platnosc != null && currentstate == ISPAID) |
| 233 | | { |
| 234 | | platnosc.Status = true; |
| 235 | | platnosc.Status_data = DateTime.Now; |
| 236 | | _repPl.SubmitChanges(); |
| 237 | | |
| 238 | | System.Diagnostics.Debug.WriteLine("IsUpdate"); |
| 239 | | } |
| 240 | | } |
| | 206 | var platnosc = _repPayment.Find(p => p.ORDERNUMBER == ordernumber).SingleOrDefault(); |
| | 207 | |
| | 208 | if (platnosc == null || currentstate != ISPAID) return; |
| | 209 | |
| | 210 | platnosc.Status = true; |
| | 211 | platnosc.Status_data = DateTime.Now; |
| | 212 | _repPayment.SubmitChanges(); |
| | 213 | } |
| | 214 | |
| | 215 | public int CheckConfirm(int idfaktury, int order) |
| | 216 | { |
| | 217 | var pl = _repPayment.Find(p => p.ORDERNUMBER == order && p.IDFaktury == idfaktury).SingleOrDefault(); |
| | 218 | |
| | 219 | if (pl != null) |
| | 220 | { |
| | 221 | var confirm = _repConfirm.Find(p => p.ORDERNUMBER == order).FirstOrDefault(); |
| | 222 | if (confirm == null) return 0; //potwierdzenie nie przyszlo z eCardu |
| | 223 | } |
| | 224 | else |
| | 225 | { |
| | 226 | return 2; //nie ma platnosci o takim idfaktury i ordernumber |
| | 227 | } |
| | 228 | |
| | 229 | return 1; //potwierdzenie przyszlo z eCardu |
| | 230 | } |