| [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;
|
|---|
| 27 | private readonly IRepository<PotwierdzeniaEcard> _repConfirm;
|
|---|
| [866] | 28 | private FunkcjePlatnosci _func;
|
|---|
| [885] | 29 | private string weryfikacja;
|
|---|
| 30 | private string brakdanych;
|
|---|
| 31 | private string zaplacono;
|
|---|
| 32 | private string err_imie;
|
|---|
| 33 | private string err_nazwisko;
|
|---|
| [888] | 34 | private int test = 0;
|
|---|
| [885] | 35 |
|
|---|
| [866] | 36 | public PlatnoscController()
|
|---|
| 37 | {
|
|---|
| [896] | 38 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext1());
|
|---|
| 39 | _repPayment = new Repository<PlatnosciEcard>(new DataContext1());
|
|---|
| 40 | _repConfirm = new Repository<PotwierdzeniaEcard>(new DataContext1());
|
|---|
| 41 | _func = new FunkcjePlatnosci();
|
|---|
| [866] | 42 | }
|
|---|
| [896] | 43 | public PlatnoscController(IRepository<vPlatnosciEcard> repVPayment, IRepository<PlatnosciEcard> repPayment, IRepository<PotwierdzeniaEcard> repConfirm, int czy_test)
|
|---|
| [872] | 44 | {
|
|---|
| [896] | 45 | _repVPayment = repVPayment;
|
|---|
| 46 | _repPayment = repPayment;
|
|---|
| 47 | _repConfirm = repConfirm;
|
|---|
| [872] | 48 | _func = new FunkcjePlatnosci();
|
|---|
| [888] | 49 | test = czy_test;
|
|---|
| [870] | 50 | }
|
|---|
| [866] | 51 | public ActionResult Show(string id, string language)
|
|---|
| 52 | {
|
|---|
| 53 | language = _func.setLanguage(language);
|
|---|
| [888] | 54 | ustawTlumaczenia(test);
|
|---|
| [881] | 55 | int id1 = ConvertId(id);
|
|---|
| [873] | 56 |
|
|---|
| [896] | 57 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [880] | 58 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| [883] | 59 |
|
|---|
| 60 | string kwota = "";
|
|---|
| 61 | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| 62 | var payer = InitPayer("", "", platnosc.ID_faktury);
|
|---|
| 63 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota);
|
|---|
| 64 |
|
|---|
| [896] | 65 | var tablica_potwierdzenia = _repConfirm.FindItemsByIdFaktury(id1);
|
|---|
| [868] | 66 | if (tablica_potwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana
|
|---|
| [866] | 67 | {
|
|---|
| [883] | 68 | string data_zaplaty = String.Format("{0:dd-MM-yyyy}", tablica_potwierdzenia[0].AUTHTIME);
|
|---|
| 69 | invoiceDeatailsViewData.info = String.Format(zaplacono, platnosc.Faktura_Numer, data_zaplaty);
|
|---|
| 70 | invoiceDeatailsViewData.termin = data_zaplaty;
|
|---|
| 71 | return View("Paid", invoiceDeatailsViewData);
|
|---|
| [885] | 72 | }
|
|---|
| [888] | 73 | return View(invoiceDeatailsViewData);
|
|---|
| [868] | 74 | }
|
|---|
| [866] | 75 | [Authorize]
|
|---|
| 76 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 77 | public ActionResult Show(Payer payer, string language)
|
|---|
| 78 | {
|
|---|
| 79 | language = _func.setLanguage(language);
|
|---|
| [888] | 80 | ustawTlumaczenia(test);
|
|---|
| [896] | 81 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == payer.Id_faktury).SingleOrDefault();
|
|---|
| [880] | 82 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| [873] | 83 |
|
|---|
| [866] | 84 | if (String.IsNullOrEmpty(payer.FirstName))
|
|---|
| 85 | {
|
|---|
| [871] | 86 | ModelState.AddModelError("Payer.FirstName", err_imie);
|
|---|
| [866] | 87 | }
|
|---|
| 88 | if (String.IsNullOrEmpty(payer.LastName))
|
|---|
| 89 | {
|
|---|
| [871] | 90 | ModelState.AddModelError("Payer.LastName", err_nazwisko);
|
|---|
| [866] | 91 | }
|
|---|
| 92 | if (ModelState.IsValid == false)
|
|---|
| 93 | {
|
|---|
| 94 | string kwota = "";
|
|---|
| 95 | kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano);
|
|---|
| [868] | 96 | var viewData = InitInvoiceDetailsViewData(platnosc, payer, "", kwota );
|
|---|
| [866] | 97 | return View("Show",viewData);
|
|---|
| 98 | }
|
|---|
| 99 | if (payer != null)
|
|---|
| [873] | 100 | {
|
|---|
| [877] | 101 | System.Diagnostics.Debug.WriteLine("PlatnosciController:Show");
|
|---|
| [866] | 102 | return RedirectToAction("Merchant", "Merchant", payer);
|
|---|
| [877] | 103 | }
|
|---|
| [866] | 104 | else return View("Error");
|
|---|
| 105 | }
|
|---|
| [873] | 106 | public ActionResult Ok(string id, string language)
|
|---|
| [866] | 107 | {
|
|---|
| 108 | language = _func.setLanguage(language);
|
|---|
| [888] | 109 | ustawTlumaczenia(test);
|
|---|
| [873] | 110 | int id1 = ConvertId(id);
|
|---|
| [896] | 111 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [880] | 112 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| 113 |
|
|---|
| [873] | 114 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "" , "");
|
|---|
| [866] | 115 | return View(invoiceDeatailsViewData);
|
|---|
| 116 | }
|
|---|
| [873] | 117 | public ActionResult Fail(string id, string language)
|
|---|
| [871] | 118 | {
|
|---|
| [873] | 119 | language = _func.setLanguage(language);
|
|---|
| [888] | 120 | ustawTlumaczenia(test);
|
|---|
| [873] | 121 | int id1 = ConvertId(id);
|
|---|
| [896] | 122 | vPlatnosciEcard platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| [885] | 123 | if (!String.IsNullOrEmpty(Iserror(platnosc).error)) return View("Error1", Iserror(platnosc));
|
|---|
| [873] | 124 |
|
|---|
| 125 | var invoiceDeatailsViewData = InitInvoiceDetailsViewData(platnosc, null, "", "");
|
|---|
| 126 | return View(invoiceDeatailsViewData);
|
|---|
| [871] | 127 | }
|
|---|
| [866] | 128 | public ActionResult Status()
|
|---|
| 129 | {
|
|---|
| 130 | string MERCHANTNUMBER = Request.Form["MERCHANTNUMBER"];
|
|---|
| 131 | int ORDERNUMBER = Convert.ToInt32(Request.Form["ORDERNUMBER"]);
|
|---|
| 132 | string COMMTYPE = Request.Form["COMMTYPE"];
|
|---|
| 133 | string CURRENTSTATE = Request.Form["CURRENTSTATE"];
|
|---|
| 134 | string PREVIOUSSTATE = Request.Form["PREVIOUSSTATE"];
|
|---|
| 135 | bool PAYMENTTYPE = Convert.ToBoolean(Request.Form["PAYMENTTYPE"]);
|
|---|
| 136 | bool EVENTTYPE = Convert.ToBoolean(Request.Form["EVENTTYPE"]);
|
|---|
| 137 | bool PAYMENTNUMBER = Convert.ToBoolean(Request.Form["PAYMENTNUMBER"]);
|
|---|
| 138 | string APPROVALCODE = Request.Form["APPROVALCODE"];
|
|---|
| 139 | string VALIDATIONCODE = Request.Form["VALIDATIONCODE"];
|
|---|
| 140 | string BIN = Request.Form["BIN"];
|
|---|
| 141 | DateTime AUTHTIME = Convert.ToDateTime(Request.Form["AUTHTIME"]);
|
|---|
| 142 | string TYPE = Request.Form["TYPE"];
|
|---|
| 143 | string WITHCVC = Request.Form["WITHCVC"];
|
|---|
| 144 | DateTime DATATRANSMISJI = Convert.ToDateTime(Request.Form["DATATRANSMISJI"]);
|
|---|
| 145 |
|
|---|
| 146 | PotwierdzeniaEcard potwierdzenie = new PotwierdzeniaEcard();
|
|---|
| 147 | potwierdzenie.APPROVALCODE = APPROVALCODE;
|
|---|
| 148 | potwierdzenie.AUTHTIME = AUTHTIME;
|
|---|
| 149 | potwierdzenie.BIN = BIN;
|
|---|
| 150 | potwierdzenie.COMMTYPE = COMMTYPE;
|
|---|
| 151 | potwierdzenie.CURRENTSTATE = CURRENTSTATE;
|
|---|
| 152 | potwierdzenie.DATATRANSMISJI = DATATRANSMISJI;
|
|---|
| 153 | potwierdzenie.EVENTTYPE = EVENTTYPE;
|
|---|
| 154 | potwierdzenie.MERCHANTNUMBER = MERCHANTNUMBER;
|
|---|
| 155 | potwierdzenie.ORDERNUMBER = ORDERNUMBER;
|
|---|
| 156 | potwierdzenie.PAYMENTNUMBER = PAYMENTNUMBER;
|
|---|
| 157 | potwierdzenie.PAYMENTTYPE = PAYMENTTYPE;
|
|---|
| 158 | potwierdzenie.PREVIOUSSTATE = PREVIOUSSTATE;
|
|---|
| 159 | potwierdzenie.TYPE = TYPE;
|
|---|
| 160 | potwierdzenie.VALIDATIONCODE = VALIDATIONCODE;
|
|---|
| 161 | potwierdzenie.WITHCVC = WITHCVC;
|
|---|
| 162 |
|
|---|
| [896] | 163 | _repConfirm.Insert(potwierdzenie);
|
|---|
| [883] | 164 | UpdateStatus(ORDERNUMBER, CURRENTSTATE);
|
|---|
| [866] | 165 | return View();
|
|---|
| 166 | }
|
|---|
| [868] | 167 | private Payer InitPayer(string FirstName, string LastName, int Id_faktury)
|
|---|
| 168 | {
|
|---|
| 169 | Payer payer = new Payer();
|
|---|
| 170 | payer.FirstName = "";
|
|---|
| 171 | payer.LastName = "";
|
|---|
| 172 | payer.Id_faktury = Id_faktury;
|
|---|
| 173 | return payer;
|
|---|
| 174 | }
|
|---|
| 175 | private InvoiceDetailsViewData InitInvoiceDetailsViewData(vPlatnosciEcard platnosc, Payer payer, string status, string brutto )
|
|---|
| 176 | {
|
|---|
| 177 | var invoiceDeatailsViewData = new InvoiceDetailsViewData();
|
|---|
| 178 | invoiceDeatailsViewData.vPlatnosciEcard = platnosc;
|
|---|
| 179 | invoiceDeatailsViewData.Payer = payer;
|
|---|
| 180 | invoiceDeatailsViewData.Status = status;
|
|---|
| 181 | invoiceDeatailsViewData.brutto = brutto;
|
|---|
| 182 | return invoiceDeatailsViewData;
|
|---|
| 183 | }
|
|---|
| [888] | 184 | private void ustawTlumaczenia(int test)
|
|---|
| [885] | 185 | {
|
|---|
| [888] | 186 | if (test == 0)
|
|---|
| 187 | {
|
|---|
| 188 | weryfikacja = Resources.tlumaczenia.weryfikacja.ToString();
|
|---|
| 189 | brakdanych = Resources.tlumaczenia.brakdanych.ToString();
|
|---|
| 190 | zaplacono = Resources.tlumaczenia.zaplacono.ToString();
|
|---|
| 191 | err_imie = Resources.tlumaczenia.err_imieWK.ToString();
|
|---|
| 192 | err_nazwisko = Resources.tlumaczenia.err_nazwiskoWK.ToString();
|
|---|
| 193 | }
|
|---|
| [885] | 194 | }
|
|---|
| [871] | 195 | public void setWeryfikacja(string value)
|
|---|
| 196 | {
|
|---|
| 197 | this.weryfikacja = value;
|
|---|
| 198 | }
|
|---|
| 199 | public void setBrakDanych(string value)
|
|---|
| 200 | {
|
|---|
| 201 | this.brakdanych = value;
|
|---|
| 202 | }
|
|---|
| 203 | public void setZaplacono(string value)
|
|---|
| 204 | {
|
|---|
| 205 | this.zaplacono = value;
|
|---|
| [873] | 206 | }
|
|---|
| 207 | public int ConvertId(string id)
|
|---|
| 208 | {
|
|---|
| 209 | int id1 = 0;
|
|---|
| 210 | try
|
|---|
| 211 | {
|
|---|
| 212 | id1 = (id != null) ? Convert.ToInt32(id) : 0;
|
|---|
| 213 | }
|
|---|
| 214 | catch
|
|---|
| 215 | {
|
|---|
| 216 | }
|
|---|
| 217 | return id1;
|
|---|
| 218 | }
|
|---|
| 219 | public ErrorViewData Iserror(vPlatnosciEcard platnosc)
|
|---|
| 220 | {
|
|---|
| [880] | 221 | string errortxt = "";
|
|---|
| 222 | if (platnosc == null) errortxt = brakdanych;
|
|---|
| 223 | else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) errortxt = weryfikacja;
|
|---|
| 224 | ErrorViewData errorViewData = _func.InitErrorViewData(errortxt);
|
|---|
| [873] | 225 | return errorViewData;
|
|---|
| 226 | }
|
|---|
| [883] | 227 | public void UpdateStatus(int ordernumber, string currentstate)
|
|---|
| [873] | 228 | {
|
|---|
| [896] | 229 | PlatnosciEcard platnosc = _repPayment.Find(p => p.ORDERNUMBER == ordernumber).SingleOrDefault();
|
|---|
| [888] | 230 | if (platnosc != null && currentstate == ISPAID)
|
|---|
| [873] | 231 | {
|
|---|
| 232 | platnosc.Status = true;
|
|---|
| 233 | platnosc.Status_data = DateTime.Now;
|
|---|
| [896] | 234 | _repPayment.SubmitChanges();
|
|---|
| [888] | 235 |
|
|---|
| 236 | System.Diagnostics.Debug.WriteLine("IsUpdate");
|
|---|
| [873] | 237 | }
|
|---|
| 238 | }
|
|---|
| [866] | 239 | }
|
|---|
| 240 | }
|
|---|