Added endpoint to create a sessionCheckout with stripe
This commit is contained in:
@@ -3,6 +3,7 @@ using Hutopy.Domain.Constants;
|
||||
using Hutopy.Infrastructure.Data;
|
||||
using Hutopy.Infrastructure.Data.Interceptors;
|
||||
using Hutopy.Infrastructure.Identity;
|
||||
using Hutopy.Infrastructure.Stripe;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
@@ -49,6 +50,7 @@ public static class DependencyInjection
|
||||
|
||||
services.AddSingleton(TimeProvider.System);
|
||||
services.AddTransient<IIdentityService, IdentityService>();
|
||||
services.AddTransient<IStripeService, StripeService>();
|
||||
|
||||
services.AddAuthorization(options =>
|
||||
options.AddPolicy(Policies.CanPurge, policy => policy.RequireRole(Roles.Administrator)));
|
||||
|
||||
@@ -4,18 +4,19 @@
|
||||
<AssemblyName>Hutopy.Infrastructure</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
|
||||
<PackageReference Include="Stripe.net" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Application\Application.csproj"/>
|
||||
<ProjectReference Include="..\Application\Application.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
46
src/Infrastructure/Stripe/StripeService.cs
Normal file
46
src/Infrastructure/Stripe/StripeService.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Stripe;
|
||||
using Stripe.Checkout;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
|
||||
|
||||
namespace Hutopy.Infrastructure.Stripe;
|
||||
|
||||
public class StripeService : IStripeService
|
||||
{
|
||||
public StripeService()
|
||||
{
|
||||
// I removed the key to push. Will need to be in config.
|
||||
StripeConfiguration.ApiKey = "";
|
||||
}
|
||||
|
||||
public async Task<string> CreateCheckoutSession(int price, string currency = "cad")
|
||||
{
|
||||
var options = new SessionCreateOptions
|
||||
{
|
||||
LineItems = new List<SessionLineItemOptions>
|
||||
{
|
||||
new SessionLineItemOptions
|
||||
{
|
||||
PriceData = new SessionLineItemPriceDataOptions
|
||||
{
|
||||
UnitAmount = price,
|
||||
Currency = currency,
|
||||
ProductData = new SessionLineItemPriceDataProductDataOptions
|
||||
{
|
||||
Name = "Tip",
|
||||
},
|
||||
},
|
||||
Quantity = 1,
|
||||
},
|
||||
},
|
||||
Mode = "payment",
|
||||
UiMode = "embedded",
|
||||
ReturnUrl = "http://localhost:5174",
|
||||
};
|
||||
|
||||
var service = new SessionService();
|
||||
Session session = await service.CreateAsync(options);
|
||||
|
||||
return session.ClientSecret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user