Spaces:
Running
Running
Download FlowAPI.Application/Services/PaymentService.cs from DanilDrotik/FlowAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/DanilDrotik/FlowAPI/resolve/c8301b4e0f289c0e69fa026bb49f7828aec1850d/FlowAPI.Application/Services/PaymentService.cs
- Command line
-
hf download hf://spaces/DanilDrotik/FlowAPI@c8301b4e0f289c0e69fa026bb49f7828aec1850d/FlowAPI.Application/Services/PaymentService.cs
-
curl -L -o PaymentService.cs https://huggingface.co/spaces/DanilDrotik/FlowAPI/resolve/c8301b4e0f289c0e69fa026bb49f7828aec1850d/FlowAPI.Application/Services/PaymentService.cs
1.99 kB
| using FlowAPI.Application.Interfaces; | |
| using FlowAPI.Domain.Entities; | |
| using Microsoft.Extensions.Configuration; | |
| namespace FlowAPI.Application.Services | |
| { | |
| public class PaymentService : IPaymentService | |
| { | |
| private readonly IUserRepository _userRepo; | |
| private readonly IConfiguration _config; | |
| public PaymentService(IUserRepository userRepo, IConfiguration config) | |
| { | |
| _userRepo = userRepo; | |
| _config = config; | |
| } | |
| public async Task<string> CreateCheckoutSessionAsync(Guid userId) | |
| { | |
| // Implementation with Stripe.net: | |
| // var options = new SessionCreateOptions { ... }; | |
| // var service = new SessionService(); | |
| // var session = await service.CreateAsync(options); | |
| // return session.Url; | |
| return "https://checkout.stripe.com/pay/cs_test_placeholder_" + userId; | |
| } | |
| public async Task<bool> HandleWebhookAsync(string payload, string signature) | |
| { | |
| try | |
| { | |
| // In real app, we'd verify the signature: | |
| // var stripeEvent = EventUtility.ConstructEvent(payload, signature, _config["Stripe:WebhookSecret"]); | |
| // if (stripeEvent.Type == Events.CheckoutSessionCompleted) | |
| // { | |
| // var session = stripeEvent.Data.Object as Session; | |
| // var userId = Guid.Parse(session.ClientReferenceId); | |
| // await UpgradeUserToPremium(userId); | |
| // } | |
| return true; | |
| } | |
| catch | |
| { | |
| return false; | |
| } | |
| } | |
| private async Task UpgradeUserToPremium(Guid userId) | |
| { | |
| var user = await _userRepo.GetByIdAsync(userId); | |
| if (user != null) | |
| { | |
| user.IsPremium = true; | |
| await _userRepo.UpdateAsync(user); | |
| } | |
| } | |
| } | |
| } | |