From 3bb140aeb35f7c5805dcf9fa959cddd836e4ae0e Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 1 Oct 2025 12:00:01 +0500 Subject: [PATCH] common: handle paddle billing errors --- .../Interfaces/IUserAccountService.cs | 2 +- .../Services/PaddleBillingService.cs | 16 ++++++++-------- .../Services/UserAccountService.cs | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Streetwriters.Common/Interfaces/IUserAccountService.cs b/Streetwriters.Common/Interfaces/IUserAccountService.cs index facb452..74c16b9 100644 --- a/Streetwriters.Common/Interfaces/IUserAccountService.cs +++ b/Streetwriters.Common/Interfaces/IUserAccountService.cs @@ -7,7 +7,7 @@ namespace Streetwriters.Common.Interfaces public interface IUserAccountService { [WampProcedure("co.streetwriters.identity.users.get_user")] - Task GetUserAsync(string clientId, string userId); + Task GetUserAsync(string clientId, string userId); [WampProcedure("co.streetwriters.identity.users.delete_user")] Task DeleteUserAsync(string clientId, string userId, string password); // [WampProcedure("co.streetwriters.identity.users.create_user")] diff --git a/Streetwriters.Common/Services/PaddleBillingService.cs b/Streetwriters.Common/Services/PaddleBillingService.cs index a536359..32cedc1 100644 --- a/Streetwriters.Common/Services/PaddleBillingService.cs +++ b/Streetwriters.Common/Services/PaddleBillingService.cs @@ -58,7 +58,7 @@ namespace Streetwriters.Common.Services return await response.Content.ReadFromJsonAsync(); } - public async Task RefundTransactionAsync(string transactionId, string transactionItemId, string reason = "") + public async Task RefundTransactionAsync(string transactionId, string transactionItemId, string reason = "") { var url = $"{PADDLE_BASE_URI}/adjustments"; var response = await httpClient.PostAsync(url, JsonContent.Create(new Dictionary @@ -77,7 +77,7 @@ namespace Streetwriters.Common.Services { "reason", reason }, { "transaction_id", transactionId } })); - return response.IsSuccessStatusCode; + return await response.Content.ReadFromJsonAsync(); } public async Task PreviewSubscriptionChangeAsync(string subscriptionId, string newProductId, bool isTrialing) @@ -102,28 +102,28 @@ namespace Streetwriters.Common.Services return await response.Content.ReadFromJsonAsync(); } - public async Task CancelSubscriptionAsync(string subscriptionId) + public async Task CancelSubscriptionAsync(string subscriptionId) { var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}/cancel"; var response = await httpClient.PostAsync(url, JsonContent.Create(new { effective_from = "immediately" })); - return response.IsSuccessStatusCode; + return await response.Content.ReadFromJsonAsync(); } - public async Task PauseSubscriptionAsync(string subscriptionId) + public async Task PauseSubscriptionAsync(string subscriptionId) { var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}/pause"; var response = await httpClient.PostAsync(url, JsonContent.Create(new { })); - return response.IsSuccessStatusCode; + return await response.Content.ReadFromJsonAsync(); } - public async Task ResumeSubscriptionAsync(string subscriptionId) + public async Task ResumeSubscriptionAsync(string subscriptionId) { var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}"; var response = await httpClient.PatchAsync(url, JsonContent.Create(new Dictionary { {"scheduled_change", null} })); - return response.IsSuccessStatusCode; + return await response.Content.ReadFromJsonAsync(); } public async Task FindCustomerFromTransactionAsync(string transactionId) diff --git a/Streetwriters.Identity/Services/UserAccountService.cs b/Streetwriters.Identity/Services/UserAccountService.cs index 37ae44b..0681889 100644 --- a/Streetwriters.Identity/Services/UserAccountService.cs +++ b/Streetwriters.Identity/Services/UserAccountService.cs @@ -12,11 +12,11 @@ namespace Streetwriters.Identity.Services { public class UserAccountService(UserManager userManager, IMFAService mfaService) : IUserAccountService { - public async Task GetUserAsync(string clientId, string userId) + public async Task GetUserAsync(string clientId, string userId) { var user = await userManager.FindByIdAsync(userId); if (!await UserService.IsUserValidAsync(userManager, user, clientId)) - throw new Exception($"Unable to find user with ID '{userId}'."); + return null; var claims = await userManager.GetClaimsAsync(user); var marketingConsentClaim = claims.FirstOrDefault((claim) => claim.Type == $"{clientId}:marketing_consent"); @@ -46,7 +46,7 @@ namespace Streetwriters.Identity.Services public async Task DeleteUserAsync(string clientId, string userId, string password) { var user = await userManager.FindByIdAsync(userId); - if (!await UserService.IsUserValidAsync(userManager, user, clientId)) throw new Exception($"User not found."); + if (!await UserService.IsUserValidAsync(userManager, user, clientId)) return; if (!await userManager.CheckPasswordAsync(user, password)) throw new Exception("Wrong password.");