private async Task SyncWebhook(WebhookConfiguration webhook) { try { var mobilePayWebhook = await _mobilePayWebhooksService.GetWebhook(webhook.Id); if (!mobilePayWebhook.Url.Equals(_mobilePaySettings.WebhookUrl, StringComparison.OrdinalIgnoreCase)) { await DisableAndRegisterNewWebhook(webhook); } webhook.Url = mobilePayWebhook.Url; webhook.SignatureKey = mobilePayWebhook.SignatureKey; webhook.Status = WebhookStatus.Active; webhook.LastUpdated = DateTime.UtcNow; await _context.SaveChangesAsync(); _signatureKey = mobilePayWebhook.SignatureKey; } catch (EntityNotFoundException) { await DisableAndRegisterNewWebhook(webhook); } }
private async Task DisableAndRegisterNewWebhook(WebhookConfiguration webhook) { webhook.Status = WebhookStatus.Disabled; await _context.SaveChangesAsync(); await RegisterWebhook(); }
private static void WebhookServerInitialization(IApplicationBuilder app, IConsumerOnlyCredentials consumerOnlyCredentials) { Plugins.Add <WebhooksPlugin>(); WebhookConfiguration = new WebhookConfiguration(consumerOnlyCredentials); app.UseTweetinviWebhooks(WebhookConfiguration); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); //app.UseExceptionHandler("/Home/Error"); //app.UseHsts(); } context.Database.Migrate(); app.UseStaticFiles(); app.UseCookiePolicy(); app.Use((httpContext, next) => { httpContext.Request.Scheme = "https"; return(next()); }); app.UseAuthentication(); //app.UseHttpsRedirection(); Plugins.Add <WebhooksPlugin>(); var consumerToken = Configuration["Authentication:Twitter:ConsumerKey"]; var consumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"]; var accessToken = Configuration["Authentication:Twitter:AccessToken"]; var accessTokenSecret = Configuration["Authentication:Twitter:AccessTokenSecret"]; var appCreds = Auth.SetApplicationOnlyCredentials(consumerToken, consumerSecret, true); WebhookConfiguration = new WebhookConfiguration(new ConsumerOnlyCredentials(consumerToken, consumerSecret) { ApplicationOnlyBearerToken = appCreds.ApplicationOnlyBearerToken }); app.UseTweetinviWebhooks(WebhookConfiguration); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
private async Task RegisterWebhook() { var mobilePayWebhook = await _mobilePayWebhooksService.RegisterWebhook(_mobilePaySettings.WebhookUrl, DefaultEvents); var webhook = new WebhookConfiguration { Id = mobilePayWebhook.WebhookId, Url = mobilePayWebhook.Url, SignatureKey = mobilePayWebhook.SignatureKey, Status = WebhookStatus.Active, LastUpdated = DateTime.UtcNow }; await _context.WebhookConfigurations.AddAsync(webhook); await _context.SaveChangesAsync(); _signatureKey = mobilePayWebhook.SignatureKey; }