| [866] | 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using System.Text;
|
|---|
| 4 | using System.Web;
|
|---|
| 5 | using System.Web.Mvc;
|
|---|
| 6 | using System.Web.Mvc.Ajax;
|
|---|
| 7 | using Platnosci.Models;
|
|---|
| 8 | using Platnosci.Core.Linq;
|
|---|
| 9 | using Platnosci.Core.Interface;
|
|---|
| 10 | using System.Collections.Generic;
|
|---|
| 11 | using System.Globalization;
|
|---|
| 12 | using System.Web.UI;
|
|---|
| 13 | using System.Threading;
|
|---|
| [870] | 14 | using System.Data.Linq;
|
|---|
| 15 | using System.Web.Configuration;
|
|---|
| [873] | 16 | using System.Web.Routing;
|
|---|
| [866] | 17 |
|
|---|
| 18 | namespace Platnosci.Controllers
|
|---|
| 19 | {
|
|---|
| [880] | 20 |
|
|---|
| [866] | 21 | [Authorize]
|
|---|
| 22 | public class PlatnoscController : Controller
|
|---|
| 23 | {
|
|---|
| [883] | 24 | public const string ISPAID = "payment_deposited"; //transakcja potwierdzona do rozliczenia
|
|---|
| [896] | 25 | private readonly IRepository<vPlatnosciEcard> _repVPayment;
|
|---|
| 26 | private readonly IRepository<PlatnosciEcard> _repPayment;
|
|---|
| [903] | 27 | private readonly IRepository<PotwierdzeniaEcard> _repConfirm;
|
|---|
| 28 | private ITranslate _t;
|
|---|
| [866] | 29 | private FunkcjePlatnosci _func;
|
|---|
| [903] | 30 |
|
|---|
| [866] | 31 | public PlatnoscController()
|
|---|
| 32 | {
|
|---|
| [896] | 33 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext1());
|
|---|
| 34 | _repPayment = new Repository<PlatnosciEcard>(new DataContext1());
|
|---|
| 35 | _repConfirm = new Repository<PotwierdzeniaEcard>(new DataContext1());
|
|---|
| [903] | 36 | _func = new FunkcjePlatnosci();
|
|---|
| 37 | _t = new Translate();
|
|---|
| [866] | 38 | }
|
|---|
| [903] | 39 | public PlatnoscController(IRepository<vPlatnosciEcard> repVPayment, IRepository<PlatnosciEcard> repPayment, IRepository<PotwierdzeniaEcard> repConfirm, ITranslate translate)
|
|---|
| [872] | 40 | {
|
|---|
| [896] | 41 | _repVPayment = repVPayment;
|
|---|
| 42 | _repPayment = repPayment;
|
|---|
| 43 | _repConfirm = repConfirm;
|
|---|
| [872] | 44 | _func = new FunkcjePlatnosci();
|
|---|
| [903] | 45 | _t = translate;
|
|---|
| [870] | 46 | }
|
|---|
| [866] | 47 | public ActionResult Show(string id, string language)
|
|---|
| 48 | {
|
|---|
| 49 | language = _func.setLanguage(language);
|
|---|
| [881] | 50 | int id1 = ConvertId(id);
|
|---|
| [873] | 51 |
|
|---|
| [896] | 52 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [880] | 53 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| [883] | 54 |
|
|---|
| 55 | string kwota = "";
|
|---|
| 56 | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| 57 | var payer = InitPayer("", "", platnosc.ID_faktury);
|
|---|
| 58 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota);
|
|---|
| 59 |
|
|---|
| [896] | 60 | var tablica_potwierdzenia = _repConfirm.FindItemsByIdFaktury(id1);
|
|---|
| [868] | 61 | if (tablica_potwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana
|
|---|
| [866] | 62 | {
|
|---|
| [883] | 63 | string data_zaplaty = String.Format("{0:dd-MM-yyyy}", tablica_potwierdzenia[0].AUTHTIME);
|
|---|
| [903] | 64 | invoiceDeatailsViewData.info = String.Format(_t.TranslateStr("tlumaczenia","zaplacono"), platnosc.Faktura_Numer, data_zaplaty);
|
|---|
| [883] | 65 | invoiceDeatailsViewData.termin = data_zaplaty;
|
|---|
| 66 | return View("Paid", invoiceDeatailsViewData);
|
|---|
| [885] | 67 | }
|
|---|
| [888] | 68 | return View(invoiceDeatailsViewData);
|
|---|
| [868] | 69 | }
|
|---|
| [866] | 70 | [Authorize]
|
|---|
| 71 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 72 | public ActionResult Show(Payer payer, string language)
|
|---|
| 73 | {
|
|---|
| 74 | language = _func.setLanguage(language);
|
|---|
| [896] | 75 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == payer.Id_faktury).SingleOrDefault();
|
|---|
| [880] | 76 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| [873] | 77 |
|
|---|
| [866] | 78 | if (String.IsNullOrEmpty(payer.FirstName))
|
|---|
| 79 | {
|
|---|
| [903] | 80 | ModelState.AddModelError("Payer.FirstName", _t.TranslateStr("tlumaczenia", "err_imieWK"));
|
|---|
| [866] | 81 | }
|
|---|
| 82 | if (String.IsNullOrEmpty(payer.LastName))
|
|---|
| 83 | {
|
|---|
| [903] | 84 | ModelState.AddModelError("Payer.LastName", _t.TranslateStr("tlumaczenia", "err_nazwiskoWK"));
|
|---|
| [866] | 85 | }
|
|---|
| 86 | if (ModelState.IsValid == false)
|
|---|
| 87 | {
|
|---|
| 88 | string kwota = "";
|
|---|
| 89 | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| [868] | 90 | var viewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota );
|
|---|
| [866] | 91 | return View("Show",viewData);
|
|---|
| 92 | }
|
|---|
| 93 | if (payer != null)
|
|---|
| [873] | 94 | {
|
|---|
| [877] | 95 | System.Diagnostics.Debug.WriteLine("PlatnosciController:Show");
|
|---|
| [866] | 96 | return RedirectToAction("Merchant", "Merchant", payer);
|
|---|
| [877] | 97 | }
|
|---|
| [866] | 98 | else return View("Error");
|
|---|
| 99 | }
|
|---|
| [873] | 100 | public ActionResult Ok(string id, string language)
|
|---|
| [866] | 101 | {
|
|---|
| 102 | language = _func.setLanguage(language);
|
|---|
| [873] | 103 | int id1 = ConvertId(id);
|
|---|
| [896] | 104 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [880] | 105 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| 106 |
|
|---|
| [873] | 107 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "" , "");
|
|---|
| [866] | 108 | return View(invoiceDeatailsViewData);
|
|---|
| 109 | }
|
|---|
| [873] | 110 | public ActionResult Fail(string id, string language)
|
|---|
| [871] | 111 | {
|
|---|
| [873] | 112 | language = _func.setLanguage(language);
|
|---|
| 113 | int id1 = ConvertId(id);
|
|---|
| [896] | 114 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [885] | 115 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| [873] | 116 |
|
|---|
| 117 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "", "");
|
|---|
| 118 | return View(invoiceDeatailsViewData);
|
|---|
| [871] | 119 | }
|
|---|
| [903] | 120 | public ActionResult Form()
|
|---|
| 121 | {
|
|---|
| 122 | return View();
|
|---|
| 123 | }
|
|---|
| [866] | 124 | public ActionResult Status()
|
|---|
| 125 | {
|
|---|
| 126 | string MERCHANTNUMBER = Request.Form["MERCHANTNUMBER"];
|
|---|
| 127 | int ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]);
|
|---|
| 128 | string COMMTYPE = Request.Form["COMMTYPE"];
|
|---|
| 129 | string CURRENTSTATE = Request.Form["CURRENTSTATE"];
|
|---|
| 130 | string PREVIOUSSTATE = Request.Form["PREVIOUSSTATE"];
|
|---|
| 131 | bool PAYMENTTYPE = Convert.ToBoolean(Request.Form["PAYMENTTYPE"]);
|
|---|
| 132 | bool EVENTTYPE = Convert.ToBoolean(Request.Form["EVENTTYPE"]);
|
|---|
| 133 | bool PAYMENTNUMBER = Convert.ToBoolean(Request.Form["PAYMENTNUMBER"]);
|
|---|
| 134 | string APPROVALCODE = Request.Form["APPROVALCODE"];
|
|---|
| 135 | string VALIDATIONCODE = Request.Form["VALIDATIONCODE"];
|
|---|
| 136 | string BIN = Request.Form["BIN"];
|
|---|
| 137 | DateTime AUTHTIME = Convert.ToDateTime(Request.Form["AUTHTIME"]);
|
|---|
| 138 | string TYPE = Request.Form["TYPE"];
|
|---|
| 139 | string WITHCVC = Request.Form["WITHCVC"];
|
|---|
| 140 | DateTime DATATRANSMISJI = Convert.ToDateTime(Request.Form["DATATRANSMISJI"]);
|
|---|
| 141 |
|
|---|
| 142 | PotwierdzeniaEcard potwierdzenie = new PotwierdzeniaEcard();
|
|---|
| 143 | potwierdzenie.APPROVALCODE = APPROVALCODE;
|
|---|
| 144 | potwierdzenie.AUTHTIME = AUTHTIME;
|
|---|
| 145 | potwierdzenie.BIN = BIN;
|
|---|
| 146 | potwierdzenie.COMMTYPE = COMMTYPE;
|
|---|
| 147 | potwierdzenie.CURRENTSTATE = CURRENTSTATE;
|
|---|
| 148 | potwierdzenie.DATATRANSMISJI = DATATRANSMISJI;
|
|---|
| 149 | potwierdzenie.EVENTTYPE = EVENTTYPE;
|
|---|
| 150 | potwierdzenie.MERCHANTNUMBER = MERCHANTNUMBER;
|
|---|
| 151 | potwierdzenie.ORDERNUMBER = ORDERNUMBER;
|
|---|
| 152 | potwierdzenie.PAYMENTNUMBER = PAYMENTNUMBER;
|
|---|
| 153 | potwierdzenie.PAYMENTTYPE = PAYMENTTYPE;
|
|---|
| 154 | potwierdzenie.PREVIOUSSTATE = PREVIOUSSTATE;
|
|---|
| 155 | potwierdzenie.TYPE = TYPE;
|
|---|
| 156 | potwierdzenie.VALIDATIONCODE = VALIDATIONCODE;
|
|---|
| 157 | potwierdzenie.WITHCVC = WITHCVC;
|
|---|
| 158 |
|
|---|
| [896] | 159 | _repConfirm.Insert(potwierdzenie);
|
|---|
| [883] | 160 | UpdateStatus(ORDERNUMBER, CURRENTSTATE);
|
|---|
| [903] | 161 | return new EmptyResult();
|
|---|
| [866] | 162 | }
|
|---|
| [868] | 163 | private Payer InitPayer(string FirstName, string LastName, int Id_faktury)
|
|---|
| 164 | {
|
|---|
| 165 | Payer payer = new Payer();
|
|---|
| 166 | payer.FirstName = "";
|
|---|
| 167 | payer.LastName = "";
|
|---|
| 168 | payer.Id_faktury = Id_faktury;
|
|---|
| 169 | return payer;
|
|---|
| 170 | }
|
|---|
| 171 | private InvoiceDetailsViewData InitInvoiceDetailsViewData(vPlatnosciEcard platnosc, Payer payer, string status, string brutto )
|
|---|
| 172 | {
|
|---|
| 173 | var invoiceDeatailsViewData = new InvoiceDetailsViewData();
|
|---|
| 174 | invoiceDeatailsViewData.vPlatnosciEcard = platnosc;
|
|---|
| 175 | invoiceDeatailsViewData.Payer = payer;
|
|---|
| 176 | invoiceDeatailsViewData.Status = status;
|
|---|
| 177 | invoiceDeatailsViewData.brutto = brutto;
|
|---|
| 178 | return invoiceDeatailsViewData;
|
|---|
| 179 | }
|
|---|
| [873] | 180 | public int ConvertId(string id)
|
|---|
| 181 | {
|
|---|
| 182 | int id1 = 0;
|
|---|
| 183 | try
|
|---|
| 184 | {
|
|---|
| 185 | id1 = (id != null) ? Convert.ToInt32(id) : 0;
|
|---|
| 186 | }
|
|---|
| 187 | catch
|
|---|
| 188 | {
|
|---|
| 189 | }
|
|---|
| 190 | return id1;
|
|---|
| 191 | }
|
|---|
| 192 | public ErrorViewData Iserror(vPlatnosciEcard platnosc)
|
|---|
| 193 | {
|
|---|
| [880] | 194 | string errortxt = "";
|
|---|
| [903] | 195 | if (platnosc == null) errortxt = _t.TranslateStr("tlumaczenia", "brakdanych");
|
|---|
| 196 | else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) errortxt = _t.TranslateStr("tlumaczenia","weryfikacja");
|
|---|
| [880] | 197 | ErrorViewData errorViewData = _func.InitErrorViewData(errortxt);
|
|---|
| [873] | 198 | return errorViewData;
|
|---|
| 199 | }
|
|---|
| [883] | 200 | public void UpdateStatus(int ordernumber, string currentstate)
|
|---|
| [873] | 201 | {
|
|---|
| [896] | 202 | PlatnosciEcard platnosc = _repPayment.Find(p => p.ORDERNUMBER == ordernumber).SingleOrDefault();
|
|---|
| [888] | 203 | if (platnosc != null && currentstate == ISPAID)
|
|---|
| [873] | 204 | {
|
|---|
| 205 | platnosc.Status = true;
|
|---|
| 206 | platnosc.Status_data = DateTime.Now;
|
|---|
| [896] | 207 | _repPayment.SubmitChanges();
|
|---|
| [888] | 208 |
|
|---|
| 209 | System.Diagnostics.Debug.WriteLine("IsUpdate");
|
|---|
| [873] | 210 | }
|
|---|
| 211 | }
|
|---|
| [866] | 212 | }
|
|---|
| 213 | }
|
|---|