| 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using System.Web.Mvc;
|
|---|
| 4 | using Platnosci.Models;
|
|---|
| 5 | using Platnosci.Core.Linq;
|
|---|
| 6 | using Platnosci.Core.Interface;
|
|---|
| 7 | using System.Configuration;
|
|---|
| 8 | using System.Net;
|
|---|
| 9 | using System.IO;
|
|---|
| 10 | using System.Threading;
|
|---|
| 11 |
|
|---|
| 12 | namespace Platnosci.Controllers
|
|---|
| 13 | {
|
|---|
| 14 | [Authorize]
|
|---|
| 15 | public class MerchantController : Controller
|
|---|
| 16 | {
|
|---|
| 17 | public const string BAD_HASH = "zlyHash"; //b³êdne has³o - odpowied z eCard
|
|---|
| 18 | public const string HASH_ERROR_INFO = "payment not exist";
|
|---|
| 19 |
|
|---|
| 20 | private readonly IRepository<vPlatnosciEcard> _repVPayment;
|
|---|
| 21 | private readonly IRepository<PlatnosciEcard> _repPayment;
|
|---|
| 22 | private readonly FunkcjePlatnosci _funkcjePlatnosci;
|
|---|
| 23 | private readonly eCardData _eCardData;
|
|---|
| 24 | private readonly ITranslateManager _translateManager;
|
|---|
| 25 |
|
|---|
| 26 | public MerchantController()
|
|---|
| 27 | {
|
|---|
| 28 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext());
|
|---|
| 29 | _repPayment = new Repository<PlatnosciEcard>(new DataContext());
|
|---|
| 30 | _funkcjePlatnosci = new FunkcjePlatnosci();
|
|---|
| 31 | _translateManager = new Translation();
|
|---|
| 32 | _eCardData = new eCardData(_repPayment);
|
|---|
| 33 | }
|
|---|
| 34 | public MerchantController(IRepository<vPlatnosciEcard> repVPayment, IRepository<PlatnosciEcard> repPayment, ITranslateManager translate, eCardData ecardData)
|
|---|
| 35 | {
|
|---|
| 36 | _repVPayment = repVPayment;
|
|---|
| 37 | _repPayment = repPayment;
|
|---|
| 38 | _funkcjePlatnosci = new FunkcjePlatnosci();
|
|---|
| 39 | _translateManager = translate;
|
|---|
| 40 | _eCardData = ecardData;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public ActionResult Merchant(Payer payer, string language)
|
|---|
| 44 | {
|
|---|
| 45 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| 46 |
|
|---|
| 47 | var id1 = Convert.ToInt32(payer.Id_faktury);
|
|---|
| 48 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 49 |
|
|---|
| 50 | if (platnosc == null)
|
|---|
| 51 | return View("Error1", IsError("brakdanych", 0));
|
|---|
| 52 |
|
|---|
| 53 | if (!_funkcjePlatnosci.UserIdentity(platnosc, ControllerContext.HttpContext.User.Identity.Name))
|
|---|
| 54 | return View("Error1", IsError("weryfikacja", 0));
|
|---|
| 55 |
|
|---|
| 56 | var merchant = _eCardData.CreateMerchantData(platnosc, payer, language, Session.SessionID);
|
|---|
| 57 |
|
|---|
| 58 | if (merchant != null) merchant.IsValid();
|
|---|
| 59 |
|
|---|
| 60 | if (merchant == null || (merchant != null && (!String.IsNullOrEmpty(merchant.Error))))
|
|---|
| 61 | return View("Error1", IsError("error_hash", payer.Id_faktury));
|
|---|
| 62 |
|
|---|
| 63 | var adres = _eCardData.GetUrl(merchant);
|
|---|
| 64 | Response.Redirect(adres);
|
|---|
| 65 | return new EmptyResult();
|
|---|
| 66 | }
|
|---|
| 67 | public ErrorViewData IsError(string errortxt, int idFaktury)
|
|---|
| 68 | {
|
|---|
| 69 | if (errortxt == "brakdanych")
|
|---|
| 70 | errortxt = _translateManager.Translate("tlumaczenia", "brakdanych");
|
|---|
| 71 | else if (errortxt == "weryfikacja")
|
|---|
| 72 | errortxt = _translateManager.Translate("tlumaczenia", "weryfikacja");
|
|---|
| 73 | else if (errortxt == "error_hash")
|
|---|
| 74 | errortxt = _translateManager.Translate("tlumaczenia", "error_hash");
|
|---|
| 75 | else if (errortxt == "error_hash")
|
|---|
| 76 | errortxt = _translateManager.Translate("tlumaczenia", "error_hash");
|
|---|
| 77 |
|
|---|
| 78 | return _funkcjePlatnosci.InitErrorViewData(errortxt, idFaktury);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|