| [866] | 1 | using System;
|
|---|
| 2 | using System.Web;
|
|---|
| 3 | using Platnosci.Core.Linq;
|
|---|
| 4 | using System.Threading;
|
|---|
| 5 | using System.Globalization;
|
|---|
| 6 | using System.Configuration;
|
|---|
| [871] | 7 | using System.Security.Principal;
|
|---|
| [951] | 8 | using Platnosci.Core.Interface;
|
|---|
| [866] | 9 |
|
|---|
| 10 |
|
|---|
| 11 | namespace Platnosci.Models
|
|---|
| 12 | {
|
|---|
| 13 | public class FunkcjePlatnosci
|
|---|
| 14 | {
|
|---|
| [954] | 15 | public const string EUR = "978";
|
|---|
| 16 | public const string GBP = "826";
|
|---|
| 17 | public const string USD = "789";
|
|---|
| 18 | public const string PLN = "985";
|
|---|
| [951] | 19 | public const string CARDS = "CARDS"; //obsługa tylko kart płatniczych
|
|---|
| 20 | public const string KOD_POLSKA = "616"; //kod kraju Akceptanta - Polska
|
|---|
| 21 | public const string KODOWANIE = "ISO-8859-2";
|
|---|
| [952] | 22 | private IRepository<PlatnosciEcard> _repPayment;
|
|---|
| 23 | private readonly ITranslateManager _translateManager;
|
|---|
| [866] | 24 |
|
|---|
| [952] | 25 | public FunkcjePlatnosci()
|
|---|
| 26 | {
|
|---|
| 27 | _repPayment = new Repository<PlatnosciEcard>(new DataContext());
|
|---|
| 28 | _translateManager = new Translation();
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | public FunkcjePlatnosci(IRepository<PlatnosciEcard> repPayment)
|
|---|
| 32 | {
|
|---|
| 33 | _repPayment = repPayment;
|
|---|
| 34 | _translateManager = new Translation();
|
|---|
| 35 | }
|
|---|
| 36 | public FunkcjePlatnosci(IRepository<PlatnosciEcard> repPayment, ITranslateManager translate)
|
|---|
| 37 | {
|
|---|
| 38 | _repPayment = repPayment;
|
|---|
| 39 | _translateManager = translate;
|
|---|
| 40 | }
|
|---|
| [866] | 41 | public string BruttoToString(decimal? kwota, decimal? waluta, string miano)
|
|---|
| 42 | {
|
|---|
| [950] | 43 | var brutto = String.Format("{0:0.00}", kwota.ToString().Replace(",", ".")) + " PLN ";
|
|---|
| 44 |
|
|---|
| [957] | 45 | if (waluta > 0 && (miano != "" || miano.ToUpper() != "PLN"))
|
|---|
| 46 | brutto += "(" + (waluta.ToString()).Replace(",", ".") + " " + miano.ToUpper() + ")";
|
|---|
| 47 |
|
|---|
| [866] | 48 | return brutto;
|
|---|
| 49 | }
|
|---|
| [950] | 50 |
|
|---|
| [866] | 51 | public bool UserIdentity(vPlatnosciEcard platnosc, string userName)
|
|---|
| 52 | {
|
|---|
| [950] | 53 | return platnosc != null && platnosc.nip == userName;
|
|---|
| [866] | 54 | }
|
|---|
| [950] | 55 |
|
|---|
| 56 | public Waluta SetAmount(vPlatnosciEcard platnosc)
|
|---|
| 57 | {
|
|---|
| [952] | 58 | var waluta = new Waluta();
|
|---|
| [954] | 59 | waluta.Currency = GetCurrency(platnosc.waluta_miano);
|
|---|
| [957] | 60 |
|
|---|
| [954] | 61 | if (waluta.Currency == PLN)
|
|---|
| 62 | waluta.Amount = Convert.ToInt32(platnosc.Brutto * 100);
|
|---|
| [950] | 63 | else
|
|---|
| [954] | 64 | waluta.Amount = Convert.ToInt32(platnosc.waluta_brutto * 100);
|
|---|
| 65 |
|
|---|
| [866] | 66 | return waluta;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| [954] | 69 | public string GetCurrency(string currency)
|
|---|
| 70 | {
|
|---|
| 71 | if (string.IsNullOrEmpty(currency))
|
|---|
| 72 | return PLN;
|
|---|
| 73 |
|
|---|
| 74 | switch (currency.ToUpper())
|
|---|
| 75 | {
|
|---|
| 76 | case "EUR":
|
|---|
| 77 | return EUR;
|
|---|
| 78 | case "GBP":
|
|---|
| 79 | return GBP;
|
|---|
| 80 | case "USD":
|
|---|
| 81 | return USD;
|
|---|
| 82 | default:
|
|---|
| 83 | return PLN;
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| [950] | 87 | public string SetLanguage(string lang)
|
|---|
| 88 | {
|
|---|
| 89 | switch (lang)
|
|---|
| [866] | 90 | {
|
|---|
| [950] | 91 | case "de":
|
|---|
| 92 | case "en":
|
|---|
| 93 | case "pl":
|
|---|
| 94 | if (lang != Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower())
|
|---|
| 95 | {
|
|---|
| 96 | var culture = "pl-PL";
|
|---|
| 97 | switch (lang)
|
|---|
| 98 | {
|
|---|
| 99 | case "pl":
|
|---|
| 100 | culture = "pl-PL";
|
|---|
| 101 | break;
|
|---|
| 102 | case "en":
|
|---|
| 103 | culture = "en-US";
|
|---|
| 104 | break;
|
|---|
| 105 | case "de":
|
|---|
| 106 | culture = "de-DE";
|
|---|
| 107 | break;
|
|---|
| 108 | }
|
|---|
| [866] | 109 |
|
|---|
| [950] | 110 | Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
|
|---|
| 111 | Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
|
|---|
| 112 | }
|
|---|
| 113 | break;
|
|---|
| [866] | 114 | }
|
|---|
| [950] | 115 | return CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToLower();
|
|---|
| [866] | 116 | }
|
|---|
| [950] | 117 |
|
|---|
| 118 | public string SetTitle()
|
|---|
| [866] | 119 | {
|
|---|
| [950] | 120 | var str = "";
|
|---|
| 121 | var css = ConfigurationManager.AppSettings["Css"];
|
|---|
| 122 |
|
|---|
| 123 | if (css == "truck")
|
|---|
| 124 | str = HttpContext.GetGlobalResourceObject("tlumaczenia", "adresTruck") + " - ";
|
|---|
| 125 | else if (css == "admoto")
|
|---|
| 126 | str = HttpContext.GetGlobalResourceObject("tlumaczenia", "adresAdmoto") + " - ";
|
|---|
| 127 |
|
|---|
| [866] | 128 | return str;
|
|---|
| 129 | }
|
|---|
| [950] | 130 |
|
|---|
| 131 | public void SetUserLogger(string nip, string faktura)
|
|---|
| 132 | {
|
|---|
| 133 |
|
|---|
| 134 | var user = nip + "-" + faktura;
|
|---|
| 135 | Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(user, ""), null);
|
|---|
| [871] | 136 | }
|
|---|
| [950] | 137 |
|
|---|
| [934] | 138 | public ErrorViewData InitErrorViewData(string errortxt, int idFaktury)
|
|---|
| [880] | 139 | {
|
|---|
| [950] | 140 | var er = new ErrorViewData { Error = errortxt, InvoiceId = idFaktury };
|
|---|
| [880] | 141 | return er;
|
|---|
| 142 | }
|
|---|
| [952] | 143 | public PlatnosciEcard CreateAndAddNewPyment(vPlatnosciEcard platnosc, Waluta waluta, Payer payer, string sessionId)
|
|---|
| [951] | 144 | {
|
|---|
| 145 | var newPayment = new PlatnosciEcard();
|
|---|
| 146 | newPayment.IDFaktury = platnosc.ID_faktury;
|
|---|
| 147 | newPayment.ORDERDESCRIPTION = platnosc.Faktura_Numer;
|
|---|
| 148 | newPayment.nip = platnosc.nip;
|
|---|
| 149 | newPayment.nrZlecenia = "";
|
|---|
| 150 | newPayment.AMOUNT = waluta.Amount;
|
|---|
| 151 | newPayment.CURRENCY = waluta.Currency;
|
|---|
| 152 | newPayment.SESSIONID = sessionId;
|
|---|
| 153 | newPayment.NAME = payer.FirstName;
|
|---|
| 154 | newPayment.SURNAME = payer.LastName;
|
|---|
| 155 | newPayment.AUTODEPOSIT = true;
|
|---|
| [958] | 156 | newPayment.LANGUAGE = GetLanguage(); //ustawiamy jezyk, w ktorym ma byc wyświetlany formularz na stronie eCard
|
|---|
| [951] | 157 | newPayment.CHARSET = KODOWANIE;
|
|---|
| 158 | newPayment.COUNTRY = KOD_POLSKA;
|
|---|
| 159 | newPayment.JS = true;
|
|---|
| 160 | newPayment.PAYMENTTYPE = CARDS;
|
|---|
| 161 | newPayment.Data = DateTime.Now;
|
|---|
| 162 | newPayment.Status = null;
|
|---|
| 163 | newPayment.Status_data = null;
|
|---|
| [950] | 164 |
|
|---|
| [952] | 165 | _repPayment.Insert(newPayment);
|
|---|
| 166 | return newPayment;
|
|---|
| [951] | 167 | }
|
|---|
| [952] | 168 | public ErrorViewData IsError(vPlatnosciEcard platnosc, String UserName)
|
|---|
| 169 | {
|
|---|
| 170 | var errortxt = "";
|
|---|
| 171 |
|
|---|
| 172 | if (platnosc == null)
|
|---|
| 173 | errortxt = _translateManager.Translate("tlumaczenia", "brakdanych");
|
|---|
| 174 | else if (!UserIdentity(platnosc, UserName))
|
|---|
| 175 | errortxt = _translateManager.Translate("tlumaczenia", "weryfikacja");
|
|---|
| 176 |
|
|---|
| 177 | return InitErrorViewData(errortxt, 0);
|
|---|
| 178 | }
|
|---|
| [958] | 179 | public string GetLanguage()
|
|---|
| 180 | {
|
|---|
| 181 | string language = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToUpper();
|
|---|
| 182 |
|
|---|
| 183 | if (language != "PL" && language != "EN" && language != "DE")
|
|---|
| 184 | return "PL"; //domyślny jezyk, w ktorym ma byc wyświetlony formularz na stronie eCard
|
|---|
| 185 | else
|
|---|
| 186 | return language;
|
|---|
| 187 | }
|
|---|
| [866] | 188 | }
|
|---|
| [950] | 189 | } |
|---|