| [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 | {
|
|---|
| [896] | 23 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext1());
|
|---|
| 24 | _repPayment = new Repository<PlatnosciEcard>(new DataContext1());
|
|---|
| 25 | _repConfirm = new Repository<PotwierdzeniaEcard>(new DataContext1());
|
|---|
| [933] | 26 | _funkcjePlatnosci = new FunkcjePlatnosci();
|
|---|
| 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 | _funkcjePlatnosci = new FunkcjePlatnosci();
|
|---|
| 35 | _translateManager = translate;
|
|---|
| [870] | 36 | }
|
|---|
| [866] | 37 | public ActionResult Show(string id, string language)
|
|---|
| 38 | {
|
|---|
| [933] | 39 | _funkcjePlatnosci.setLanguage(language);
|
|---|
| 40 | var id1 = ConvertId(id);
|
|---|
| [873] | 41 |
|
|---|
| [933] | 42 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 43 | if (!String.IsNullOrEmpty(IsError(platnosc).Error)) return View("Error1", IsError(platnosc));
|
|---|
| [883] | 44 |
|
|---|
| [933] | 45 | var kwota = _funkcjePlatnosci.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| 46 |
|
|---|
| 47 | var payer = InitPayer(platnosc.ID_faktury);
|
|---|
| 48 |
|
|---|
| [883] | 49 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota);
|
|---|
| 50 |
|
|---|
| [933] | 51 | var tablicaPotwierdzenia = _repConfirm.FindItemsByIdFaktury(id1);
|
|---|
| 52 | if (tablicaPotwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana
|
|---|
| [866] | 53 | {
|
|---|
| [933] | 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;
|
|---|
| [883] | 57 | return View("Paid", invoiceDeatailsViewData);
|
|---|
| [885] | 58 | }
|
|---|
| [888] | 59 | return View(invoiceDeatailsViewData);
|
|---|
| [868] | 60 | }
|
|---|
| [866] | 61 | [Authorize]
|
|---|
| 62 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 63 | public ActionResult Show(Payer payer, string language)
|
|---|
| 64 | {
|
|---|
| [933] | 65 | _funkcjePlatnosci.setLanguage(language);
|
|---|
| [873] | 66 |
|
|---|
| [933] | 67 | var platnosc = _repVPayment.Find(p => p.ID_faktury == payer.Id_faktury).SingleOrDefault();
|
|---|
| 68 |
|
|---|
| 69 | if (!String.IsNullOrEmpty(IsError(platnosc).Error)) return View("Error1", IsError(platnosc));
|
|---|
| 70 |
|
|---|
| [866] | 71 | if (String.IsNullOrEmpty(payer.FirstName))
|
|---|
| 72 | {
|
|---|
| [933] | 73 | ModelState.AddModelError("Payer.FirstName", _translateManager.Translate("tlumaczenia", "err_imieWK"));
|
|---|
| [866] | 74 | }
|
|---|
| 75 | if (String.IsNullOrEmpty(payer.LastName))
|
|---|
| 76 | {
|
|---|
| [933] | 77 | ModelState.AddModelError("Payer.LastName", _translateManager.Translate("tlumaczenia", "err_nazwiskoWK"));
|
|---|
| [866] | 78 | }
|
|---|
| 79 | if (ModelState.IsValid == false)
|
|---|
| 80 | {
|
|---|
| [933] | 81 | var kwota = _funkcjePlatnosci.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| [868] | 82 | var viewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota );
|
|---|
| [919] | 83 | return View("Show",viewData);
|
|---|
| [933] | 84 | }
|
|---|
| 85 |
|
|---|
| 86 | return RedirectToAction("Merchant", "Merchant", payer);
|
|---|
| [866] | 87 | }
|
|---|
| [933] | 88 |
|
|---|
| [926] | 89 | public ActionResult Ok(string id, string language, string o)
|
|---|
| [866] | 90 | {
|
|---|
| [933] | 91 | var order = ConvertId(o);
|
|---|
| [880] | 92 |
|
|---|
| [933] | 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));
|
|---|
| 100 |
|
|---|
| [873] | 101 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "" , "");
|
|---|
| [926] | 102 |
|
|---|
| 103 | //sprawdzamy czy dla kombinacji ordernumber i idfaktury istnieje platnosc,
|
|---|
| 104 | //jesli tak, to sprawdzamy czy przyszlo potwierdzenie z eCardu.
|
|---|
| 105 | if (order > 0)
|
|---|
| 106 | {
|
|---|
| 107 | if (CheckConfirm(id1, order) == 0) //nie ma potwierdzenia z eCardu
|
|---|
| 108 | {
|
|---|
| [933] | 109 | invoiceDeatailsViewData.info = String.Format(_translateManager.Translate("tlumaczenia", "blad1"), invoiceDeatailsViewData.vPlatnosciEcard.Faktura_Numer);
|
|---|
| [926] | 110 | }
|
|---|
| 111 | else
|
|---|
| 112 | {
|
|---|
| [933] | 113 | if (CheckConfirm(id1, order) == 2) invoiceDeatailsViewData.info = _translateManager.Translate("tlumaczenia", "weryfikacja");
|
|---|
| [926] | 114 | }
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| [866] | 117 | return View(invoiceDeatailsViewData);
|
|---|
| 118 | }
|
|---|
| [926] | 119 | public ActionResult Fail(string id, string language)
|
|---|
| [871] | 120 | {
|
|---|
| [933] | 121 | _funkcjePlatnosci.setLanguage(language);
|
|---|
| 122 | var id1 = ConvertId(id);
|
|---|
| 123 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 124 | if (!String.IsNullOrEmpty(IsError(platnosc).Error)) return View("Error1", IsError(platnosc));
|
|---|
| [919] | 125 |
|
|---|
| [873] | 126 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "", "");
|
|---|
| 127 | return View(invoiceDeatailsViewData);
|
|---|
| [871] | 128 | }
|
|---|
| [903] | 129 | public ActionResult Form()
|
|---|
| 130 | {
|
|---|
| 131 | return View();
|
|---|
| 132 | }
|
|---|
| [866] | 133 | public ActionResult Status()
|
|---|
| 134 | {
|
|---|
| [933] | 135 | var potwierdzenie = new PotwierdzeniaEcard();
|
|---|
| [911] | 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"];
|
|---|
| [933] | 143 | if (!String.IsNullOrEmpty(Request.Form["CURRENTSTATE"])) potwierdzenie.CURRENTSTATE = Request.Form["CURRENTSTATE"];
|
|---|
| [911] | 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"];
|
|---|
| [933] | 147 | if (!String.IsNullOrEmpty(Request.Form["ORDERNUMBER"])) potwierdzenie.ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]);
|
|---|
| [911] | 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"];
|
|---|
| [866] | 154 |
|
|---|
| [911] | 155 | _repConfirm.Insert(potwierdzenie);
|
|---|
| [933] | 156 |
|
|---|
| 157 | if (potwierdzenie.ORDERNUMBER.HasValue)
|
|---|
| 158 | UpdateStatus(potwierdzenie.ORDERNUMBER.Value, potwierdzenie.CURRENTSTATE);
|
|---|
| 159 |
|
|---|
| [926] | 160 | content.Content = "OK";
|
|---|
| [911] | 161 | }
|
|---|
| 162 | catch(Exception ex)
|
|---|
| 163 | {
|
|---|
| [926] | 164 | content.Content = "FALSE " + ex.Message + " " + ex.GetType();
|
|---|
| [911] | 165 | }
|
|---|
| 166 |
|
|---|
| [908] | 167 | return content;
|
|---|
| [866] | 168 | }
|
|---|
| [933] | 169 |
|
|---|
| 170 | private static Payer InitPayer(int idFaktury)
|
|---|
| [868] | 171 | {
|
|---|
| [933] | 172 | var payer = new Payer {Id_faktury = idFaktury};
|
|---|
| [868] | 173 | return payer;
|
|---|
| 174 | }
|
|---|
| [933] | 175 |
|
|---|
| 176 | private static InvoiceDetailsViewData InitInvoiceDetailsViewData(vPlatnosciEcard platnosc, Payer payer, string status, string brutto )
|
|---|
| [868] | 177 | {
|
|---|
| 178 | var invoiceDeatailsViewData = new InvoiceDetailsViewData();
|
|---|
| 179 | invoiceDeatailsViewData.vPlatnosciEcard = platnosc;
|
|---|
| 180 | invoiceDeatailsViewData.Payer = payer;
|
|---|
| 181 | invoiceDeatailsViewData.Status = status;
|
|---|
| 182 | invoiceDeatailsViewData.brutto = brutto;
|
|---|
| 183 | return invoiceDeatailsViewData;
|
|---|
| 184 | }
|
|---|
| [933] | 185 |
|
|---|
| [873] | 186 | public int ConvertId(string id)
|
|---|
| 187 | {
|
|---|
| [933] | 188 | int id1;
|
|---|
| 189 | return Int32.TryParse(id, out id1) ? id1 : 0;
|
|---|
| [873] | 190 | }
|
|---|
| [933] | 191 |
|
|---|
| 192 | public ErrorViewData IsError(vPlatnosciEcard platnosc)
|
|---|
| [873] | 193 | {
|
|---|
| [933] | 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);
|
|---|
| [873] | 202 | }
|
|---|
| [933] | 203 |
|
|---|
| [883] | 204 | public void UpdateStatus(int ordernumber, string currentstate)
|
|---|
| [873] | 205 | {
|
|---|
| [933] | 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();
|
|---|
| [911] | 213 | }
|
|---|
| [933] | 214 |
|
|---|
| [926] | 215 | public int CheckConfirm(int idfaktury, int order)
|
|---|
| 216 | {
|
|---|
| [933] | 217 | var pl = _repPayment.Find(p => p.ORDERNUMBER == order && p.IDFaktury == idfaktury).SingleOrDefault();
|
|---|
| 218 |
|
|---|
| [926] | 219 | if (pl != null)
|
|---|
| 220 | {
|
|---|
| [933] | 221 | var confirm = _repConfirm.Find(p => p.ORDERNUMBER == order).FirstOrDefault();
|
|---|
| [926] | 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 | }
|
|---|
| [933] | 228 |
|
|---|
| [926] | 229 | return 1; //potwierdzenie przyszlo z eCardu
|
|---|
| [933] | 230 | }
|
|---|
| [866] | 231 | }
|
|---|
| 232 | }
|
|---|