Ejemplo n.º 1
0
 public static string GeneratePublishableKey(string userId, bool isTest)
 {
     var newKey = GenerateRandomKey();
     var secretKey = new PublishableKey
     {
         UserId = userId,
         CreatedDate = DateTime.UtcNow,
         IsTest = isTest,
         Value = newKey
     };
     using (var db = new DBEntities())
     {
         db.PublishableKeys.Add(secretKey);
         db.SaveChanges();
     }
     return FormatTHeKey("pk_", isTest, newKey);
 }
Ejemplo n.º 2
0
 private static void AddNewPublishableKey(string key, string userId, bool isTestMode)
 {
     var publishableKey = new PublishableKey
     {
         UserId = userId,
         CreatedDate = DateTime.UtcNow,
         IsTest = isTestMode,
         Value = key
     };
     using (var db = new DBEntities())
     {
         var activePublishableKey = db.PublishableKeys.Where(pk => pk.UserId == userId && !pk.IsRevoked && pk.IsTest == isTestMode).FirstOrDefault();
         if (activePublishableKey != null)
         {
             activePublishableKey.IsRevoked = true;
             activePublishableKey.RevokedDate = DateTime.UtcNow;
         }
         db.PublishableKeys.Add(publishableKey);
         db.SaveChanges();
     }
 }