Exemplo n.º 1
0
        /// <summary>
        /// Joins all request parameters to one string (with UrlEncode)
        /// </summary>
        public string JoinPaymentParameters(PayseraPaymentRequest rq)
        {
            Dictionary <string, string> ar = new Dictionary <string, string>();

            ar["orderid"]     = rq.OrderId;
            ar["amount"]      = (rq.AmountToPay * 100).ToString("#");
            ar["currency"]    = rq.CurrencyCode;
            ar["country"]     = rq.Country.ToString();
            ar["accepturl"]   = rq.AcceptUrl;
            ar["cancelurl"]   = rq.CancelUrl;
            ar["callbackurl"] = rq.CallbackUrl;
            ar["test"]        = rq.IsTestPayment ? "1" : "0";
            ar["payment"]     = rq.RequestedPaymentMehtods;
            ar["p_email"]     = rq.CustomerEmail;
            ar["p_firstname"] = rq.CustomerName;
            ar["p_lastname"]  = rq.CustomerLastName;
            ar["p_phone"]     = rq.CustomerPhone;
            ar["p_comment"]   = rq.Remarks;
            ar["p_ip"]        = rq.Ip;
            ar["p_agent"]     = rq.BrowserAgent;
            ar["p_file"]      = "";
            ar["version"]     = PayseraPaymentRequest.Version;
            ar["projectid"]   = rq.ProjectId;
            ar["paytext"]     = rq.PayText;

            //string[] p = ar.Select(x => String.Concat(x.Key, "=", WebUtility.UrlEncode(x.Value))).ToArray();
            string[] p = ar.Select(x => String.Concat(x.Key, "=", UrlEncode(x.Value))).ToArray();

            return(String.Join("&", p));
        }
