common: handle paddle billing errors
This commit is contained in:
1 parent
7172510c9e
commit
3bb140aeb3
3 files changed
+12
-12
No files matched your search
@@ -7,7 +7,7 @@ namespace Streetwriters.Common.Interfaces
|
|||||||
public interface IUserAccountService
|
public interface IUserAccountService
|
||||||
{
|
{
|
||||||
[WampProcedure("co.streetwriters.identity.users.get_user")]
|
[WampProcedure("co.streetwriters.identity.users.get_user")]
|
||||||
Task<UserModel> GetUserAsync(string clientId, string userId);
|
Task<UserModel?> GetUserAsync(string clientId, string userId);
|
||||||
[WampProcedure("co.streetwriters.identity.users.delete_user")]
|
[WampProcedure("co.streetwriters.identity.users.delete_user")]
|
||||||
Task DeleteUserAsync(string clientId, string userId, string password);
|
Task DeleteUserAsync(string clientId, string userId, string password);
|
||||||
// [WampProcedure("co.streetwriters.identity.users.create_user")]
|
// [WampProcedure("co.streetwriters.identity.users.create_user")]
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace Streetwriters.Common.Services
|
|||||||
return await response.Content.ReadFromJsonAsync<ListTransactionsResponseV2>();
|
return await response.Content.ReadFromJsonAsync<ListTransactionsResponseV2>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> RefundTransactionAsync(string transactionId, string transactionItemId, string reason = "")
|
public async Task<PaddleResponse?> RefundTransactionAsync(string transactionId, string transactionItemId, string reason = "")
|
||||||
{
|
{
|
||||||
var url = $"{PADDLE_BASE_URI}/adjustments";
|
var url = $"{PADDLE_BASE_URI}/adjustments";
|
||||||
var response = await httpClient.PostAsync(url, JsonContent.Create(new Dictionary<string, object>
|
var response = await httpClient.PostAsync(url, JsonContent.Create(new Dictionary<string, object>
|
||||||
@@ -77,7 +77,7 @@ namespace Streetwriters.Common.Services
|
|||||||
{ "reason", reason },
|
{ "reason", reason },
|
||||||
{ "transaction_id", transactionId }
|
{ "transaction_id", transactionId }
|
||||||
}));
|
}));
|
||||||
return response.IsSuccessStatusCode;
|
return await response.Content.ReadFromJsonAsync<PaddleResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<SubscriptionPreviewResponse?> PreviewSubscriptionChangeAsync(string subscriptionId, string newProductId, bool isTrialing)
|
public async Task<SubscriptionPreviewResponse?> PreviewSubscriptionChangeAsync(string subscriptionId, string newProductId, bool isTrialing)
|
||||||
@@ -102,28 +102,28 @@ namespace Streetwriters.Common.Services
|
|||||||
return await response.Content.ReadFromJsonAsync<PaddleResponse>();
|
return await response.Content.ReadFromJsonAsync<PaddleResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> CancelSubscriptionAsync(string subscriptionId)
|
public async Task<PaddleResponse?> CancelSubscriptionAsync(string subscriptionId)
|
||||||
{
|
{
|
||||||
var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}/cancel";
|
var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}/cancel";
|
||||||
var response = await httpClient.PostAsync(url, JsonContent.Create(new { effective_from = "immediately" }));
|
var response = await httpClient.PostAsync(url, JsonContent.Create(new { effective_from = "immediately" }));
|
||||||
return response.IsSuccessStatusCode;
|
return await response.Content.ReadFromJsonAsync<PaddleResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> PauseSubscriptionAsync(string subscriptionId)
|
public async Task<PaddleResponse?> PauseSubscriptionAsync(string subscriptionId)
|
||||||
{
|
{
|
||||||
var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}/pause";
|
var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}/pause";
|
||||||
var response = await httpClient.PostAsync(url, JsonContent.Create(new { }));
|
var response = await httpClient.PostAsync(url, JsonContent.Create(new { }));
|
||||||
return response.IsSuccessStatusCode;
|
return await response.Content.ReadFromJsonAsync<PaddleResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> ResumeSubscriptionAsync(string subscriptionId)
|
public async Task<PaddleResponse?> ResumeSubscriptionAsync(string subscriptionId)
|
||||||
{
|
{
|
||||||
var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}";
|
var url = $"{PADDLE_BASE_URI}/subscriptions/{subscriptionId}";
|
||||||
var response = await httpClient.PatchAsync(url, JsonContent.Create(new Dictionary<string, string?>
|
var response = await httpClient.PatchAsync(url, JsonContent.Create(new Dictionary<string, string?>
|
||||||
{
|
{
|
||||||
{"scheduled_change", null}
|
{"scheduled_change", null}
|
||||||
}));
|
}));
|
||||||
return response.IsSuccessStatusCode;
|
return await response.Content.ReadFromJsonAsync<PaddleResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<GetCustomerResponse?> FindCustomerFromTransactionAsync(string transactionId)
|
public async Task<GetCustomerResponse?> FindCustomerFromTransactionAsync(string transactionId)
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ namespace Streetwriters.Identity.Services
|
|||||||
{
|
{
|
||||||
public class UserAccountService(UserManager<User> userManager, IMFAService mfaService) : IUserAccountService
|
public class UserAccountService(UserManager<User> userManager, IMFAService mfaService) : IUserAccountService
|
||||||
{
|
{
|
||||||
public async Task<UserModel> GetUserAsync(string clientId, string userId)
|
public async Task<UserModel?> GetUserAsync(string clientId, string userId)
|
||||||
{
|
{
|
||||||
var user = await userManager.FindByIdAsync(userId);
|
var user = await userManager.FindByIdAsync(userId);
|
||||||
if (!await UserService.IsUserValidAsync(userManager, user, clientId))
|
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 claims = await userManager.GetClaimsAsync(user);
|
||||||
var marketingConsentClaim = claims.FirstOrDefault((claim) => claim.Type == $"{clientId}:marketing_consent");
|
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)
|
public async Task DeleteUserAsync(string clientId, string userId, string password)
|
||||||
{
|
{
|
||||||
var user = await userManager.FindByIdAsync(userId);
|
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.");
|
if (!await userManager.CheckPasswordAsync(user, password)) throw new Exception("Wrong password.");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user