| 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 |
|
|---|
| 17 | namespace Platnosci.Controllers
|
|---|
| 18 | {
|
|---|
| 19 | [Authorize]
|
|---|
| 20 | public class PlatnoscController : Controller
|
|---|
| 21 | {
|
|---|
| 22 | private readonly PlatnosciDataContext _context;
|
|---|
| 23 | private readonly IDataContext _context1;
|
|---|
| 24 | private readonly IRepository<PotwierdzeniaEcard> _rep;
|
|---|
| 25 | private readonly IRepository<PlatnosciEcard> _repPl;
|
|---|
| 26 | private FunkcjePlatnosci _func;
|
|---|
| 27 | private string weryfikacja = "";
|
|---|
| 28 | private string brakdanych = "";
|
|---|
| 29 | private string zaplacono = "";
|
|---|
| 30 | private string err_imie = "";
|
|---|
| 31 | private string err_nazwisko = "";
|
|---|
| 32 |
|
|---|
| 33 | protected override void Initialize(System.Web.Routing.RequestContext requestContext)
|
|---|
| 34 | {
|
|---|
| 35 | base.Initialize(requestContext);
|
|---|
| 36 | weryfikacja = HttpContext.GetGlobalResourceObject("tlumaczenia", "weryfikacja").ToString();
|
|---|
| 37 | brakdanych = HttpContext.GetGlobalResourceObject("tlumaczenia", "brakdanych").ToString();
|
|---|
| 38 | zaplacono = HttpContext.GetGlobalResourceObject("tlumaczenia", "zaplacono").ToString();
|
|---|
| 39 | err_imie = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_imieWK").ToString();
|
|---|
| 40 | err_nazwisko = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_nazwiskoWK").ToString();
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public PlatnoscController()
|
|---|
| 44 | {
|
|---|
| 45 | _context = new PlatnosciDataContext();
|
|---|
| 46 | _rep = new Repository<PotwierdzeniaEcard>(new DataContext1());
|
|---|
| 47 | _repPl = new Repository<PlatnosciEcard>(new DataContext1());
|
|---|
| 48 | _func = new FunkcjePlatnosci();
|
|---|
| 49 |
|
|---|
| 50 | }
|
|---|
| 51 | public PlatnoscController(IDataContext datacontext)
|
|---|
| 52 | {
|
|---|
| 53 | _rep = new Repository<PotwierdzeniaEcard>(datacontext);
|
|---|
| 54 | _repPl = new Repository<PlatnosciEcard>(datacontext);
|
|---|
| 55 | _context1 = datacontext;
|
|---|
| 56 | _func = new FunkcjePlatnosci();
|
|---|
| 57 | }
|
|---|
| 58 | public ActionResult Show(string id, string language)
|
|---|
| 59 | {
|
|---|
| 60 |
|
|---|
| 61 | language = _func.setLanguage(language);
|
|---|
| 62 | int id1 = 0;
|
|---|
| 63 | try
|
|---|
| 64 | {
|
|---|
| 65 | id1 = (id != null) ? Convert.ToInt32(id) : 0;
|
|---|
| 66 | }
|
|---|
| 67 | catch
|
|---|
| 68 | {
|
|---|
| 69 | }
|
|---|
| 70 | vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
|
|---|
| 71 | ErrorViewData errorViewData = new ErrorViewData();
|
|---|
| 72 | if (platnosc == null)
|
|---|
| 73 | {
|
|---|
| 74 | errorViewData.error = brakdanych;
|
|---|
| 75 | return View("Error1", errorViewData);
|
|---|
| 76 | }
|
|---|
| 77 | else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name))
|
|---|
| 78 | {
|
|---|
| 79 | errorViewData.error = weryfikacja;
|
|---|
| 80 | return View("Error1", errorViewData);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | var tablica_potwierdzenia = _rep.FindItemsByIdFaktury(id1);
|
|---|
| 84 | if (tablica_potwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana
|
|---|
| 85 | {
|
|---|
| 86 | string data_zaplaty = String.Format("{0:dd-MM-yyyy}",tablica_potwierdzenia[0].AUTHTIME);
|
|---|
| 87 | errorViewData.error = String.Format(zaplacono, platnosc.Faktura_Numer, data_zaplaty);
|
|---|
| 88 | return View("Error1", errorViewData);
|
|---|
| 89 | }
|
|---|
| 90 | string kwota = "";
|
|---|
| 91 | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| 92 | var payer = InitPayer("", "", platnosc.ID_faktury);
|
|---|
| 93 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota);
|
|---|
| 94 | return View(invoiceDeatailsViewData);
|
|---|
| 95 | }
|
|---|
| 96 | [Authorize]
|
|---|
| 97 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 98 | public ActionResult Show(Payer payer, string language)
|
|---|
| 99 | {
|
|---|
| 100 | language = _func.setLanguage(language);
|
|---|
| 101 | int id1 = 0;
|
|---|
| 102 | try
|
|---|
| 103 | {
|
|---|
| 104 | id1 = (payer.Id_faktury != null) ? Convert.ToInt32(payer.Id_faktury) : 0;
|
|---|
| 105 | }
|
|---|
| 106 | catch
|
|---|
| 107 | {
|
|---|
| 108 | }
|
|---|
| 109 | vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
|
|---|
| 110 | ErrorViewData errorViewData = new ErrorViewData();
|
|---|
| 111 |
|
|---|
| 112 | if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name))
|
|---|
| 113 | {
|
|---|
| 114 | errorViewData.error = weryfikacja;
|
|---|
| 115 | return View("Error1", errorViewData);
|
|---|
| 116 | }
|
|---|
| 117 | if (platnosc == null)
|
|---|
| 118 | {
|
|---|
| 119 | errorViewData.error = brakdanych;
|
|---|
| 120 | return View("Error1", errorViewData);
|
|---|
| 121 | }
|
|---|
| 122 | else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name))
|
|---|
| 123 | {
|
|---|
| 124 | errorViewData.error = weryfikacja;
|
|---|
| 125 | return View("Error1", errorViewData);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | if (String.IsNullOrEmpty(payer.FirstName))
|
|---|
| 129 | {
|
|---|
| 130 | ModelState.AddModelError("Payer.FirstName", err_imie);
|
|---|
| 131 | }
|
|---|
| 132 | if (String.IsNullOrEmpty(payer.LastName))
|
|---|
| 133 | {
|
|---|
| 134 | ModelState.AddModelError("Payer.LastName", err_nazwisko);
|
|---|
| 135 | }
|
|---|
| 136 | if (ModelState.IsValid == false)
|
|---|
| 137 | {
|
|---|
| 138 | string kwota = "";
|
|---|
| 139 | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| 140 | var viewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota );
|
|---|
| 141 | return View("Show",viewData);
|
|---|
| 142 | }
|
|---|
| 143 | if (payer != null)
|
|---|
| 144 | return RedirectToAction("Merchant", "Merchant", payer);
|
|---|
| 145 | else return View("Error");
|
|---|
| 146 | }
|
|---|
| 147 | public ActionResult Potwierdzenie(string id, string status, string language)
|
|---|
| 148 | {
|
|---|
| 149 | language = _func.setLanguage(language);
|
|---|
| 150 |
|
|---|
| 151 | int id1 = 0;
|
|---|
| 152 | try
|
|---|
| 153 | {
|
|---|
| 154 | id1 = (id != null) ? Convert.ToInt32(id) : 0;
|
|---|
| 155 | }
|
|---|
| 156 | catch
|
|---|
| 157 | {
|
|---|
| 158 | //id1=0 -> error type = platnoscIsNotExist;
|
|---|
| 159 | }
|
|---|
| 160 | vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
|
|---|
| 161 | ErrorViewData errorViewData = new ErrorViewData();
|
|---|
| 162 | if (platnosc == null)
|
|---|
| 163 | {
|
|---|
| 164 | errorViewData.error = brakdanych;
|
|---|
| 165 | return View("Error1", errorViewData);
|
|---|
| 166 | }
|
|---|
| 167 | else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name))
|
|---|
| 168 | {
|
|---|
| 169 | errorViewData.error = weryfikacja;
|
|---|
| 170 | return View("Error1", errorViewData);
|
|---|
| 171 | }
|
|---|
| 172 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, status, "" );
|
|---|
| 173 | return View(invoiceDeatailsViewData);
|
|---|
| 174 | }
|
|---|
| 175 | public void UpdateStatus(int ordernumber, string validationcode)
|
|---|
| 176 | {
|
|---|
| 177 |
|
|---|
| 178 | var platnosc = _repPl.FindOne(i => i.ORDERNUMBER == ordernumber);
|
|---|
| 179 | if (platnosc != null && platnosc.Status == true && validationcode == "000")
|
|---|
| 180 | {
|
|---|
| 181 | platnosc.Status = true;
|
|---|
| 182 | platnosc.Status_data = DateTime.Now;
|
|---|
| 183 | _repPl.Update(platnosc);
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 | public ActionResult Status()
|
|---|
| 187 | {
|
|---|
| 188 | if (string.IsNullOrEmpty(Request.Form["MERCHANTNUMBER"]))
|
|---|
| 189 | throw new ArgumentException("MERCHANTNUMBER");
|
|---|
| 190 |
|
|---|
| 191 | //TODO: validate the Form
|
|---|
| 192 | string MERCHANTNUMBER = Request.Form["MERCHANTNUMBER"];
|
|---|
| 193 | int ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]);
|
|---|
| 194 | string COMMTYPE = Request.Form["COMMTYPE"];
|
|---|
| 195 | string CURRENTSTATE = Request.Form["CURRENTSTATE"];
|
|---|
| 196 | string PREVIOUSSTATE = Request.Form["PREVIOUSSTATE"];
|
|---|
| 197 | bool PAYMENTTYPE = Convert.ToBoolean(Request.Form["PAYMENTTYPE"]);
|
|---|
| 198 | bool EVENTTYPE = Convert.ToBoolean(Request.Form["EVENTTYPE"]);
|
|---|
| 199 | bool PAYMENTNUMBER = Convert.ToBoolean(Request.Form["PAYMENTNUMBER"]);
|
|---|
| 200 | string APPROVALCODE = Request.Form["APPROVALCODE"];
|
|---|
| 201 | string VALIDATIONCODE = Request.Form["VALIDATIONCODE"];
|
|---|
| 202 | string BIN = Request.Form["BIN"];
|
|---|
| 203 | DateTime AUTHTIME = Convert.ToDateTime(Request.Form["AUTHTIME"]);
|
|---|
| 204 | string TYPE = Request.Form["TYPE"];
|
|---|
| 205 | string WITHCVC = Request.Form["WITHCVC"];
|
|---|
| 206 | DateTime DATATRANSMISJI = Convert.ToDateTime(Request.Form["DATATRANSMISJI"]);
|
|---|
| 207 |
|
|---|
| 208 | PotwierdzeniaEcard potwierdzenie = new PotwierdzeniaEcard();
|
|---|
| 209 | potwierdzenie.APPROVALCODE = APPROVALCODE;
|
|---|
| 210 | potwierdzenie.AUTHTIME = AUTHTIME;
|
|---|
| 211 | potwierdzenie.BIN = BIN;
|
|---|
| 212 | potwierdzenie.COMMTYPE = COMMTYPE;
|
|---|
| 213 | potwierdzenie.CURRENTSTATE = CURRENTSTATE;
|
|---|
| 214 | potwierdzenie.DATATRANSMISJI = DATATRANSMISJI;
|
|---|
| 215 | potwierdzenie.EVENTTYPE = EVENTTYPE;
|
|---|
| 216 | potwierdzenie.MERCHANTNUMBER = MERCHANTNUMBER;
|
|---|
| 217 | potwierdzenie.ORDERNUMBER = ORDERNUMBER;
|
|---|
| 218 | potwierdzenie.PAYMENTNUMBER = PAYMENTNUMBER;
|
|---|
| 219 | potwierdzenie.PAYMENTTYPE = PAYMENTTYPE;
|
|---|
| 220 | potwierdzenie.PREVIOUSSTATE = PREVIOUSSTATE;
|
|---|
| 221 | potwierdzenie.TYPE = TYPE;
|
|---|
| 222 | potwierdzenie.VALIDATIONCODE = VALIDATIONCODE;
|
|---|
| 223 | potwierdzenie.WITHCVC = WITHCVC;
|
|---|
| 224 |
|
|---|
| 225 | _rep.Insert(potwierdzenie);
|
|---|
| 226 | return View();
|
|---|
| 227 | }
|
|---|
| 228 | private Payer InitPayer(string FirstName, string LastName, int Id_faktury)
|
|---|
| 229 | {
|
|---|
| 230 | Payer payer = new Payer();
|
|---|
| 231 | payer.FirstName = "";
|
|---|
| 232 | payer.LastName = "";
|
|---|
| 233 | payer.Id_faktury = Id_faktury;
|
|---|
| 234 | return payer;
|
|---|
| 235 | }
|
|---|
| 236 | private InvoiceDetailsViewData InitInvoiceDetailsViewData(vPlatnosciEcard platnosc, Payer payer, string status, string brutto )
|
|---|
| 237 | {
|
|---|
| 238 | var invoiceDeatailsViewData = new InvoiceDetailsViewData();
|
|---|
| 239 | invoiceDeatailsViewData.vPlatnosciEcard = platnosc;
|
|---|
| 240 | invoiceDeatailsViewData.Payer = payer;
|
|---|
| 241 | invoiceDeatailsViewData.Status = status;
|
|---|
| 242 | invoiceDeatailsViewData.brutto = brutto;
|
|---|
| 243 | return invoiceDeatailsViewData;
|
|---|
| 244 | }
|
|---|
| 245 | public void setWeryfikacja(string value)
|
|---|
| 246 | {
|
|---|
| 247 | this.weryfikacja = value;
|
|---|
| 248 |
|
|---|
| 249 | }
|
|---|
| 250 | public void setBrakDanych(string value)
|
|---|
| 251 | {
|
|---|
| 252 | this.brakdanych = value;
|
|---|
| 253 |
|
|---|
| 254 | }
|
|---|
| 255 | public void setZaplacono(string value)
|
|---|
| 256 | {
|
|---|
| 257 | this.zaplacono = value;
|
|---|
| 258 |
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | }
|
|---|
| 262 | }
|
|---|