Exemplo n.º 2
0
        public void Test_DovanuKuponai_Payment_Link_As_Test()
        {
            var rq = new PayseraPaymentRequest();

            rq.PayseraProjectPassword = PayseraPassword;
            rq.ProjectId = PayseraProjectId;

            rq.OrderId      = Guid.NewGuid().ToString("N");
            rq.AmountToPay  = 0.01m;
            rq.CurrencyCode = "EUR";
            rq.Country      = PayseraPaymentRequest.Countries.LT;

            rq.AcceptUrl   = "http://www.dovanukuponai.com/payment/accept/";
            rq.CancelUrl   = "http://www.dovanukuponai.com/payment/cancel/";
            rq.CallbackUrl = "http://www.dovanukuponai.com/payment/callback/";

            rq.CustomerName     = "Aleksej";
            rq.CustomerLastName = "Vasinov";
            rq.CustomerEmail    = "*****@*****.**";
            rq.CustomerPhone    = "+370 5 2166481";
            rq.Remarks          = "Just test payment";

            rq.PayText = "RitosMasazai.lt [owner_name]. Jusu uzsakymas http://www.dovanukuponai.com/gift/get/[order_nr]";

            Uri paymentLink = _psBll.PreparePaymentLink(_psPaymentUrl, rq);

            // To get exception and see result :)
            Assert.AreEqual("-", paymentLink.AbsoluteUri);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Throws exception when any of mandatory fields is absent
        /// </summary>
        public void ValidatePaymentRequest(PayseraPaymentRequest rq)
        {
            if (String.IsNullOrEmpty(rq.ProjectId))
            {
                throw new ArgumentNullException("ProjectId");
            }

            if (String.IsNullOrEmpty(rq.OrderId))
            {
                throw new ArgumentNullException("OrderId");
            }

            if (rq.AcceptUrl == null)
            {
                throw new ArgumentNullException("AcceptUrl");
            }

            if (rq.CancelUrl == null)
            {
                throw new ArgumentNullException("CancelUrl");
            }

            if (rq.CallbackUrl == null)
            {
                throw new ArgumentNullException("CallbackUrl");
            }

            //if (String.IsNullOrEmpty(rq.Version))
            //{
            //    throw new ArgumentNullException("Version");
            //}
        }
Exemplo n.º 4
0
        public void Test_Check_Prepared_Payment_Sign1()
        {
            string goodSign1 = "524b0c22694888382a9698ee18a8c429";

            var rq = new PayseraPaymentRequest();

            rq.PayseraProjectPassword = "******";

            rq.OrderId                 = "0";
            rq.AmountToPay             = 123.45m;
            rq.CurrencyCode            = "EUR";
            rq.Country                 = PayseraPaymentRequest.Countries.LT;
            rq.AcceptUrl               = "/accept.php";
            rq.CancelUrl               = "/cancel.php";
            rq.CallbackUrl             = "/callback.php";
            rq.IsTestPayment           = false;
            rq.RequestedPaymentMehtods = "payment";
            rq.CustomerEmail           = "email";
            rq.CustomerName            = "firstname";
            rq.CustomerLastName        = "lastname";
            rq.CustomerPhone           = "phone";
            rq.Remarks                 = "comment";

            rq.Ip           = "::1";
            rq.BrowserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0";

            rq.File      = "";
            rq.ProjectId = "73097";

            string data = "b3JkZXJpZD0wJmFtb3VudD0xMjM0NSZjdXJyZW5jeT1FVVImY291bnRyeT1MVCZhY2NlcHR1cmw9JTJGYWNjZXB0LnBocCZjYW5jZWx1cmw9JTJGY2FuY2VsLnBocCZjYWxsYmFja3VybD0lMkZjYWxsYmFjay5waHAmdGVzdD0wJnBheW1lbnQ9cGF5bWVudCZwX2VtYWlsPWVtYWlsJnBfZmlyc3RuYW1lPWZpcnN0bmFtZSZwX2xhc3RuYW1lPWxhc3RuYW1lJnBfcGhvbmU9cGhvbmUmcF9jb21tZW50PWNvbW1lbnQmcF9pcD0lM0ElM0ExJnBfYWdlbnQ9TW96aWxsYSUyRjUuMCslMjhXaW5kb3dzK05UKzEwLjAlM0IrV09XNjQlM0IrcnYlM0E0Mi4wJTI5K0dlY2tvJTJGMjAxMDAxMDErRmlyZWZveCUyRjQyLjAmcF9maWxlPSZ2ZXJzaW9uPTEuNiZwcm9qZWN0aWQ9NzMwOTc=";

            string sign1 = _psBll.GenerateSs1(data, rq.PayseraProjectPassword);

            Assert.AreEqual(goodSign1, sign1);
        }
Exemplo n.º 5
0
 private bool WasExceptionForProperty(PayseraPaymentRequest rq, string propertyName)
 {
     try
     {
         _psBll.ValidatePaymentRequest(rq);
     }
     catch (ArgumentNullException anex)
     {
         return(anex.ParamName == propertyName);
     }
     return(false);
 }
Exemplo n.º 6
0
        public Uri PreparePaymentLink(Uri payserPaymentUrl, PayseraPaymentRequest rq)
        {
            Logger.Info("Preparing payment link for Payser");
            ValidatePaymentRequest(rq);

            string data = EncodeString(JoinPaymentParameters(rq));

            Logger.Info("  data=" + data);

            string ss1Sign = GenerateSs1(data, rq.PayseraProjectPassword);

            Logger.Info("  ss1: " + ss1Sign);

            // Need to convert '=' to "%3D" (Paysera)
            data.Replace("=", "%3D");
            return(new Uri(payserPaymentUrl, String.Concat("?data=", data, "&sign=", ss1Sign)));
        }
Exemplo n.º 7
0
        public void Init()
        {
            _rqValid = new PayseraPaymentRequest();

            _rqValid.PayseraProjectPassword = "******";

            _rqValid.ProjectId = "666";
            _rqValid.OrderId   = Guid.NewGuid().ToString("N");

            _rqValid.AcceptUrl   = "http://localhost:56620/Ok/";
            _rqValid.CallbackUrl = "http://localhost:56620/Callback/";
            _rqValid.CancelUrl   = "http://localhost:56620/Cancel/";

            //_rqValid.Language = PayseraPaymentRequest.Languages.LIT;

            //_rqValid.AmountToPay = 123.45m;
            //_rqValid.CurrencyCode = "EUR";
        }
Exemplo n.º 8
0
        public void Test_DovanuKuponai_Payment_Link_By_WebToPay()
        {
            string goodData = "b3JkZXJpZD0xMjM0NTY3ODkwJmFtb3VudD0xMjM0NSZjdXJyZW5jeT1FVVImY291bnRyeT1MVCZhY2NlcHR1cmw9aHR0cCUzQSUyRiUyRnd3dy5kb3ZhbnVrdXBvbmFpLmNvbSUyRnBheW1lbnQlMkZhY2NlcHQlMkYmY2FuY2VsdXJsPWh0dHAlM0ElMkYlMkZ3d3cuZG92YW51a3Vwb25haS5jb20lMkZwYXltZW50JTJGY2FuY2VsJmNhbGxiYWNrdXJsPWh0dHAlM0ElMkYlMkZ3d3cuZG92YW51a3Vwb25haS5jb20lMkZwYXltZW50JTJGY2FsbGJhY2smdGVzdD0xJnBheW1lbnQ9cGF5bWVudCZwX2VtYWlsPWl0JTQwaW50ZXJhdGVpdGlzLmx0JnBfZmlyc3RuYW1lPVRlc3QmcF9sYXN0bmFtZT1JQSZwX3Bob25lPSUyQjM3MCs2MDArMTIzNDUmcF9jb21tZW50PWNvbW1lbnQmcF9pcD0lM0ElM0ExJnBfYWdlbnQ9TW96aWxsYSUyRjUuMCslMjhXaW5kb3dzK05UKzEwLjAlM0IrV09XNjQlM0IrcnYlM0E0Mi4wJTI5K0dlY2tvJTJGMjAxMDAxMDErRmlyZWZveCUyRjQyLjAmcF9maWxlPSZ2ZXJzaW9uPTEuNiZwcm9qZWN0aWQ9NzY0NTc=";
            string goodSign = "78f862fcddbc175a55dd5651410a7df1";

            var rq = new PayseraPaymentRequest();

            rq.PayseraProjectPassword = PayseraPassword;
            rq.ProjectId = PayseraProjectId;

            rq.OrderId      = "1234567890";
            rq.AmountToPay  = 123.45m;
            rq.CurrencyCode = "EUR";
            rq.Country      = PayseraPaymentRequest.Countries.LT;

            rq.AcceptUrl   = "http://www.dovanukuponai.com/payment/accept/";
            rq.CancelUrl   = "http://www.dovanukuponai.com/payment/cancel";
            rq.CallbackUrl = "http://www.dovanukuponai.com/payment/callback";

            rq.IsTestPayment           = true;
            rq.RequestedPaymentMehtods = "payment";

            rq.CustomerEmail    = "*****@*****.**";
            rq.CustomerName     = "Test";
            rq.CustomerLastName = "IA";
            rq.CustomerPhone    = "+370 600 12345";
            rq.Remarks          = "comment";

            rq.Ip           = "::1";
            rq.BrowserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0";
            rq.File         = ".";

            string data = _psBll.EncodeString(_psBll.JoinPaymentParameters(rq));

            Assert.AreEqual(goodData, data);
            string sign1 = _psBll.GenerateSs1(data, rq.PayseraProjectPassword);

            Assert.AreEqual(goodSign, sign1);

            Uri paymentUrl = _psBll.PreparePaymentLink(new Uri("https://www.mokejimai.lt/pay/"), rq);
        }
Exemplo n.º 9
0
        public ActionResult Checkout(string id, ProductCheckoutModel checkout)
        {
            try
            {
                var posResponse = Session["__Product"] as PaymentRequestValidationResponse;
                if (posResponse == null)
                {
                    throw new ArgumentNullException("No product information from POS in session");
                }

                if (checkout.LocationId < 1)
                {
                    ModelState.AddModelError("LocationId", Resources.Language.Payment_Checkout_ChooseLocation);
                }
                if (ModelState.IsValid == false)
                {
                    checkout.ProductName = posResponse.ProductName;
                    checkout.ProductDescription = posResponse.ProductDescription;
                    checkout.ProductDuration = posResponse.ProductDuration;
                    checkout.PosUserUid = id;
                    checkout.ProductValidTill = Factory.HelperBll.ConvertFromUnixTimestamp(posResponse.ProductValidTillTm);
                    checkout.RequestedAmount = posResponse.RequestedAmountMinor / 100m;
                    checkout.Locations = posResponse.Locations ?? new List<ProductServiceLocation>();
                    return View("Checkout", GetLayoutForPos(posResponse.PosId), checkout);
                }

                var product = Factory.GiftsBll.SaveProductInformationFromPos(id, posResponse, checkout);
                var transaction = Factory.TransactionsBll.StartTransaction(id, product);

                var configuration = Factory.ConfigurationBll.Get();

                //Factory.CommunicationBll.SendEmailToClientOnSuccess(product);
                var rq = new PayseraPaymentRequest();

                // Paysera information is stored in POS
                var pos = Factory.PosBll.GetById(posResponse.PosId);
                rq.ProjectId = pos.PayseraPayerId;
                rq.PayseraProjectPassword = pos.PayseraPassword;
                Logger.DebugFormat("  configuring Paysera payment to use payer ID: {0} for POS ID: {1}", rq.ProjectId, pos.Id);

                //rq.OrderId = transaction.PaySystemUid;
                rq.OrderId = transaction.OrderNr;
                rq.AmountToPay = posResponse.RequestedAmountMinor / 100m;
                rq.CurrencyCode = posResponse.CurrencyCode;
                rq.Country = PayseraPaymentRequest.Countries.LT;

                rq.AcceptUrl = Url.Action("accept", "payment", null, Request.Url.Scheme);
                rq.CancelUrl = Url.Action("cancel", "payment", null, Request.Url.Scheme);
                rq.CallbackUrl = Url.Action("callback", "payment", null, Request.Url.Scheme);

                rq.CustomerName = checkout.CustomerName;
                rq.CustomerEmail = checkout.CustomerEmail;
                rq.CustomerPhone = checkout.CustomerPhone;

                rq.PayText = Factory.PosBll.FormatNoteForPayment(pos, product, configuration.MaxLengthOfPayseraNote);
                Logger.Debug("  sending PayText: " + rq.PayText);

                //rq.Language = PayseraPaymentRequest.Languages.LIT;
                //rq.IsTestPayment = configuration.UseTestPayment;
                rq.IsTestPayment = pos.UseTestPayment;
                Logger.InfoFormat("  use test payment for POS #{0}: {1}", pos.Id, pos.UseTestPayment);

                Uri paymentUri = Factory.PayseraBll.PreparePaymentLink(configuration.PayseraPaymentUrl, rq);
                Logger.Info("Redirecting to Paysera:");
                Logger.Info(paymentUri.ToString());

                Logger.InfoFormat("  saving payment order nr in session in case of cancel: `{0}`", rq.OrderId);
                //Session["__PaySystemUid"] = rq.OrderId;
                SessionStore.PaymentOrderNr = rq.OrderId;

                return Redirect(paymentUri.ToString());

            }
            catch (Exception ex)
            {
                Logger.Error("Error processing payment form", ex);
                return Incorrect();
            }
        }