/// <summary> /// Unsubscribed the asynchronous. /// </summary> /// <param name="payload">The payload.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task UnsubscribedAsync(WebhookPayload payload) { var oldValue = this.subscriptionService.GetSubscriptionsBySubscriptionId(payload.SubscriptionId); this.subscriptionService.UpdateStateOfSubscription(payload.SubscriptionId, SubscriptionStatusEnumExtension.Unsubscribed.ToString(), false); this.applicationLogService.AddApplicationLog("Offer Successfully UnSubscribed."); if (oldValue != null) { SubscriptionAuditLogs auditLog = new SubscriptionAuditLogs() { Attribute = Convert.ToString(SubscriptionLogAttributes.Status), SubscriptionId = oldValue.SubscribeId, NewValue = Convert.ToString(SubscriptionStatusEnum.Unsubscribed), OldValue = Convert.ToString(oldValue.SaasSubscriptionStatus), CreateBy = null, CreateDate = DateTime.Now, }; this.subscriptionsLogRepository.Save(auditLog); } this.notificationStatusHandlers.Process(payload.SubscriptionId); await Task.CompletedTask; }
/// <summary> /// Processes the webhook notification asynchronous. /// </summary> /// <param name="payload">The payload.</param> /// <returns> Notification.</returns> public async Task ProcessWebhookNotificationAsync(WebhookPayload payload) { switch (payload.Action) { case WebhookAction.Unsubscribe: await this.webhookHandler.UnsubscribedAsync(payload).ConfigureAwait(false); break; case WebhookAction.ChangePlan: await this.webhookHandler.ChangePlanAsync(payload).ConfigureAwait(false); break; case WebhookAction.ChangeQuantity: await this.webhookHandler.ChangeQuantityAsync(payload).ConfigureAwait(false); break; case WebhookAction.Suspend: await this.webhookHandler.SuspendedAsync(payload).ConfigureAwait(false); break; case WebhookAction.Reinstate: await this.webhookHandler.ReinstatedAsync(payload).ConfigureAwait(false); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Reinstated is followed by Suspend. /// This is called when customer fixed their billing issues and partner can choose to reinstate the suspened subscription to subscribed. /// And resume the software access to the customer. /// </summary> /// <param name="payload">The payload.</param> /// <returns> Exception.</returns> /// <exception cref="NotImplementedException"> Not Implemented Exception. </exception> public async Task ReinstatedAsync(WebhookPayload payload) { var oldValue = this.subscriptionService.GetSubscriptionsBySubscriptionId(payload.SubscriptionId); SubscriptionAuditLogs auditLog = new SubscriptionAuditLogs() { Attribute = Convert.ToString(SubscriptionLogAttributes.Status), SubscriptionId = oldValue?.SubscribeId, OldValue = Convert.ToString(oldValue?.SubscriptionStatus), CreateBy = null, CreateDate = DateTime.Now, }; //gets the user setting from appconfig, if key doesnt exist, add to control the behavior. //_acceptSubscriptionUpdates should be true and subscription should be in db to accept subscription updates var _acceptSubscriptionUpdates = Convert.ToBoolean(this.applicationConfigRepository.GetValueByName(AcceptSubscriptionUpdates)); if (_acceptSubscriptionUpdates && oldValue != null) { this.subscriptionService.UpdateStateOfSubscription(payload.SubscriptionId, SubscriptionStatusEnumExtension.Subscribed.ToString(), false); await this.applicationLogService.AddApplicationLog("Reinstated Successfully.").ConfigureAwait(false); auditLog.NewValue = Convert.ToString(SubscriptionStatusEnum.Subscribed); } else { var patchOperation = await fulfillApiService.PatchOperationStatusResultAsync(payload.SubscriptionId, payload.OperationId, SaaS.Models.UpdateOperationStatusEnum.Failure); if (patchOperation != null && patchOperation.Status != 200) { await this.applicationLogService.AddApplicationLog($"Reinstate operation PATCH failed with status statuscode {patchOperation.Status} {patchOperation.ReasonPhrase}.").ConfigureAwait(false); //partner trying to fail update operation from customer but PATCH on operation didnt succeced, hence throwing an error throw new Exception(patchOperation.ReasonPhrase); } await this.applicationLogService.AddApplicationLog("Reinstate Change Request Rejected Successfully.").ConfigureAwait(false); auditLog.NewValue = Convert.ToString(oldValue?.SubscriptionStatus); } this.subscriptionsLogRepository.Save(auditLog); await Task.CompletedTask; }
/// <summary> /// Changes the plan asynchronous. /// </summary> /// <param name="payload">The payload.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task ChangePlanAsync(WebhookPayload payload) { var oldValue = this.subscriptionService.GetSubscriptionsBySubscriptionId(payload.SubscriptionId); this.subscriptionService.UpdateSubscriptionPlan(payload.SubscriptionId, payload.PlanId); this.applicationLogService.AddApplicationLog("Plan Successfully Changed."); if (oldValue != null) { SubscriptionAuditLogs auditLog = new SubscriptionAuditLogs() { Attribute = Convert.ToString(SubscriptionLogAttributes.Plan), SubscriptionId = oldValue.SubscribeId, NewValue = payload.PlanId, OldValue = oldValue.PlanId, CreateBy = null, CreateDate = DateTime.Now, }; this.subscriptionsLogRepository.Save(auditLog); } await Task.CompletedTask; }
/// <summary> /// Suspended the asynchronous. /// </summary> /// <param name="payload">The payload.</param> /// <returns> Exception.</returns> /// <exception cref="NotImplementedException"> Implemented Exception.</exception> public Task SuspendedAsync(WebhookPayload payload) { throw new NotImplementedException(); }
/// <summary> /// Reinstated the asynchronous. /// </summary> /// <param name="payload">The payload.</param> /// <returns> Exception.</returns> /// <exception cref="NotImplementedException"> Not Implemented Exception. </exception> public Task ReinstatedAsync(WebhookPayload payload) { throw new NotImplementedException(); }
/// <summary> /// Changes the quantity asynchronous. /// </summary> /// <param name="payload">The payload.</param> /// <returns> /// Change QuantityAsync. /// </returns> /// <exception cref="NotImplementedException"> Exception.</exception> public Task ChangeQuantityAsync(WebhookPayload payload) { throw new NotImplementedException(); }
/// <summary> /// Report unknow action from the webhook the asynchronous. /// </summary> /// <param name="payload">The payload.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task UnknownActionAsync(WebhookPayload payload) { await this.applicationLogService.AddApplicationLog("Offer Received an unknow action: " + payload.Action).ConfigureAwait(false); await Task.CompletedTask; }