| [866] | 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using System.Web.Mvc;
|
|---|
| 4 | using Platnosci.Models;
|
|---|
| 5 | using Platnosci.Core.Linq;
|
|---|
| 6 | using Platnosci.Core.Interface;
|
|---|
| 7 |
|
|---|
| 8 | namespace Platnosci.Controllers
|
|---|
| 9 | {
|
|---|
| [880] | 10 |
|
|---|
| [866] | 11 | [Authorize]
|
|---|
| 12 | public class PlatnoscController : Controller
|
|---|
| 13 | {
|
|---|
| [883] | 14 | public const string ISPAID = "payment_deposited"; //transakcja potwierdzona do rozliczenia
|
|---|
| [896] | 15 | private readonly IRepository<vPlatnosciEcard> _repVPayment;
|
|---|
| [933] | 16 | private readonly IRepository<PlatnosciEcard> _repPayment;
|
|---|
| [903] | 17 | private readonly IRepository<PotwierdzeniaEcard> _repConfirm;
|
|---|
| [933] | 18 | private readonly ITranslateManager _translateManager;
|
|---|
| 19 | private readonly FunkcjePlatnosci _funkcjePlatnosci;
|
|---|
| [903] | 20 |
|
|---|
| [866] | 21 | public PlatnoscController()
|
|---|
| 22 | {
|
|---|
| [949] | 23 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext());
|
|---|
| 24 | _repPayment = new Repository<PlatnosciEcard>(new DataContext());
|
|---|
| 25 | _repConfirm = new Repository<PotwierdzeniaEcard>(new DataContext());
|
|---|
| [952] | 26 | _funkcjePlatnosci = new FunkcjePlatnosci(_repPayment);
|
|---|
| [933] | 27 | _translateManager = new Translation();
|
|---|
| [866] | 28 | }
|
|---|
| [927] | 29 | public PlatnoscController(IRepository<vPlatnosciEcard> repVPayment, IRepository<PlatnosciEcard> repPayment, IRepository<PotwierdzeniaEcard> repConfirm, ITranslateManager translate)
|
|---|
| [872] | 30 | {
|
|---|
| [896] | 31 | _repVPayment = repVPayment;
|
|---|
| 32 | _repPayment = repPayment;
|
|---|
| 33 | _repConfirm = repConfirm;
|
|---|
| [933] | 34 | _translateManager = translate;
|
|---|
| [952] | 35 | _funkcjePlatnosci = new FunkcjePlatnosci(_repPayment, _translateManager);
|
|---|
| 36 |
|
|---|
| [870] | 37 | }
|
|---|
| [866] | 38 | public ActionResult Show(string id, string language)
|
|---|
| 39 | {
|
|---|
| [950] | 40 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [933] | 41 | var id1 = ConvertId(id);
|
|---|
| [873] | 42 |
|
|---|
| [933] | 43 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [952] | 44 |
|
|---|
| 45 | var errorViewData = _funkcjePlatnosci.IsError(platnosc, HttpContext.User.Identity.Name);
|
|---|
| 46 | if (!String.IsNullOrEmpty(errorViewData.Error)) return View("Error1", errorViewData);
|
|---|
| [933] | 47 |
|
|---|
| [951] | 48 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc);
|
|---|
| [883] | 49 |
|
|---|
| [933] | 50 | var tablicaPotwierdzenia = _repConfirm.FindItemsByIdFaktury(id1);
|
|---|
| 51 | if (tablicaPotwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana
|
|---|
| [866] | 52 | {
|
|---|
| [933] | 53 | var dataZaplaty = String.Format("{0:dd-MM-yyyy}", tablicaPotwierdzenia[0].AUTHTIME);
|
|---|
| 54 | invoiceDeatailsViewData.info = String.Format(_translateManager.Translate("tlumaczenia","zaplacono"), platnosc.Faktura_Numer, dataZaplaty);
|
|---|
| 55 | invoiceDeatailsViewData.termin = dataZaplaty;
|
|---|
| [883] | 56 | return View("Paid", invoiceDeatailsViewData);
|
|---|
| [885] | 57 | }
|
|---|
| [888] | 58 | return View(invoiceDeatailsViewData);
|
|---|
| [868] | 59 | }
|
|---|
| [866] | 60 | [Authorize]
|
|---|
| 61 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 62 | public ActionResult Show(Payer payer, string language)
|
|---|
| 63 | {
|
|---|
| [956] | 64 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [873] | 65 |
|
|---|
| [866] | 66 | if (String.IsNullOrEmpty(payer.FirstName))
|
|---|
| [933] | 67 | ModelState.AddModelError("Payer.FirstName", _translateManager.Translate("tlumaczenia", "err_imieWK"));
|
|---|
| [956] | 68 | else if (payer.FirstName.Length > 25)
|
|---|
| 69 | ModelState.AddModelError("Payer.FirstName", String.Format(_translateManager.Translate("tlumaczenia", "ToLongValue"), "25"));
|
|---|
| 70 |
|
|---|
| [866] | 71 | if (String.IsNullOrEmpty(payer.LastName))
|
|---|
| [933] | 72 | ModelState.AddModelError("Payer.LastName", _translateManager.Translate("tlumaczenia", "err_nazwiskoWK"));
|
|---|
| [956] | 73 | else if (payer.LastName.Length > 30)
|
|---|
| 74 | ModelState.AddModelError("Payer.LastName", String.Format(_translateManager.Translate("tlumaczenia", "ToLongValue"), "30"));
|
|---|
| 75 |
|
|---|
| [866] | 76 | if (ModelState.IsValid == false)
|
|---|
| 77 | {
|
|---|
| [956] | 78 | var platnosc = _repVPayment.Find(p => p.ID_faktury == payer.Id_faktury).SingleOrDefault();
|
|---|
| 79 | var errorViewData = _funkcjePlatnosci.IsError(platnosc, HttpContext.User.Identity.Name);
|
|---|
| [933] | 80 |
|
|---|
| [956] | 81 | if (!String.IsNullOrEmpty(errorViewData.Error))
|
|---|
| 82 | return View("Error1", errorViewData);
|
|---|
| 83 |
|
|---|
| 84 | return View("Show", InitInvoiceDetailsViewData(platnosc));
|
|---|
| 85 | }
|
|---|
| [933] | 86 | return RedirectToAction("Merchant", "Merchant", payer);
|
|---|
| [866] | 87 | }
|
|---|
| [933] | 88 |
|
|---|
| [926] | 89 | public ActionResult Ok(string id, string language, string o)
|
|---|
| [866] | 90 | {
|
|---|
| [955] | 91 | var order = ConvertId(o);
|
|---|
| 92 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| 93 | var id1 = ConvertId(id);
|
|---|
| [933] | 94 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [955] | 95 |
|
|---|
| 96 | if (platnosc == null)
|
|---|
| [956] | 97 | return View("Error1", _funkcjePlatnosci.InitErrorViewData(_translateManager.Translate("tlumaczenia", "brakdanych"), 0));
|
|---|
| 98 |
|
|---|
| [951] | 99 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc);
|
|---|
| [926] | 100 |
|
|---|
| [956] | 101 | //sprawdzamy czy dla kombinacji ordernumber i idfaktury istnieje platnosc,
|
|---|
| [926] | 102 | //jesli tak, to sprawdzamy czy przyszlo potwierdzenie z eCardu.
|
|---|
| [956] | 103 |
|
|---|
| 104 | if (CheckConfirm(id1, order) == 0) //nie ma potwierdzenia z eCardu
|
|---|
| 105 | invoiceDeatailsViewData.info = String.Format(_translateManager.Translate("tlumaczenia", "blad1"), invoiceDeatailsViewData.vPlatnosciEcard.Faktura_Numer);
|
|---|
| [937] | 106 |
|
|---|
| [956] | 107 | else if (CheckConfirm(id1, order) == 2)
|
|---|
| [937] | 108 | invoiceDeatailsViewData.info = _translateManager.Translate("tlumaczenia", "weryfikacja");
|
|---|
| 109 |
|
|---|
| [956] | 110 | return View(invoiceDeatailsViewData);
|
|---|
| [866] | 111 | }
|
|---|
| [956] | 112 | public ActionResult Fail(string id, string language)
|
|---|
| [871] | 113 | {
|
|---|
| [956] | 114 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [933] | 115 | var id1 = ConvertId(id);
|
|---|
| [956] | 116 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 117 |
|
|---|
| [955] | 118 | if (platnosc == null)
|
|---|
| [956] | 119 | return View("Error1", _funkcjePlatnosci.InitErrorViewData(_translateManager.Translate("tlumaczenia", "brakdanych"), 0));
|
|---|
| 120 |
|
|---|
| 121 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc);
|
|---|
| 122 | return View(invoiceDeatailsViewData);
|
|---|
| [871] | 123 | }
|
|---|
| [903] | 124 | public ActionResult Form()
|
|---|
| 125 | {
|
|---|
| 126 | return View();
|
|---|
| 127 | }
|
|---|
| [866] | 128 | public ActionResult Status()
|
|---|
| [956] | 129 | {
|
|---|
| [933] | 130 | var potwierdzenie = new PotwierdzeniaEcard();
|
|---|
| [911] | 131 | var content = new ContentResult();
|
|---|
| 132 | try
|
|---|
| 133 | {
|
|---|
| 134 | if (!String.IsNullOrEmpty(Request.Form["APPROVALCODE"])) potwierdzenie.APPROVALCODE = Request.Form["APPROVALCODE"];
|
|---|
| 135 | if (!String.IsNullOrEmpty(Request.Form["AUTHTIME"])) potwierdzenie.AUTHTIME = Convert.ToDateTime(Request.Form["AUTHTIME"]);
|
|---|
| 136 | if (!String.IsNullOrEmpty(Request.Form["BIN"])) potwierdzenie.BIN = Request.Form["BIN"];
|
|---|
| 137 | if (!String.IsNullOrEmpty(Request.Form["COMMTYPE"])) potwierdzenie.COMMTYPE = Request.Form["COMMTYPE"];
|
|---|
| [933] | 138 | if (!String.IsNullOrEmpty(Request.Form["CURRENTSTATE"])) potwierdzenie.CURRENTSTATE = Request.Form["CURRENTSTATE"];
|
|---|
| [911] | 139 | if (!String.IsNullOrEmpty(Request.Form["DATATRANSMISJI"])) potwierdzenie.DATATRANSMISJI = Convert.ToDateTime(Request.Form["DATATRANSMISJI"]);
|
|---|
| 140 | if (!String.IsNullOrEmpty(Request.Form["EVENTTYPE"])) potwierdzenie.EVENTTYPE = Convert.ToBoolean(Request.Form["EVENTTYPE"]);
|
|---|
| 141 | if (!String.IsNullOrEmpty(Request.Form["MERCHANTNUMBER"])) potwierdzenie.MERCHANTNUMBER = Request.Form["MERCHANTNUMBER"];
|
|---|
| [933] | 142 | if (!String.IsNullOrEmpty(Request.Form["ORDERNUMBER"])) potwierdzenie.ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]);
|
|---|
| [911] | 143 | if (!String.IsNullOrEmpty(Request.Form["PAYMENTNUMBER"])) potwierdzenie.PAYMENTNUMBER = Convert.ToBoolean(Request.Form["PAYMENTNUMBER"]);
|
|---|
| 144 | if (!String.IsNullOrEmpty(Request.Form["PAYMENTTYPE"])) potwierdzenie.PAYMENTTYPE = Convert.ToBoolean(Request.Form["PAYMENTTYPE"]);
|
|---|
| 145 | if (!String.IsNullOrEmpty(Request.Form["PREVIOUSSTATE"])) potwierdzenie.PREVIOUSSTATE = Request.Form["PREVIOUSSTATE"];
|
|---|
| 146 | if (!String.IsNullOrEmpty(Request.Form["TYPE"])) potwierdzenie.TYPE = Request.Form["TYPE"];
|
|---|
| 147 | if (!String.IsNullOrEmpty(Request.Form["VALIDATIONCODE"])) potwierdzenie.VALIDATIONCODE = Request.Form["VALIDATIONCODE"];
|
|---|
| 148 | if (!String.IsNullOrEmpty(Request.Form["WITHCVC"])) potwierdzenie.WITHCVC = Request.Form["WITHCVC"];
|
|---|
| [866] | 149 |
|
|---|
| [911] | 150 | _repConfirm.Insert(potwierdzenie);
|
|---|
| [933] | 151 |
|
|---|
| 152 | if (potwierdzenie.ORDERNUMBER.HasValue)
|
|---|
| 153 | UpdateStatus(potwierdzenie.ORDERNUMBER.Value, potwierdzenie.CURRENTSTATE);
|
|---|
| 154 |
|
|---|
| [926] | 155 | content.Content = "OK";
|
|---|
| [911] | 156 | }
|
|---|
| 157 | catch(Exception ex)
|
|---|
| 158 | {
|
|---|
| [926] | 159 | content.Content = "FALSE " + ex.Message + " " + ex.GetType();
|
|---|
| [911] | 160 | }
|
|---|
| 161 |
|
|---|
| [908] | 162 | return content;
|
|---|
| [866] | 163 | }
|
|---|
| [933] | 164 |
|
|---|
| 165 | private static Payer InitPayer(int idFaktury)
|
|---|
| [868] | 166 | {
|
|---|
| [933] | 167 | var payer = new Payer {Id_faktury = idFaktury};
|
|---|
| [868] | 168 | return payer;
|
|---|
| 169 | }
|
|---|
| [933] | 170 |
|
|---|
| [951] | 171 | private InvoiceDetailsViewData InitInvoiceDetailsViewData(vPlatnosciEcard platnosc)
|
|---|
| [868] | 172 | {
|
|---|
| 173 | var invoiceDeatailsViewData = new InvoiceDetailsViewData();
|
|---|
| 174 | invoiceDeatailsViewData.vPlatnosciEcard = platnosc;
|
|---|
| [951] | 175 | invoiceDeatailsViewData.Payer = InitPayer(platnosc.ID_faktury);
|
|---|
| 176 | invoiceDeatailsViewData.brutto = _funkcjePlatnosci.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| [868] | 177 | return invoiceDeatailsViewData;
|
|---|
| 178 | }
|
|---|
| [933] | 179 |
|
|---|
| [873] | 180 | public int ConvertId(string id)
|
|---|
| 181 | {
|
|---|
| [933] | 182 | int id1;
|
|---|
| 183 | return Int32.TryParse(id, out id1) ? id1 : 0;
|
|---|
| [873] | 184 | }
|
|---|
| [933] | 185 |
|
|---|
| [883] | 186 | public void UpdateStatus(int ordernumber, string currentstate)
|
|---|
| [873] | 187 | {
|
|---|
| [933] | 188 | var platnosc = _repPayment.Find(p => p.ORDERNUMBER == ordernumber).SingleOrDefault();
|
|---|
| 189 |
|
|---|
| [956] | 190 | if (platnosc != null && currentstate == ISPAID)
|
|---|
| 191 | {
|
|---|
| 192 | platnosc.Status = true;
|
|---|
| 193 | platnosc.Status_data = DateTime.Now;
|
|---|
| 194 | _repPayment.SubmitChanges();
|
|---|
| 195 | }
|
|---|
| [911] | 196 | }
|
|---|
| [933] | 197 |
|
|---|
| [926] | 198 | public int CheckConfirm(int idfaktury, int order)
|
|---|
| 199 | {
|
|---|
| [933] | 200 | var pl = _repPayment.Find(p => p.ORDERNUMBER == order && p.IDFaktury == idfaktury).SingleOrDefault();
|
|---|
| 201 |
|
|---|
| [926] | 202 | if (pl != null)
|
|---|
| 203 | {
|
|---|
| [933] | 204 | var confirm = _repConfirm.Find(p => p.ORDERNUMBER == order).FirstOrDefault();
|
|---|
| [926] | 205 | if (confirm == null) return 0; //potwierdzenie nie przyszlo z eCardu
|
|---|
| 206 | }
|
|---|
| 207 | else
|
|---|
| 208 | {
|
|---|
| 209 | return 2; //nie ma platnosci o takim idfaktury i ordernumber
|
|---|
| 210 | }
|
|---|
| [933] | 211 |
|
|---|
| [926] | 212 | return 1; //potwierdzenie przyszlo z eCardu
|
|---|
| [933] | 213 | }
|
|---|
| [866] | 214 | }
|
|---|
| 215 | }
|
|---|