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