| [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 | {
|
|---|
| [950] | 64 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [873] | 65 |
|
|---|
| [933] | 66 | var platnosc = _repVPayment.Find(p => p.ID_faktury == payer.Id_faktury).SingleOrDefault();
|
|---|
| [954] | 67 | var errorViewData = _funkcjePlatnosci.IsError(platnosc, HttpContext.User.Identity.Name);
|
|---|
| 68 | if (!String.IsNullOrEmpty(errorViewData.Error)) return View("Error1", errorViewData);
|
|---|
| [933] | 69 |
|
|---|
| [866] | 70 | if (String.IsNullOrEmpty(payer.FirstName))
|
|---|
| [933] | 71 | ModelState.AddModelError("Payer.FirstName", _translateManager.Translate("tlumaczenia", "err_imieWK"));
|
|---|
| [952] | 72 |
|
|---|
| [866] | 73 | if (String.IsNullOrEmpty(payer.LastName))
|
|---|
| [933] | 74 | ModelState.AddModelError("Payer.LastName", _translateManager.Translate("tlumaczenia", "err_nazwiskoWK"));
|
|---|
| [952] | 75 |
|
|---|
| 76 | if (payer.FirstName.Length > 25)
|
|---|
| 77 | ModelState.AddModelError("Payer.FirstName", String.Format(_translateManager.Translate("tlumaczenia", "ToLongValue"),"25"));
|
|---|
| 78 |
|
|---|
| 79 | if (payer.LastName.Length > 30)
|
|---|
| 80 | ModelState.AddModelError("Payer.LastName", String.Format(_translateManager.Translate("tlumaczenia", "ToLongValue"),"30"));
|
|---|
| 81 |
|
|---|
| [866] | 82 | if (ModelState.IsValid == false)
|
|---|
| 83 | {
|
|---|
| [933] | 84 | var kwota = _funkcjePlatnosci.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| [951] | 85 | var viewData = InitInvoiceDetailsViewData(platnosc);
|
|---|
| [919] | 86 | return View("Show",viewData);
|
|---|
| [933] | 87 | }
|
|---|
| 88 |
|
|---|
| 89 | return RedirectToAction("Merchant", "Merchant", payer);
|
|---|
| [866] | 90 | }
|
|---|
| [933] | 91 |
|
|---|
| [926] | 92 | public ActionResult Ok(string id, string language, string o)
|
|---|
| [866] | 93 | {
|
|---|
| [955] | 94 | var order = ConvertId(o);
|
|---|
| 95 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| 96 | var id1 = ConvertId(id);
|
|---|
| [933] | 97 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [955] | 98 |
|
|---|
| 99 | if (platnosc == null)
|
|---|
| 100 | {
|
|---|
| 101 | var errorViewData = _funkcjePlatnosci.InitErrorViewData(_translateManager.Translate("tlumaczenia", "brakdanych"), 0);
|
|---|
| 102 | return View("Error1", errorViewData);
|
|---|
| 103 | }
|
|---|
| [933] | 104 |
|
|---|
| [951] | 105 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc);
|
|---|
| [926] | 106 |
|
|---|
| 107 | //sprawdzamy czy dla kombinacji ordernumber i idfaktury istnieje platnosc,
|
|---|
| 108 | //jesli tak, to sprawdzamy czy przyszlo potwierdzenie z eCardu.
|
|---|
| 109 | if (order > 0)
|
|---|
| 110 | if (CheckConfirm(id1, order) == 0) //nie ma potwierdzenia z eCardu
|
|---|
| [933] | 111 | invoiceDeatailsViewData.info = String.Format(_translateManager.Translate("tlumaczenia", "blad1"), invoiceDeatailsViewData.vPlatnosciEcard.Faktura_Numer);
|
|---|
| [937] | 112 |
|
|---|
| 113 | if (order == 0 || (CheckConfirm(id1, order) == 2) && order > 0 )
|
|---|
| 114 | invoiceDeatailsViewData.info = _translateManager.Translate("tlumaczenia", "weryfikacja");
|
|---|
| 115 |
|
|---|
| [866] | 116 | return View(invoiceDeatailsViewData);
|
|---|
| 117 | }
|
|---|
| [926] | 118 | public ActionResult Fail(string id, string language)
|
|---|
| [871] | 119 | {
|
|---|
| [950] | 120 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [933] | 121 | var id1 = ConvertId(id);
|
|---|
| 122 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [919] | 123 |
|
|---|
| [955] | 124 | if (platnosc == null)
|
|---|
| 125 | {
|
|---|
| 126 | var errorViewData = _funkcjePlatnosci.InitErrorViewData(_translateManager.Translate("tlumaczenia", "brakdanych"), 0);
|
|---|
| 127 | return View("Error1", errorViewData);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| [951] | 130 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc);
|
|---|
| [873] | 131 | return View(invoiceDeatailsViewData);
|
|---|
| [871] | 132 | }
|
|---|
| [903] | 133 | public ActionResult Form()
|
|---|
| 134 | {
|
|---|
| 135 | return View();
|
|---|
| 136 | }
|
|---|
| [866] | 137 | public ActionResult Status()
|
|---|
| 138 | {
|
|---|
| [933] | 139 | var potwierdzenie = new PotwierdzeniaEcard();
|
|---|
| [911] | 140 | var content = new ContentResult();
|
|---|
| 141 | try
|
|---|
| 142 | {
|
|---|
| 143 | if (!String.IsNullOrEmpty(Request.Form["APPROVALCODE"])) potwierdzenie.APPROVALCODE = Request.Form["APPROVALCODE"];
|
|---|
| 144 | if (!String.IsNullOrEmpty(Request.Form["AUTHTIME"])) potwierdzenie.AUTHTIME = Convert.ToDateTime(Request.Form["AUTHTIME"]);
|
|---|
| 145 | if (!String.IsNullOrEmpty(Request.Form["BIN"])) potwierdzenie.BIN = Request.Form["BIN"];
|
|---|
| 146 | if (!String.IsNullOrEmpty(Request.Form["COMMTYPE"])) potwierdzenie.COMMTYPE = Request.Form["COMMTYPE"];
|
|---|
| [933] | 147 | if (!String.IsNullOrEmpty(Request.Form["CURRENTSTATE"])) potwierdzenie.CURRENTSTATE = Request.Form["CURRENTSTATE"];
|
|---|
| [911] | 148 | if (!String.IsNullOrEmpty(Request.Form["DATATRANSMISJI"])) potwierdzenie.DATATRANSMISJI = Convert.ToDateTime(Request.Form["DATATRANSMISJI"]);
|
|---|
| 149 | if (!String.IsNullOrEmpty(Request.Form["EVENTTYPE"])) potwierdzenie.EVENTTYPE = Convert.ToBoolean(Request.Form["EVENTTYPE"]);
|
|---|
| 150 | if (!String.IsNullOrEmpty(Request.Form["MERCHANTNUMBER"])) potwierdzenie.MERCHANTNUMBER = Request.Form["MERCHANTNUMBER"];
|
|---|
| [933] | 151 | if (!String.IsNullOrEmpty(Request.Form["ORDERNUMBER"])) potwierdzenie.ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]);
|
|---|
| [911] | 152 | if (!String.IsNullOrEmpty(Request.Form["PAYMENTNUMBER"])) potwierdzenie.PAYMENTNUMBER = Convert.ToBoolean(Request.Form["PAYMENTNUMBER"]);
|
|---|
| 153 | if (!String.IsNullOrEmpty(Request.Form["PAYMENTTYPE"])) potwierdzenie.PAYMENTTYPE = Convert.ToBoolean(Request.Form["PAYMENTTYPE"]);
|
|---|
| 154 | if (!String.IsNullOrEmpty(Request.Form["PREVIOUSSTATE"])) potwierdzenie.PREVIOUSSTATE = Request.Form["PREVIOUSSTATE"];
|
|---|
| 155 | if (!String.IsNullOrEmpty(Request.Form["TYPE"])) potwierdzenie.TYPE = Request.Form["TYPE"];
|
|---|
| 156 | if (!String.IsNullOrEmpty(Request.Form["VALIDATIONCODE"])) potwierdzenie.VALIDATIONCODE = Request.Form["VALIDATIONCODE"];
|
|---|
| 157 | if (!String.IsNullOrEmpty(Request.Form["WITHCVC"])) potwierdzenie.WITHCVC = Request.Form["WITHCVC"];
|
|---|
| [866] | 158 |
|
|---|
| [911] | 159 | _repConfirm.Insert(potwierdzenie);
|
|---|
| [933] | 160 |
|
|---|
| 161 | if (potwierdzenie.ORDERNUMBER.HasValue)
|
|---|
| 162 | UpdateStatus(potwierdzenie.ORDERNUMBER.Value, potwierdzenie.CURRENTSTATE);
|
|---|
| 163 |
|
|---|
| [926] | 164 | content.Content = "OK";
|
|---|
| [911] | 165 | }
|
|---|
| 166 | catch(Exception ex)
|
|---|
| 167 | {
|
|---|
| [926] | 168 | content.Content = "FALSE " + ex.Message + " " + ex.GetType();
|
|---|
| [911] | 169 | }
|
|---|
| 170 |
|
|---|
| [908] | 171 | return content;
|
|---|
| [866] | 172 | }
|
|---|
| [933] | 173 |
|
|---|
| 174 | private static Payer InitPayer(int idFaktury)
|
|---|
| [868] | 175 | {
|
|---|
| [933] | 176 | var payer = new Payer {Id_faktury = idFaktury};
|
|---|
| [868] | 177 | return payer;
|
|---|
| 178 | }
|
|---|
| [933] | 179 |
|
|---|
| [951] | 180 | private InvoiceDetailsViewData InitInvoiceDetailsViewData(vPlatnosciEcard platnosc)
|
|---|
| [868] | 181 | {
|
|---|
| 182 | var invoiceDeatailsViewData = new InvoiceDetailsViewData();
|
|---|
| 183 | invoiceDeatailsViewData.vPlatnosciEcard = platnosc;
|
|---|
| [951] | 184 | invoiceDeatailsViewData.Payer = InitPayer(platnosc.ID_faktury);
|
|---|
| 185 | invoiceDeatailsViewData.brutto = _funkcjePlatnosci.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| [868] | 186 | return invoiceDeatailsViewData;
|
|---|
| 187 | }
|
|---|
| [933] | 188 |
|
|---|
| [873] | 189 | public int ConvertId(string id)
|
|---|
| 190 | {
|
|---|
| [933] | 191 | int id1;
|
|---|
| 192 | return Int32.TryParse(id, out id1) ? id1 : 0;
|
|---|
| [873] | 193 | }
|
|---|
| [933] | 194 |
|
|---|
| [883] | 195 | public void UpdateStatus(int ordernumber, string currentstate)
|
|---|
| [873] | 196 | {
|
|---|
| [933] | 197 | var platnosc = _repPayment.Find(p => p.ORDERNUMBER == ordernumber).SingleOrDefault();
|
|---|
| 198 |
|
|---|
| 199 | if (platnosc == null || currentstate != ISPAID) return;
|
|---|
| 200 |
|
|---|
| 201 | platnosc.Status = true;
|
|---|
| 202 | platnosc.Status_data = DateTime.Now;
|
|---|
| 203 | _repPayment.SubmitChanges();
|
|---|
| [911] | 204 | }
|
|---|
| [933] | 205 |
|
|---|
| [926] | 206 | public int CheckConfirm(int idfaktury, int order)
|
|---|
| 207 | {
|
|---|
| [933] | 208 | var pl = _repPayment.Find(p => p.ORDERNUMBER == order && p.IDFaktury == idfaktury).SingleOrDefault();
|
|---|
| 209 |
|
|---|
| [926] | 210 | if (pl != null)
|
|---|
| 211 | {
|
|---|
| [933] | 212 | var confirm = _repConfirm.Find(p => p.ORDERNUMBER == order).FirstOrDefault();
|
|---|
| [926] | 213 | if (confirm == null) return 0; //potwierdzenie nie przyszlo z eCardu
|
|---|
| 214 | }
|
|---|
| 215 | else
|
|---|
| 216 | {
|
|---|
| 217 | return 2; //nie ma platnosci o takim idfaktury i ordernumber
|
|---|
| 218 | }
|
|---|
| [933] | 219 |
|
|---|
| [926] | 220 | return 1; //potwierdzenie przyszlo z eCardu
|
|---|
| [933] | 221 | }
|
|---|
| [866] | 222 | }
|
|---|
| 223 | }
|
|---|