| 61 | | |
| 62 | | var merchant = getMerchantInfo(systemKs); |
| 63 | | |
| 64 | | var hash = GetHash(newPayment, merchant); |
| 65 | | hash = hash.Replace("\n",""); |
| 66 | | |
| 67 | | if (hash == BAD_HASH || hash == "" || hash == HASH_ERROR_INFO) |
| 68 | | return View("Error1", IsError("error_hash", payer.Id_faktury)); |
| 69 | | |
| 70 | | //przeslanie w linku ordernumber potrzebnego do wyswietlenia potwierdzenia |
| 71 | | var orderek = _repPayment.GetOrdernumber(newPayment.ORDERDESCRIPTION, newPayment.IDFaktury, newPayment.Data); |
| 72 | | |
| 73 | | var linkFail = ConfigurationManager.AppSettings["Strona"]; |
| 74 | | linkFail += "/" + language + ConfigurationManager.AppSettings["LinkFail"]; |
| 75 | | linkFail += "/" + newPayment.IDFaktury + "?o=" + orderek; |
| 76 | | |
| 77 | | var linkOk = ConfigurationManager.AppSettings["Strona"]; |
| 78 | | linkOk += "/" + language + ConfigurationManager.AppSettings["LinkOk"]; |
| 79 | | linkOk += "/" + newPayment.IDFaktury + "?o=" + orderek; |
| 80 | | |
| 81 | | if (merchant != null && !String.IsNullOrEmpty(merchant.Id)) |
| 82 | | SendRequest(newPayment, hash, merchant, linkFail, linkOk); |
| 83 | | else |
| 84 | | return View("Error1", IsError("error_hash", payer.Id_faktury)); |
| 85 | | |
| | 62 | |
| | 63 | var adres = _eCardData.GetUrl(merchant); |
| | 64 | Response.Redirect(adres); |
| 87 | | } |
| 88 | | private PlatnosciEcard InitNewPayment(int id, vPlatnosciEcard platnosc, Waluta waluta, Payer payer) |
| 89 | | { |
| 90 | | var newPayment = new PlatnosciEcard(); |
| 91 | | newPayment.IDFaktury = id; |
| 92 | | newPayment.ORDERDESCRIPTION = platnosc.Faktura_Numer; |
| 93 | | newPayment.nip = platnosc.nip; |
| 94 | | newPayment.nrZlecenia = ""; |
| 95 | | newPayment.AMOUNT = waluta.Amount; |
| 96 | | newPayment.CURRENCY = waluta.Currency; |
| 97 | | newPayment.SESSIONID = Session.SessionID; |
| 98 | | newPayment.NAME = payer.FirstName; |
| 99 | | newPayment.SURNAME = payer.LastName; |
| 100 | | newPayment.AUTODEPOSIT = true; |
| 101 | | newPayment.LANGUAGE = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToUpper(); |
| 102 | | newPayment.CHARSET = KODOWANIE; |
| 103 | | newPayment.COUNTRY = KOD_POLSKA; |
| 104 | | newPayment.JS = true; |
| 105 | | newPayment.PAYMENTTYPE = CARDS; |
| 106 | | newPayment.Data = DateTime.Now; |
| 107 | | newPayment.Status = null; |
| 108 | | newPayment.Status_data = null; |
| 109 | | return newPayment; |
| 110 | | } |
| 111 | | |
| 112 | | private bool AddNewPayment(PlatnosciEcard platnosc) |
| 113 | | { |
| 114 | | if (platnosc != null) |
| 115 | | { |
| 116 | | _repPayment.Insert(platnosc); |
| 117 | | return true; |
| 118 | | } |
| 119 | | return false; |
| 120 | | } |
| 121 | | |
| 122 | | private string GetHash(PlatnosciEcard p, Merchant merchant) |
| 123 | | { |
| 124 | | var platnosc = _repPayment.Find(i => i.ORDERDESCRIPTION == p.ORDERDESCRIPTION && i.IDFaktury == p.IDFaktury && i.Data == p.Data).First(); |
| 125 | | |
| 126 | | if (platnosc == null || merchant == null) return HASH_ERROR_INFO; |
| 127 | | |
| 128 | | var adres = "https://pay.ecard.pl/servlet/HS?orderNumber=" + platnosc.ORDERNUMBER; |
| 129 | | var req = (HttpWebRequest)WebRequest.Create(adres); |
| 130 | | var dane = "&orderDescription=&amount=" + platnosc.AMOUNT; |
| 131 | | dane += "¤cy=" + platnosc.CURRENCY; |
| 132 | | dane += string.Format("&merchantId={0}&password={1}", merchant.Id, merchant.Password); |
| 133 | | |
| 134 | | var bdata = System.Text.Encoding.ASCII.GetBytes(dane); |
| 135 | | req.Method = "POST"; |
| 136 | | req.ContentType = "application/x-www-form-urlencoded"; |
| 137 | | req.ContentLength = dane.Length; |
| 138 | | |
| 139 | | var reqStream = req.GetRequestStream(); |
| 140 | | reqStream.Write(bdata, 0, bdata.Length); |
| 141 | | reqStream.Close(); |
| 142 | | |
| 143 | | var streamResponse = new StreamReader(req.GetResponse().GetResponseStream()); |
| 144 | | string strResponse = streamResponse.ReadToEnd(); |
| 145 | | streamResponse.Close(); |
| 146 | | |
| 147 | | return strResponse; |
| 148 | | } |
| 149 | | |
| 150 | | private void SendRequest(PlatnosciEcard m, string hash, Merchant merchant, string linkok, string linkfail) |
| 151 | | { |
| 152 | | var adres = ConfigurationManager.AppSettings["eCard.Url"] + "?ORDERDESCRIPTION=" + m.ORDERDESCRIPTION; |
| 153 | | |
| 154 | | var dane = "&AMOUNT=" + m.AMOUNT + "&CURRENCY=" + m.CURRENCY + "&ORDERNUMBER=" + m.ORDERNUMBER; |
| 155 | | dane += "&NAME=" + m.NAME + "&SURNAME=" + m.SURNAME + "&LANGUAGE=" + m.LANGUAGE + "&CHARSET=ISO-8859-2"; |
| 156 | | dane += "&COUNTRY=616&PAYMENTTYPE=CARDS&JS=1&HASH=" + hash + "&MERCHANTID=" + merchant.Id + "&AUTODEPOSIT=" + m.AUTODEPOSIT; |
| 157 | | dane += "&LINKFAIL=" + linkfail + "&LINKOK=" + linkok + "&SESSIONID=" + m.SESSIONID; |
| 158 | | Response.Redirect(adres + dane); |
| 159 | | } |
| | 66 | } |