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