Implemented a basic stripe interation
This commit is contained in:
parent
80ea5a543f
commit
244e87ed18
3 changed files with 52 additions and 6 deletions
|
@ -21,6 +21,17 @@ public class BillingController : Controller
|
|||
BillingService = billingService;
|
||||
}
|
||||
|
||||
[HttpGet("cancel")]
|
||||
public async Task<ActionResult> Cancel()
|
||||
{
|
||||
var user = await IdentityService.Get();
|
||||
|
||||
if (user == null)
|
||||
return Redirect("/login");
|
||||
|
||||
return Redirect("/profile/subscriptions/close");
|
||||
}
|
||||
|
||||
[HttpGet("success")]
|
||||
public async Task<ActionResult> Success()
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@ public class DiscordNotificationService
|
|||
Event.On<SupportChatMessage>("supportChat.message", this, OnSupportChatMessage);
|
||||
Event.On<User>("supportChat.close", this, OnSupportChatClose);
|
||||
Event.On<User>("user.rating", this, OnUserRated);
|
||||
Event.On<User>("billing.completed", this, OnBillingCompleted);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -42,6 +43,21 @@ public class DiscordNotificationService
|
|||
}
|
||||
}
|
||||
|
||||
private async Task OnBillingCompleted(User user)
|
||||
{
|
||||
await SendNotification("", builder =>
|
||||
{
|
||||
builder.Color = Color.Red;
|
||||
builder.Title = "New payment received";
|
||||
|
||||
builder.AddField("User", user.Email);
|
||||
builder.AddField("Firstname", user.FirstName);
|
||||
builder.AddField("Lastname", user.LastName);
|
||||
builder.AddField("Amount", user.CurrentSubscription!.Price);
|
||||
builder.AddField("Currency", user.CurrentSubscription!.Currency);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task OnUserRated(User user)
|
||||
{
|
||||
await SendNotification("", builder =>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using Moonlight.App.Database.Entities;
|
||||
using System.Globalization;
|
||||
using Moonlight.App.Database.Entities;
|
||||
using Moonlight.App.Events;
|
||||
using Moonlight.App.Exceptions;
|
||||
using Moonlight.App.Repositories;
|
||||
using Moonlight.App.Services.Mail;
|
||||
using Moonlight.App.Services.Sessions;
|
||||
using Stripe.Checkout;
|
||||
using Subscription = Moonlight.App.Database.Entities.Subscription;
|
||||
|
@ -15,19 +17,22 @@ public class BillingService
|
|||
private readonly Repository<Subscription> SubscriptionRepository;
|
||||
private readonly SessionServerService SessionServerService;
|
||||
private readonly EventSystem Event;
|
||||
private readonly MailService MailService;
|
||||
|
||||
public BillingService(
|
||||
ConfigService configService,
|
||||
SubscriptionService subscriptionService,
|
||||
Repository<Subscription> subscriptionRepository,
|
||||
EventSystem eventSystem,
|
||||
SessionServerService sessionServerService)
|
||||
SessionServerService sessionServerService,
|
||||
MailService mailService)
|
||||
{
|
||||
ConfigService = configService;
|
||||
SubscriptionService = subscriptionService;
|
||||
SubscriptionRepository = subscriptionRepository;
|
||||
Event = eventSystem;
|
||||
SessionServerService = sessionServerService;
|
||||
MailService = mailService;
|
||||
}
|
||||
|
||||
public async Task<string> StartCheckout(User user, Subscription subscription)
|
||||
|
@ -97,12 +102,26 @@ public class BillingService
|
|||
if (subscription == null)
|
||||
throw new DisplayException("No subscription for this product found");
|
||||
|
||||
if (await SubscriptionService.GetActiveSubscription(user) != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// if (await SubscriptionService.GetActiveSubscription(user) != null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
await SubscriptionService.SetActiveSubscription(user, subscription);
|
||||
|
||||
await MailService.SendMail(user, "checkoutComplete", values =>
|
||||
{
|
||||
values.Add("SubscriptionName", subscription.Name);
|
||||
values.Add("SubscriptionPrice", subscription.Price
|
||||
.ToString(CultureInfo.InvariantCulture));
|
||||
values.Add("SubscriptionCurrency", subscription.Currency
|
||||
.ToString());
|
||||
values.Add("SubscriptionDuration", subscription.Duration
|
||||
.ToString(CultureInfo.InvariantCulture));
|
||||
});
|
||||
|
||||
await Event.Emit("billing.completed", user);
|
||||
|
||||
await SessionServerService.ReloadUserSessions(user);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue