public static string Signature(this GetPaymentAttemptRequest parameters)
        {
            //------------------------ TEST ---------------------------------------------------------
            // проверка
            //using (var md5 = MD5.Create())
            //{
            //    var shopID = md5.ComputeHash(Encoding.UTF8.GetBytes(parameters.ShopID));
            //    var orderID = md5.ComputeHash(Encoding.UTF8.GetBytes(parameters.OrderID));
            //    var password = md5.ComputeHash(Encoding.UTF8.GetBytes(parameters.Password));

            //    Console.WriteLine($"ShopID={Byte2HexString(shopID)}");
            //    Console.WriteLine($"OrderID={Byte2HexString(orderID)}");
            //    Console.WriteLine($"Password={Byte2HexString(password)}");
            //}
            //---------------------------------------------------------------------------------------

            using (var md5 = MD5.Create())
            {
                var parts = parameters.GetParts()
                            .Select(p => p.SignPart(md5))
                            .ToArray();

                //var signature = string.Join("&", parts).Sign(md5).ToUpper();
                var signature = string.Concat(parts).Sign(md5).ToUpper();
                return(signature);
            }
        }
        private static IEnumerable <KeyValuePair <string, string> > ToKeyValuePairs(GetPaymentAttemptRequest original)
        {
            yield return(new KeyValuePair <string, string>("ShopID", original.ShopID));

            yield return(new KeyValuePair <string, string>("OrderID", original.OrderID));

            yield return(new KeyValuePair <string, string>("Signature", original.Signature));
        }
        private static IEnumerable <string> GetParts(this GetPaymentAttemptRequest parameters)
        {
            // Shop_IDP
            yield return(parameters.ShopID);

            // Order_IDP
            yield return(parameters.OrderID);

            // password
            yield return(parameters.Password);
        }
Esempio n. 4
0
        public string GetPaymentAttempt(ref FiscalizationData fiscal)
        {
            try
            {
                var getPaymentAttemptRequest = new GetPaymentAttemptRequest
                {
                    ShopID   = fiscal.ShopID,
                    OrderID  = fiscal.OrderID,
                    Password = _password
                };

                var signature = getPaymentAttemptRequest.Signature();
                getPaymentAttemptRequest.Signature = signature;

                var requestContent    = RequestFormedHelper.ToFormUrlEncodedContent(getPaymentAttemptRequest);
                var responseXmlString = GetResponse(unitellerCheckUrl, requestContent);
                var response          = DeserializeXml <XmlResponse>(responseXmlString);

                if (response == null ||
                    !string.Equals(response.Result, "0") ||
                    response.PaymentAttemptID == null)
                {
                    var errorMessage = (response == null || string.IsNullOrEmpty(response.ErrorMessage)) ? "GetPaymentAttemptError" : response.ErrorMessage;
                    logger.Error($"UnitellerProcessor.CreateFiscalCheck ShopId = {fiscal.ShopID}, OrderID = {fiscal.OrderID}, СustomerId = {fiscal.СustomerId}, " +
                                 $"Error = {errorMessage}");
                    fiscal.ErrorMessage = errorMessage;
                    return(string.Empty);
                }

                return(response.PaymentAttemptID);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"UnitellerProcessor.GetPaymentAttempt Exception ShopId = {fiscal.ShopID}, OrderID = {fiscal.OrderID} ");
                fiscal.ErrorMessage = ex.Message;
                return(string.Empty);
            }
        }
 public static FormUrlEncodedContent ToFormUrlEncodedContent(GetPaymentAttemptRequest original)
 {
     return(new FormUrlEncodedContent(ToKeyValuePairs(original)));
 }