| [951] | 1 | using System;
|
|---|
| 2 | using System.Net;
|
|---|
| 3 | using System.IO;
|
|---|
| 4 | using System.Linq;
|
|---|
| [952] | 5 | using System.Configuration;
|
|---|
| 6 | using Platnosci.Core.Linq;
|
|---|
| 7 | using Platnosci.Core.Interface;
|
|---|
| [951] | 8 |
|
|---|
| 9 | namespace Platnosci.Models
|
|---|
| 10 | {
|
|---|
| 11 | public class eCardData
|
|---|
| 12 | {
|
|---|
| 13 | public const string HASH_ERROR_INFO = "payment not exist";
|
|---|
| 14 | private readonly FunkcjePlatnosci _funkcjePlatnosci;
|
|---|
| 15 | private IRepository<PlatnosciEcard> _repPayment;
|
|---|
| [960] | 16 |
|
|---|
| [951] | 17 | public eCardData(IRepository<PlatnosciEcard> repPayment)
|
|---|
| 18 | {
|
|---|
| 19 | _repPayment = repPayment;
|
|---|
| [952] | 20 | _funkcjePlatnosci = new FunkcjePlatnosci(_repPayment);
|
|---|
| [951] | 21 | }
|
|---|
| 22 |
|
|---|
| 23 | public String GetUrl(Merchant merchant)
|
|---|
| 24 | {
|
|---|
| [960] | 25 | if (merchant == null)
|
|---|
| 26 | throw new ArgumentNullException("merchant");
|
|---|
| 27 |
|
|---|
| [951] | 28 | var dane = ConfigurationManager.AppSettings["eCard.Url"] + "?ORDERDESCRIPTION=" + merchant.Payment.ORDERDESCRIPTION;
|
|---|
| 29 | dane += "&AMOUNT=" + merchant.Payment.AMOUNT + "&CURRENCY=" + merchant.Payment.CURRENCY;
|
|---|
| 30 | dane += "&ORDERNUMBER=" + merchant.Payment.ORDERNUMBER;
|
|---|
| 31 | dane += "&NAME=" + merchant.Payment.NAME + "&SURNAME=" + merchant.Payment.SURNAME;
|
|---|
| 32 | dane += "&LANGUAGE=" + merchant.Payment.LANGUAGE + "&CHARSET=ISO-8859-2";
|
|---|
| 33 | dane += "&COUNTRY=616&PAYMENTTYPE=CARDS&JS=1&HASH=" + merchant.Hash;
|
|---|
| 34 | dane += "&MERCHANTID=" + merchant.Id + "&AUTODEPOSIT=" + merchant.Payment.AUTODEPOSIT;
|
|---|
| 35 | dane += "&LINKFAIL=" + merchant.LinkFail + "&LINKOK=" + merchant.LinkOk;
|
|---|
| 36 | dane += "&SESSIONID=" + merchant.Payment.SESSIONID;
|
|---|
| [968] | 37 |
|
|---|
| [951] | 38 | return dane;
|
|---|
| 39 | }
|
|---|
| 40 | public Merchant CreateMerchantData(vPlatnosciEcard invoice, Payer payer, string lang, string sessionId)
|
|---|
| 41 | {
|
|---|
| [952] | 42 | var merchant = new Merchant();
|
|---|
| [960] | 43 |
|
|---|
| [951] | 44 | var waluta = _funkcjePlatnosci.SetAmount(invoice);
|
|---|
| [952] | 45 | var newPayment = _funkcjePlatnosci.CreateAndAddNewPyment(invoice, waluta, payer, sessionId);
|
|---|
| [951] | 46 |
|
|---|
| 47 | merchant.SystemKsiegowy = invoice.SystemKsiegowyId.ToString();
|
|---|
| 48 |
|
|---|
| [960] | 49 | #if DEBUG
|
|---|
| [967] | 50 | //TODO: find better method to set SystemKsiegowy when testing or developing
|
|---|
| [960] | 51 | merchant.SystemKsiegowy = "2";
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| [951] | 54 | merchant.Payment = newPayment;
|
|---|
| [957] | 55 | GetMerchantInfo(merchant);
|
|---|
| [959] | 56 | merchant.Hash = SetHash(merchant);
|
|---|
| [951] | 57 |
|
|---|
| 58 | //przeslanie w linku ordernumber potrzebnego do wyswietlenia potwierdzenia
|
|---|
| 59 | var orderek = _repPayment.GetOrdernumber(newPayment.ORDERDESCRIPTION, newPayment.IDFaktury, newPayment.Data);
|
|---|
| 60 |
|
|---|
| 61 | var linkFail = ConfigurationManager.AppSettings["Strona"];
|
|---|
| 62 | linkFail += "/" + lang + ConfigurationManager.AppSettings["LinkFail"];
|
|---|
| [968] | 63 | linkFail += "/" + newPayment.IDFaktury + "/?";
|
|---|
| [951] | 64 |
|
|---|
| 65 | var linkOk = ConfigurationManager.AppSettings["Strona"];
|
|---|
| 66 | linkOk += "/" + lang + ConfigurationManager.AppSettings["LinkOk"];
|
|---|
| [968] | 67 | linkOk += "/" + newPayment.IDFaktury + "/" + orderek + "/?";
|
|---|
| [951] | 68 |
|
|---|
| 69 | merchant.LinkOk = linkOk;
|
|---|
| 70 | merchant.LinkFail = linkFail;
|
|---|
| 71 |
|
|---|
| [960] | 72 | merchant.IsValid();
|
|---|
| [952] | 73 |
|
|---|
| [951] | 74 | return merchant;
|
|---|
| 75 | }
|
|---|
| [967] | 76 |
|
|---|
| [957] | 77 | public void GetMerchantInfo(Merchant merchant)
|
|---|
| [951] | 78 | {
|
|---|
| 79 | if (merchant.SystemKsiegowy == "2")
|
|---|
| 80 | {
|
|---|
| 81 | merchant.Id = "171485000";
|
|---|
| 82 | merchant.Password = "ashSeth2";
|
|---|
| 83 | }
|
|---|
| 84 | else
|
|---|
| 85 | {
|
|---|
| 86 | merchant.Id = "170906000";
|
|---|
| 87 | merchant.Password = "JaYpqfs0";
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| [959] | 90 | public string SetHash(Merchant merchant)
|
|---|
| [951] | 91 | {
|
|---|
| [959] | 92 | if (merchant == null)
|
|---|
| [960] | 93 | throw new ArgumentNullException("merchant");
|
|---|
| [959] | 94 |
|
|---|
| [951] | 95 | var platnosc = _repPayment.Find(i => i.ORDERDESCRIPTION == merchant.Payment.ORDERDESCRIPTION && i.IDFaktury == merchant.Payment.IDFaktury && i.Data == merchant.Payment.Data).SingleOrDefault();
|
|---|
| 96 |
|
|---|
| [960] | 97 | if (platnosc == null)
|
|---|
| [951] | 98 | merchant.Hash = HASH_ERROR_INFO;
|
|---|
| 99 | else
|
|---|
| 100 | {
|
|---|
| 101 | var adres = "https://pay.ecard.pl/servlet/HS?orderNumber=" + platnosc.ORDERNUMBER;
|
|---|
| 102 | var req = (HttpWebRequest)WebRequest.Create(adres);
|
|---|
| 103 | var dane = "&orderDescription=&amount=" + platnosc.AMOUNT;
|
|---|
| 104 | dane += "¤cy=" + platnosc.CURRENCY;
|
|---|
| 105 | dane += string.Format("&merchantId={0}&password={1}", merchant.Id, merchant.Password);
|
|---|
| 106 |
|
|---|
| 107 | var bdata = System.Text.Encoding.ASCII.GetBytes(dane);
|
|---|
| 108 | req.Method = "POST";
|
|---|
| 109 | req.ContentType = "application/x-www-form-urlencoded";
|
|---|
| 110 | req.ContentLength = dane.Length;
|
|---|
| 111 |
|
|---|
| 112 | var reqStream = req.GetRequestStream();
|
|---|
| 113 | reqStream.Write(bdata, 0, bdata.Length);
|
|---|
| 114 | reqStream.Close();
|
|---|
| 115 |
|
|---|
| 116 | var streamResponse = new StreamReader(req.GetResponse().GetResponseStream());
|
|---|
| 117 | string strResponse = streamResponse.ReadToEnd();
|
|---|
| 118 | streamResponse.Close();
|
|---|
| 119 | strResponse = strResponse.Replace("\n", "");
|
|---|
| 120 |
|
|---|
| 121 | merchant.Hash = strResponse;
|
|---|
| 122 | }
|
|---|
| [959] | 123 | return merchant.Hash;
|
|---|
| [951] | 124 | }
|
|---|
| 125 | }
|
|---|
| [960] | 126 | } |
|---|