private static StripeWebhookEventsLogTableEntity GetWebhookEvent(string eventId) { CloudTableClient cloudTableClient = Sahara.Core.Settings.Azure.Storage.StorageConnections.PlatformStorage.CreateCloudTableClient(); //Create and set retry policy //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4); IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 3); cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy; CloudTable cloudTable = cloudTableClient.GetTableReference(StripeWebhookEventsLogTableName); cloudTable.CreateIfNotExists(); TableQuery <StripeWebhookEventsLogTableEntity> query = new TableQuery <StripeWebhookEventsLogTableEntity>() .Where(TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, eventId), TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, eventId) )); StripeWebhookEventsLogTableEntity stripeWebhookEventsLog = cloudTable.ExecuteQuery(query).FirstOrDefault(); return(stripeWebhookEventsLog); }
/* REVISIT FOR PURGE -- * internal static bool ClearStripeWebhookEventsLog(int amountOfDays) * { * * CloudTableClient cloudTableClient = Sahara.Core.Settings.Azure.Storage.StorageConnections.PlatformStorage.CreateCloudTableClient(); * * //Create and set retry policy * //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4); * IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 3); * cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy; * * CloudTable cloudTable = cloudTableClient.GetTableReference(StripeWebhookEventsLogTableName); * * cloudTable.CreateIfNotExists(); * * TableQuery<TableEntity> query = new TableQuery<TableEntity>() * .Where(TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, DateTimeOffset.UtcNow.AddDays(amountOfDays).Date)); * * var stripeWebhookEventsLog = cloudTable.ExecuteQuery(query); * * foreach (var log in stripeWebhookEventsLog) * { * cloudTable.Execute(TableOperation.Delete(log)); * } * * * PlatformLogManager.LogActivity( * CategoryType.StripeEvent, * ActivityType.StripeEvent_IdempotentLogPurged, * "Purge initiated for logs older than " + Math.Abs(amountOfDays) + " days. Resulted in " + stripeWebhookEventsLog.Count() + " purged items.", * stripeWebhookEventsLog.Count() + " logs purged from events over " + Math.Abs(amountOfDays) + " days ago." * ); * * return true; * }*/ internal static bool LogWebhookEvent(string eventId) { var stripeWebhookEventsLog = new StripeWebhookEventsLogTableEntity(eventId); TableOperation operation = TableOperation.Insert((stripeWebhookEventsLog as TableEntity)); try { stripeWebhookEventsLog.cloudTable.Execute(operation); return(true); } catch (Exception e) { //Log exception and email platform admins PlatformExceptionsHelper.LogExceptionAndAlertAdmins( e, "attempting to store stripe webhook event log for idempotency purposes", System.Reflection.MethodBase.GetCurrentMethod() ); return(false); } }