| 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;
|
|---|
| 14 | using System.Data.Linq;
|
|---|
| 15 | using System.Web.Configuration;
|
|---|
| 16 | using System.Web.Routing;
|
|---|
| 17 |
|
|---|
| 18 | namespace Platnosci.Controllers
|
|---|
| 19 | {
|
|---|
| 20 |
|
|---|
| 21 | [Authorize]
|
|---|
| 22 | public class PlatnoscController : Controller
|
|---|
| 23 | {
|
|---|
| 24 | public const string ISPAID = "payment_deposited"; //transakcja potwierdzona do rozliczenia
|
|---|
| 25 | private readonly IRepository<vPlatnosciEcard> _repVPayment;
|
|---|
| 26 | private readonly IRepository<PlatnosciEcard> _repPayment;
|
|---|
| 27 | private readonly IRepository<PotwierdzeniaEcard> _repConfirm;
|
|---|
| 28 | private ITranslate _t;
|
|---|
| 29 | private FunkcjePlatnosci _func;
|
|---|
| 30 |
|
|---|
| 31 | public PlatnoscController()
|
|---|
| 32 | {
|
|---|
| 33 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext1());
|
|---|
| 34 | _repPayment = new Repository<PlatnosciEcard>(new DataContext1());
|
|---|
| 35 | _repConfirm = new Repository<PotwierdzeniaEcard>(new DataContext1());
|
|---|
| 36 | _func = new FunkcjePlatnosci();
|
|---|
| 37 | _t = new Translate();
|
|---|
| 38 | }
|
|---|
| 39 | public PlatnoscController(IRepository<vPlatnosciEcard> repVPayment, IRepository<PlatnosciEcard> repPayment, IRepository<PotwierdzeniaEcard> repConfirm, ITranslate translate)
|
|---|
| 40 | {
|
|---|
| 41 | _repVPayment = repVPayment;
|
|---|
| 42 | _repPayment = repPayment;
|
|---|
| 43 | _repConfirm = repConfirm;
|
|---|
| 44 | _func = new FunkcjePlatnosci();
|
|---|
| 45 | _t = translate;
|
|---|
| 46 | }
|
|---|
| 47 | public ActionResult Show(string id, string language)
|
|---|
| 48 | {
|
|---|
| 49 | language = _func.setLanguage(language);
|
|---|
| 50 | int id1 = ConvertId(id);
|
|---|
| 51 |
|
|---|
| 52 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 53 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| 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 |
|
|---|
| 60 | var tablica_potwierdzenia = _repConfirm.FindItemsByIdFaktury(id1);
|
|---|
| 61 | if (tablica_potwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana
|
|---|
| 62 | {
|
|---|
| 63 | string data_zaplaty = String.Format("{0:dd-MM-yyyy}", tablica_potwierdzenia[0].AUTHTIME);
|
|---|
| 64 | invoiceDeatailsViewData.info = String.Format(_t.TranslateStr("tlumaczenia","zaplacono"), platnosc.Faktura_Numer, data_zaplaty);
|
|---|
| 65 | invoiceDeatailsViewData.termin = data_zaplaty;
|
|---|
| 66 | return View("Paid", invoiceDeatailsViewData);
|
|---|
| 67 | }
|
|---|
| 68 | return View(invoiceDeatailsViewData);
|
|---|
| 69 | }
|
|---|
| 70 | [Authorize]
|
|---|
| 71 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 72 | public ActionResult Show(Payer payer, string language)
|
|---|
| 73 | {
|
|---|
| 74 | language = _func.setLanguage(language);
|
|---|
| 75 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == payer.Id_faktury).SingleOrDefault();
|
|---|
| 76 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| 77 |
|
|---|
| 78 | if (String.IsNullOrEmpty(payer.FirstName))
|
|---|
| 79 | {
|
|---|
| 80 | ModelState.AddModelError("Payer.FirstName", _t.TranslateStr("tlumaczenia", "err_imieWK"));
|
|---|
| 81 | }
|
|---|
| 82 | if (String.IsNullOrEmpty(payer.LastName))
|
|---|
| 83 | {
|
|---|
| 84 | ModelState.AddModelError("Payer.LastName", _t.TranslateStr("tlumaczenia", "err_nazwiskoWK"));
|
|---|
| 85 | }
|
|---|
| 86 | if (ModelState.IsValid == false)
|
|---|
| 87 | {
|
|---|
| 88 | string kwota = "";
|
|---|
| 89 | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| 90 | var viewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota );
|
|---|
| 91 | return View("Show",viewData);
|
|---|
| 92 | }
|
|---|
| 93 | if (payer != null)
|
|---|
| 94 | {
|
|---|
| 95 | System.Diagnostics.Debug.WriteLine("PlatnosciController:Show");
|
|---|
| 96 | return RedirectToAction("Merchant", "Merchant", payer);
|
|---|
| 97 | }
|
|---|
| 98 | else return View("Error");
|
|---|
| 99 | }
|
|---|
| 100 | public ActionResult Ok(string id, string language)
|
|---|
| 101 | {
|
|---|
| 102 | language = _func.setLanguage(language);
|
|---|
| 103 | int id1 = ConvertId(id);
|
|---|
| 104 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 105 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| 106 |
|
|---|
| 107 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "" , "");
|
|---|
| 108 | return View(invoiceDeatailsViewData);
|
|---|
| 109 | }
|
|---|
| 110 | public ActionResult Fail(string id, string language)
|
|---|
| 111 | {
|
|---|
| 112 | language = _func.setLanguage(language);
|
|---|
| 113 | int id1 = ConvertId(id);
|
|---|
| 114 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 115 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| 116 |
|
|---|
| 117 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "", "");
|
|---|
| 118 | return View(invoiceDeatailsViewData);
|
|---|
| 119 | }
|
|---|
| 120 | public ActionResult Form()
|
|---|
| 121 | {
|
|---|
| 122 | return View();
|
|---|
| 123 | }
|
|---|
| 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 |
|
|---|
| 159 | _repConfirm.Insert(potwierdzenie);
|
|---|
| 160 | UpdateStatus(ORDERNUMBER, CURRENTSTATE);
|
|---|
| 161 | return new EmptyResult();
|
|---|
| 162 | }
|
|---|
| 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 | }
|
|---|
| 180 | /*private void ustawTlumaczenia(int test)
|
|---|
| 181 | {
|
|---|
| 182 | if (test == 0)
|
|---|
| 183 | {
|
|---|
| 184 |
|
|---|
| 185 | err_imie = Resources.tlumaczenia.err_imieWK.ToString();
|
|---|
| 186 | err_nazwisko = Resources.tlumaczenia.err_nazwiskoWK.ToString();
|
|---|
| 187 | }
|
|---|
| 188 | }
|
|---|
| 189 | public void setWeryfikacja(string value)
|
|---|
| 190 | {
|
|---|
| 191 | this.weryfikacja = value;
|
|---|
| 192 | }
|
|---|
| 193 | public void setBrakDanych(string value)
|
|---|
| 194 | {
|
|---|
| 195 | this.brakdanych = value;
|
|---|
| 196 | }
|
|---|
| 197 | public void setZaplacono(string value)
|
|---|
| 198 | {
|
|---|
| 199 | this.zaplacono = value;
|
|---|
| 200 | }*/
|
|---|
| 201 | public int ConvertId(string id)
|
|---|
| 202 | {
|
|---|
| 203 | int id1 = 0;
|
|---|
| 204 | try
|
|---|
| 205 | {
|
|---|
| 206 | id1 = (id != null) ? Convert.ToInt32(id) : 0;
|
|---|
| 207 | }
|
|---|
| 208 | catch
|
|---|
| 209 | {
|
|---|
| 210 | }
|
|---|
| 211 | return id1;
|
|---|
| 212 | }
|
|---|
| 213 | public ErrorViewData Iserror(vPlatnosciEcard platnosc)
|
|---|
| 214 | {
|
|---|
| 215 | string errortxt = "";
|
|---|
| 216 | if (platnosc == null) errortxt = _t.TranslateStr("tlumaczenia", "brakdanych");
|
|---|
| 217 | else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) errortxt = _t.TranslateStr("tlumaczenia","weryfikacja");
|
|---|
| 218 | ErrorViewData errorViewData = _func.InitErrorViewData(errortxt);
|
|---|
| 219 | return errorViewData;
|
|---|
| 220 | }
|
|---|
| 221 | public void UpdateStatus(int ordernumber, string currentstate)
|
|---|
| 222 | {
|
|---|
| 223 | PlatnosciEcard platnosc = _repPayment.Find(p => p.ORDERNUMBER == ordernumber).SingleOrDefault();
|
|---|
| 224 | if (platnosc != null && currentstate == ISPAID)
|
|---|
| 225 | {
|
|---|
| 226 | platnosc.Status = true;
|
|---|
| 227 | platnosc.Status_data = DateTime.Now;
|
|---|
| 228 | _repPayment.SubmitChanges();
|
|---|
| 229 |
|
|---|
| 230 | System.Diagnostics.Debug.WriteLine("IsUpdate");
|
|---|
| 231 | }
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|