Exemplo n.º 1
0
        private string CreateQueryParameters()
        {
            var token = new ExpressTokenRequest();

            token.ApiKey              = "bc8882c4f6540769b33f809bcb98a839";
            token.RequestDateTime     = DateTime.Now.ToString("yyyy-MM-ddTHH\\:mm\\:ss");
            token.CurrencyCode        = "PEN";
            token.Amount              = decimal.Round(12.00M, 2, MidpointRounding.AwayFromZero);
            token.MerchantSalesID     = "1";
            token.Language            = "ES";
            token.TrackingCode        = "22";
            token.ExpirationTime      = 1440;
            token.TransactionOkURL    = "https://www.website.com/thanks";
            token.TransactionErrorURL = "https://flippingbook.com/404";
            token.CustomMerchantName  = "My Store";
            token.ShopperEmail        = "*****@*****.**";
            token.ProductID           = 8;
            //token.FilterBy = "";
            token.ShopperInformation_email        = "*****@*****.**";
            token.ShopperInformation_first_name   = "Pedro";
            token.ShopperInformation_last_name    = "Curich";
            token.ShopperInformation_country_code = "+51";       //_genericAttributeService.GetAttribute<string>(customer, NopCustomerDefaults.PhoneAttribute);
            token.ShopperInformation_mobile       = "973905013"; //_genericAttributeService.GetAttribute<string>(customer, NopCustomerDefaults.PhoneAttribute);
            token.ResponseFormat = "XML";
            token.Signature      = Helper.ComputeSha256Hash(token, "eb4d9032a344ad1b0b8099e484b8519c");

            var root = new
            {
                ExpressTokenRequest = token
            };

            return(JsonConvert.SerializeObject(token));
        }
Exemplo n.º 2
0
        public static string ComputeSha256Hash(ExpressTokenRequest token, string signatureKey)
        {
            var rawData = token.RequestDateTime
                          + token.CurrencyCode
                          + token.Amount
                          + token.MerchantSalesID
                          + token.Language
                          + token.TrackingCode
                          + token.ExpirationTime
                          + token.TransactionOkURL
                          + token.TransactionErrorURL
                          + signatureKey;

            // Create a SHA256
            using (var sha256Hash = SHA256.Create())
            {
                // ComputeHash - returns byte array
                byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));

                // Convert byte array to a string
                var builder = new StringBuilder();
                for (var i = 0; i < bytes.Length; i++)
                {
                    builder.Append(bytes[i].ToString("x2"));
                }
                return(builder.ToString());
            }
        }