-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33c9b80
commit c006fb7
Showing
20 changed files
with
336 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
Source/Modules/Subscriptions/Web/Server/Controllers/StripeWebhook.cs
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Shared.Modules.Layers.Application.Messaging.Command; | ||
using Shared.Modules.Layers.Features.StripeIntegration; | ||
using Shared.Modules.Layers.Features.StripeIntegration.Commands; | ||
using Shared.Modules.Layers.Features.StripeIntegration.Configuration; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using Stripe; | ||
using System.IO; | ||
using Shared.Features.Server; | ||
|
||
namespace Web.Server.Controllers.Stripe | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class StripeWebhook : BaseController | ||
{ | ||
private readonly StripeOptions stripeOptions; | ||
private readonly ICommandDispatcher commandDispatcher; | ||
public StripeWebhook(IOptions<StripeOptions> stripeOptions, ICommandDispatcher commandDispatcher) | ||
{ | ||
this.stripeOptions = stripeOptions.Value; | ||
this.commandDispatcher = commandDispatcher; | ||
} | ||
|
||
[HttpPost] | ||
[IgnoreAntiforgeryToken] | ||
[AllowAnonymous] | ||
public async Task<IActionResult> Index() | ||
{ | ||
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); | ||
try | ||
{ | ||
var stripeEvent = EventUtility.ParseEvent(json); | ||
var signatureHeader = Request.Headers["Stripe-Signature"]; | ||
stripeEvent = EventUtility.ConstructEvent(json, | ||
signatureHeader, stripeOptions.EndpointSecret); | ||
|
||
//More Events Events.Checkout... | ||
if (stripeEvent.Type == Events.CustomerSubscriptionCreated) | ||
{ | ||
var subscription = stripeEvent.Data.Object as Subscription; | ||
await commandDispatcher.DispatchAsync(new CreateSubscriptionCommand { Subscription = subscription }); | ||
} | ||
else if (stripeEvent.Type == Events.CustomerSubscriptionUpdated) | ||
{ | ||
var subscription = stripeEvent.Data.Object as Subscription; | ||
await commandDispatcher.DispatchAsync(new UpdateSubscriptionCommand { Subscription = subscription }); | ||
} | ||
else if (stripeEvent.Type == Events.CustomerSubscriptionDeleted) | ||
{ | ||
var subscription = stripeEvent.Data.Object as Subscription; | ||
await commandDispatcher.DispatchAsync(new DeleteSubscriptionCommand { Subscription = subscription }); | ||
} | ||
else if (stripeEvent.Type == Events.CustomerSubscriptionTrialWillEnd) | ||
{ | ||
var subscription = stripeEvent.Data.Object as Subscription; | ||
await commandDispatcher.DispatchAsync(new SubscriptionTrialEndedCommand { Subscription = subscription }); | ||
} | ||
return Ok(); | ||
} | ||
catch (StripeException e) | ||
{ | ||
throw new StripeIntegrationException(e.Message); | ||
} | ||
} | ||
} | ||
} |
71 changes: 0 additions & 71 deletions
71
Source/Modules/TenantIdentity/Web/Server/Controllers/IdentityController.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ules/TenantIdentity/Web/Server/Controllers/Infrastructure/IdentityOperationsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Modules.TenantIdentity.Features.DomainFeatures.Tenants.Application.Queries; | ||
using Modules.TenantIdentity.Features.DomainFeatures.Users; | ||
using Modules.TenantIdentity.Features.DomainFeatures.Users.Application.Commands; | ||
using Modules.TenantIdentity.Features.DomainFeatures.Users.Application.Queries; | ||
using Modules.TenantIdentity.Shared.DTOs.IdentityOperations; | ||
using Shared.Features.Server; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Modules.TenantIdentity.Shared.DTOs.Tenant; | ||
using Modules.IdentityModule.Shared; | ||
|
||
namespace Modules.TenantIdentity.Web.Server.Controllers.IdentityOperations | ||
{ | ||
[Route("api/[controller]")] | ||
[Authorize] | ||
[ApiController] | ||
public class IdentityOperationsController : BaseController | ||
{ | ||
private readonly SignInManager<ApplicationUser> signInManager; | ||
|
||
public IdentityOperationsController(SignInManager<ApplicationUser> signInManager, IServiceProvider serviceProvider) : base(serviceProvider) | ||
{ | ||
this.signInManager = signInManager; | ||
} | ||
|
||
[HttpGet] | ||
[AllowAnonymous] | ||
public ActionResult<BFFUserInfoDTO> GetClaimsOfCurrentUser() | ||
{ | ||
if (!User.Identity.IsAuthenticated) | ||
{ | ||
return BFFUserInfoDTO.Anonymous; | ||
} | ||
return new BFFUserInfoDTO() | ||
{ | ||
Claims = User.Claims.Select(claim => new ClaimValueDTO { Type = claim.Type, Value = claim.Value }).ToList() | ||
}; | ||
} | ||
|
||
[HttpGet("selectTenant/{TenantId}")] | ||
public async Task<ActionResult> SetTenantForCurrentUser(Guid tenantId, [FromQuery] string redirectUri) | ||
{ | ||
var user = await queryDispatcher.DispatchAsync<GetUserById, ApplicationUser>(new GetUserById { }); | ||
|
||
var tenantMembershipsOfUserQuery = new GetAllTenantMembershipsOfUser() { UserId = user.Id }; | ||
var tenantMemberships = await queryDispatcher.DispatchAsync<GetAllTenantMembershipsOfUser, List<TenantMembershipDTO>>(tenantMembershipsOfUserQuery); | ||
|
||
if (tenantMemberships.Select(t => t.TenantId).Contains(tenantId)) | ||
{ | ||
var setSelectedTenantForUser = new SetSelectedTenantForUser { }; | ||
await commandDispatcher.DispatchAsync(setSelectedTenantForUser); | ||
await signInManager.RefreshSignInAsync(user); | ||
} | ||
else | ||
{ | ||
throw new Exception(); | ||
} | ||
|
||
return LocalRedirect(redirectUri ?? "/"); | ||
} | ||
|
||
[HttpGet("Logout")] | ||
public async Task<ActionResult> LogoutCurrentUser([FromQuery] string redirectUri) | ||
{ | ||
await signInManager.SignOutAsync(); | ||
return LocalRedirect(redirectUri ?? "/"); | ||
} | ||
} | ||
} |
Oops, something went wrong.