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