| [866] | 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using System.Web.Mvc;
|
|---|
| [970] | 4 | using adMoto.Payments.Core;
|
|---|
| 5 | using adMoto.Payments.Core.Data;
|
|---|
| 6 | using adMoto.Payments.Core.Interfaces;
|
|---|
| [971] | 7 | using adMoto.Payments.Web.Models;
|
|---|
| [866] | 8 |
|
|---|
| [971] | 9 | namespace adMoto.Payments.Web.Controllers
|
|---|
| [866] | 10 | {
|
|---|
| 11 | [Authorize]
|
|---|
| 12 | public class MerchantController : Controller
|
|---|
| 13 | {
|
|---|
| [970] | 14 | private readonly IRepository<Invoice> _repVPayment;
|
|---|
| [919] | 15 | private readonly IRepository<PlatnosciEcard> _repPayment;
|
|---|
| [971] | 16 | private readonly PaymentsUtils _paymentsUtils;
|
|---|
| 17 | private readonly MerchantHelper _merchantHelper;
|
|---|
| [933] | 18 | private readonly ITranslateManager _translateManager;
|
|---|
| [866] | 19 |
|
|---|
| 20 | public MerchantController()
|
|---|
| [896] | 21 | {
|
|---|
| [970] | 22 | _repVPayment = new Repository<Invoice>(new DataContext());
|
|---|
| [949] | 23 | _repPayment = new Repository<PlatnosciEcard>(new DataContext());
|
|---|
| [971] | 24 | _paymentsUtils = new PaymentsUtils(_repPayment);
|
|---|
| [933] | 25 | _translateManager = new Translation();
|
|---|
| [971] | 26 | _merchantHelper = new MerchantHelper(_repPayment);
|
|---|
| [866] | 27 | }
|
|---|
| [970] | 28 | public MerchantController(IRepository<Invoice> repVPayment, IRepository<PlatnosciEcard> repPayment, ITranslateManager translate)
|
|---|
| [951] | 29 | {
|
|---|
| 30 | _repVPayment = repVPayment;
|
|---|
| 31 | _repPayment = repPayment;
|
|---|
| 32 | _translateManager = translate;
|
|---|
| [971] | 33 | _paymentsUtils = new PaymentsUtils(_repPayment, _translateManager);
|
|---|
| 34 | _merchantHelper = new MerchantHelper(_repPayment);
|
|---|
| [951] | 35 | }
|
|---|
| [866] | 36 | public ActionResult Merchant(Payer payer, string language)
|
|---|
| 37 | {
|
|---|
| [971] | 38 | language = _paymentsUtils.SetLanguage(language);
|
|---|
| [866] | 39 |
|
|---|
| [933] | 40 | var id1 = Convert.ToInt32(payer.Id_faktury);
|
|---|
| 41 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 42 |
|
|---|
| [971] | 43 | var errorViewData = _paymentsUtils.IsError(platnosc, ControllerContext.HttpContext.User.Identity.Name);
|
|---|
| [952] | 44 | if (!String.IsNullOrEmpty(errorViewData.Error))
|
|---|
| 45 | return View("Error1", errorViewData);
|
|---|
| 46 |
|
|---|
| [971] | 47 | var merchant = _merchantHelper.CreateMerchantData(platnosc, payer, language, Session.SessionID);
|
|---|
| [933] | 48 |
|
|---|
| [971] | 49 | if (merchant == null || !String.IsNullOrEmpty(merchant.Error))
|
|---|
| 50 | return View("Error1", _paymentsUtils.InitErrorViewData(_translateManager.Translate("tlumaczenia", "error_hash"), payer.Id_faktury));
|
|---|
| [951] | 51 |
|
|---|
| [971] | 52 | var adres = _merchantHelper.GetUrl(merchant);
|
|---|
| [951] | 53 | Response.Redirect(adres);
|
|---|
| [917] | 54 | return new EmptyResult();
|
|---|
| [952] | 55 | }
|
|---|
| [866] | 56 | }
|
|---|
| [971] | 57 | } |
|---|