From 6aafb1d067def868b7a34a3b1961e4fe2e159a2d Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro Date: Thu, 21 Aug 2025 22:00:56 -0300 Subject: [PATCH] feat: ajustes de pagamento e account/logoff --- Controllers/PagamentoController.cs | 59 ++++++++++++-- Resources/SharedResource.pt-BR.resx | 2 +- Services/StripeService.cs | 4 +- Views/Account/Profile.cshtml | 8 +- Views/Pagamento/SelecaoPlano.cshtml | 114 +++++++++++++++++++++++++++- 5 files changed, 171 insertions(+), 16 deletions(-) diff --git a/Controllers/PagamentoController.cs b/Controllers/PagamentoController.cs index 75f74e7..bbb214d 100644 --- a/Controllers/PagamentoController.cs +++ b/Controllers/PagamentoController.cs @@ -17,6 +17,7 @@ namespace QRRapidoApp.Controllers private readonly IUserService _userService; private readonly StripeService _stripeService; private readonly ILogger _logger; + private readonly List languages = new List { "pt-BR", "es-PY", "es" }; public PagamentoController(IPlanService planService, IUserService userService, StripeService stripeService, ILogger logger, AdDisplayService adDisplayService) { @@ -31,7 +32,7 @@ namespace QRRapidoApp.Controllers public async Task SelecaoPlano() { var plans = await _planService.GetActivePlansAsync(); - var countryCode = GetUserCountryCode(); // Implement this method based on your needs + var countryCode = GetUserCountryCodeComplete(); // Implement this method based on your needs _adDisplayService.SetViewBagAds(ViewBag); var model = new SelecaoPlanoViewModel @@ -44,7 +45,7 @@ namespace QRRapidoApp.Controllers } [HttpPost] - public async Task CreateCheckout(string planId) + public async Task CreateCheckout(string planId, string lang) { var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrEmpty(userId)) @@ -59,13 +60,18 @@ namespace QRRapidoApp.Controllers } var countryCode = GetUserCountryCode(); + if (countryCode != lang && languages.Contains(lang)) + { + countryCode = lang; + } + var priceId = plan.PricesByCountry.ContainsKey(countryCode) ? plan.PricesByCountry[countryCode].StripePriceId : plan.StripePriceId; try { - var checkoutUrl = await _stripeService.CreateCheckoutSessionAsync(userId, priceId); + var checkoutUrl = await _stripeService.CreateCheckoutSessionAsync(userId, priceId, lang); return Json(new { success = true, url = checkoutUrl }); } catch (Exception ex) @@ -84,11 +90,22 @@ namespace QRRapidoApp.Controllers } [HttpGet] - public IActionResult Cancelar() + public async Task Cancelar() { _adDisplayService.SetViewBagAds(ViewBag); ViewBag.CancelMessage = "O pagamento foi cancelado. Você pode tentar novamente a qualquer momento."; - return View("SelecaoPlano"); + + var plans = await _planService.GetActivePlansAsync(); + var countryCode = GetUserCountryCode(); // Implement this method based on your needs + _adDisplayService.SetViewBagAds(ViewBag); + + var model = new SelecaoPlanoViewModel + { + Plans = plans, + CountryCode = countryCode + }; + + return View("SelecaoPlano", model); } [HttpPost] @@ -118,7 +135,37 @@ namespace QRRapidoApp.Controllers private string GetUserCountryCode() { - // Prioritize Cloudflare header, fallback to a default or other methods + // Check current culture from URL first + var culture = HttpContext.Request.RouteValues["culture"]?.ToString() ?? + HttpContext.Features.Get()?.RequestCulture?.Culture?.Name; + + var countryMap = new Dictionary + { + { "pt-BR", "BR" }, + { "es-PY", "PY" }, + { "es", "PY" } + }; + + if (!string.IsNullOrEmpty(culture) && countryMap.ContainsKey(culture)) + { + return countryMap[culture]; + } + + // Fallback to Cloudflare header or default + return HttpContext.Request.Headers["CF-IPCountry"].FirstOrDefault() ?? "BR"; + } + private string GetUserCountryCodeComplete() + { + // Check current culture from URL first + var culture = HttpContext.Request.RouteValues["culture"]?.ToString() ?? + HttpContext.Features.Get()?.RequestCulture?.Culture?.Name; + + if (languages.Contains(culture)) + { + return culture; + } + + // Fallback to Cloudflare header or default return HttpContext.Request.Headers["CF-IPCountry"].FirstOrDefault() ?? "BR"; } } diff --git a/Resources/SharedResource.pt-BR.resx b/Resources/SharedResource.pt-BR.resx index b32e943..de3e4fe 100644 --- a/Resources/SharedResource.pt-BR.resx +++ b/Resources/SharedResource.pt-BR.resx @@ -643,7 +643,7 @@ Geração prioritária (0.4s) - Acelerar por R$ 19,90/mês + Acelerar por R$ 12,90/mês Primeiro, escolha o tipo de QR Code diff --git a/Services/StripeService.cs b/Services/StripeService.cs index d45824b..cac0a68 100644 --- a/Services/StripeService.cs +++ b/Services/StripeService.cs @@ -24,7 +24,7 @@ namespace QRRapidoApp.Services StripeConfiguration.ApiKey = _config["Stripe:SecretKey"]; } - public async Task CreateCheckoutSessionAsync(string userId, string priceId) + public async Task CreateCheckoutSessionAsync(string userId, string priceId, string lang = "pt-BR") { var user = await _userService.GetUserAsync(userId); if (user == null) @@ -58,7 +58,7 @@ namespace QRRapidoApp.Services Customer = customerId, ClientReferenceId = userId, SuccessUrl = $"{_config["App:BaseUrl"]}/Pagamento/Sucesso", - CancelUrl = $"{_config["App:BaseUrl"]}/Pagamento/Cancelar", + CancelUrl = $"{_config["App:BaseUrl"]}/{lang}/Pagamento/SelecaoPlano", AllowPromotionCodes = true, Metadata = new Dictionary { { "user_id", userId } } }; diff --git a/Views/Account/Profile.cshtml b/Views/Account/Profile.cshtml index f17b549..a7c40e3 100644 --- a/Views/Account/Profile.cshtml +++ b/Views/Account/Profile.cshtml @@ -182,9 +182,11 @@
- - Sair - +
+ +
diff --git a/Views/Pagamento/SelecaoPlano.cshtml b/Views/Pagamento/SelecaoPlano.cshtml index 1df6c69..c9cb0bc 100644 --- a/Views/Pagamento/SelecaoPlano.cshtml +++ b/Views/Pagamento/SelecaoPlano.cshtml @@ -9,6 +9,8 @@ var monthlyPrice = monthlyPlan?.PricesByCountry.GetValueOrDefault(Model.CountryCode)?.Amount ?? 0; var yearlyPrice = yearlyPlan?.PricesByCountry.GetValueOrDefault(Model.CountryCode)?.Amount ?? 0; var yearlySavings = (monthlyPrice * 12) - yearlyPrice; + var currency = monthlyPlan?.PricesByCountry.GetValueOrDefault(Model.CountryCode)?.Currency ?? "BRL"; + var currencySymbol = currency == "PYG" ? "₲" : "R$"; }
@@ -26,7 +28,7 @@

@Localizer["MonthlyPlan"]

- R$ @monthlyPrice.ToString("0.00") + @currencySymbol @(currency == "PYG" ? monthlyPrice.ToString("N0") : monthlyPrice.ToString("0.00")) @Localizer["PerMonth"]

@Localizer["IdealToStartExploring"]

@@ -47,13 +49,13 @@
- R$ @yearlyPrice.ToString("0.00") + @currencySymbol @(currency == "PYG" ? yearlyPrice.ToString("N0") : yearlyPrice.ToString("0.00")) @Localizer["PerYear"]
@if (yearlySavings > 0) {
- @Localizer["SaveMoney"] @yearlySavings.ToString("0.00")! + @Localizer["SaveMoney"] @(currency == "PYG" ? yearlySavings.ToString("N0") : yearlySavings.ToString("0.00"))!
}

@Localizer["BestValueFrequentUsers"]

@@ -81,19 +83,123 @@ @section Scripts { + +