Index: branches/Emisje/eCard/eCardMVC/Platnosci/Controllers/MerchantController.cs
===================================================================
--- branches/Emisje/eCard/eCardMVC/Platnosci/Controllers/MerchantController.cs (revision 868)
+++ branches/Emisje/eCard/eCardMVC/Platnosci/Controllers/MerchantController.cs (revision 895)
@@ -29,13 +29,14 @@
         public const string KOD_POLSKA = "616";         //kod kraju Akceptanta - Polska
         public const string KODOWANIE = "ISO-8859-2";
+        private int ORDERNUMBER = 122;
 
         private string merchantId;
         private readonly PlatnosciDataContext _context;
-        private readonly IRepositoryPE _rep;
+        private readonly IRepository<PlatnosciEcard> _rep;
         private FunkcjePlatnosci _func;
 
         public MerchantController()
         {   
-            _rep = new RepositoryPlatnosciEcard();
+            _rep = new Repository<PlatnosciEcard>(new DataContext1());
             _context = new PlatnosciDataContext();
             _func = new FunkcjePlatnosci();
@@ -43,13 +44,18 @@
         public ActionResult Merchant(Payer payer, string language)
         {
+            System.Diagnostics.Debug.WriteLine("MerchantController:Merchant:" + language);
             language = _func.setLanguage(language);
 
             int id1 = Convert.ToInt32(payer.Id_faktury);
-            vPlatnosciEcard platnosc = _context.FindInvoiceById(id1).SingleOrDefault();
-            
-            if (!_func.UserIdentity(platnosc, ControllerContext.HttpContext.User.Identity.Name))
+            vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
+                 
+            if (platnosc == null)
             {
-                ErrorViewData errorViewData = new ErrorViewData();
-                errorViewData.error = HttpContext.GetGlobalResourceObject("tlumaczenia", "weryfikacja").ToString();
+                ErrorViewData errorViewData = _func.InitErrorViewData(HttpContext.GetGlobalResourceObject("tlumaczenia", "brakdanych").ToString());
+                return View("Error1", errorViewData);
+            }
+            else if (!_func.UserIdentity(platnosc, ControllerContext.HttpContext.User.Identity.Name))
+            {
+                ErrorViewData errorViewData = _func.InitErrorViewData(HttpContext.GetGlobalResourceObject("tlumaczenia", "weryfikacja").ToString());
                 return View("Error1", errorViewData);
             }
@@ -64,20 +70,20 @@
 
             string hash = GetHash(newPayment, systemKs);
+            hash = hash.Replace("\n","");
+            if (hash == BAD_HASH  || hash == "" ) return View("Error");
 
-            hash = hash.Replace("\n","");
-            if (hash == BAD_HASH  || hash == "" )
-            {
-                return View("Error"); //nie mo¿na po³¹czyæ siê z serverem p³atnoci. Proszê spróbowaæ jeszcze raz.
-            }
-            if (platnosc.SystemKsiegowyId == 1)
-                merchantId = "170906000";
-            else
-                merchantId = "171485000";
+            if (systemKs == "1") merchantId = "170906000";
+                else merchantId = "171485000";
 
-            string link = ConfigurationManager.AppSettings["StatusLink"];
-            string LinkFail = link + "?status=fail";
-            string LinkOk = link + "?status=ok";
+            string LinkFail = ConfigurationManager.AppSettings["Strona"];
+            LinkFail += "/" + language + ConfigurationManager.AppSettings["LinkFail"];
+            LinkFail += "/" + newPayment.IDFaktury;
+
+            string LinkOk = ConfigurationManager.AppSettings["Strona"];
+            LinkOk += "/" + language + ConfigurationManager.AppSettings["LinkOk"];
+            LinkOk += "/" + newPayment.IDFaktury; ;
 
             var merchantViewData = InitMerchantViewData(newPayment, hash, merchantId, LinkFail, LinkOk);
+            wyslij(merchantViewData, hash, merchantId);
             return View(merchantViewData);            
         }
@@ -95,5 +101,5 @@
             newPayment.SURNAME = payer.LastName;
             newPayment.AUTODEPOSIT = true;
-            newPayment.LANGUAGE = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToUpper(); //"PL";
+            newPayment.LANGUAGE = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToUpper(); 
             newPayment.CHARSET = KODOWANIE;
             newPayment.COUNTRY = KOD_POLSKA;
@@ -124,9 +130,9 @@
             
             //wartosci testowe
-            merchantViewData.nowaPlatnosc.ORDERNUMBER = 4;
-            merchantViewData.nowaPlatnosc.ORDERDESCRIPTION = "22";
+            merchantViewData.nowaPlatnosc.ORDERNUMBER = ORDERNUMBER;
+            merchantViewData.nowaPlatnosc.ORDERDESCRIPTION = "222";
             merchantViewData.nowaPlatnosc.AMOUNT = 300;
             merchantViewData.nowaPlatnosc.CURRENCY = "985";
-            merchantViewData.nowaPlatnosc.SESSIONID = "";
+            merchantViewData.nowaPlatnosc.SESSIONID = "ff";
             merchantViewData.merchantId = "171485000";
             merchantViewData.LinkFail = "";
@@ -146,5 +152,5 @@
 
             //dane testowe
-            string adres = "https://pay.ecard.pl/servlet/HS?orderNumber=4";
+            string adres = "https://pay.ecard.pl/servlet/HS?orderNumber="+ORDERNUMBER;
             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(adres);
             string dane = "&orderDescription=&amount=300&currency=985&merchantId=171485000&password=ashSeth2";                
@@ -164,5 +170,14 @@
                      
             return strResponse;
-        }               
+        }
+        private void wyslij(MerchantViewData m, string hash, string id)
+        {
+            string adres = "https://pay.ecard.pl/servlet/PSTEST?ORDERDESCRIPTION="+m.nowaPlatnosc.ORDERDESCRIPTION;
+            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(adres);
+            string dane = "&AMOUNT=300&CURRENCY=985&ORDERNUMBER="+ORDERNUMBER+"&NAME="+m.nowaPlatnosc.NAME+"&SURNAME="+m.nowaPlatnosc.SURNAME+"&LANGUAGE=PL&CHARSET=ISO-8859-2";
+            dane += "&COUNTRY=616&PAYMENTTYPE=CARDS&JS=1&HASH=" + hash + "&MERCHANTID=171485000&AUTODEPOSIT=" + m.nowaPlatnosc.AUTODEPOSIT + "&LINKFAIL=";
+            dane += "&LINKOK=&SESSIONID=";
+            Response.Redirect(adres + dane);
+        }
     }
 }
