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