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