2026-08-12 14:04:55 +03:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using RudderSdk.Core.Models.Stores;
|
|
|
|
|
|
|
|
|
|
namespace RudderSdk.Core;
|
|
|
|
|
|
|
|
|
|
/// <summary>In-game stores and offer purchases.</summary>
|
|
|
|
|
public sealed class StoresService
|
|
|
|
|
{
|
|
|
|
|
private readonly RudderClient _client;
|
|
|
|
|
|
|
|
|
|
internal StoresService(RudderClient client) => _client = client;
|
|
|
|
|
|
|
|
|
|
/// <summary>Lists the available stores with their offers.</summary>
|
|
|
|
|
public async Task<IReadOnlyList<Store>> ListAsync(CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
var response = await _client.SendAsync<ListStoresResponse>(
|
|
|
|
|
"GET",
|
|
|
|
|
"/sdk/v1/stores",
|
|
|
|
|
cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return response?.Stores ?? new List<Store>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Resolves one store by slug.</summary>
|
|
|
|
|
public Task<Store> GetAsync(string slug, CancellationToken cancellationToken = default)
|
|
|
|
|
=> _client.SendAsync<Store>("GET", "/sdk/v1/stores/" + Url.Encode(slug), cancellationToken);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Purchases an offer (charges the wallet). When
|
|
|
|
|
/// <paramref name="idempotencyKey"/> is null, a random one is generated;
|
|
|
|
|
/// pass a stable key to make retries safe.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Task<PurchaseOfferResponse> PurchaseAsync(
|
|
|
|
|
string storeSlug,
|
2026-09-06 22:25:32 +03:00
|
|
|
string offerSlug,
|
2026-08-12 14:04:55 +03:00
|
|
|
string? idempotencyKey = null,
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
return _client.SendAsync<PurchaseOfferRequest, PurchaseOfferResponse>(
|
|
|
|
|
"POST",
|
2026-09-06 22:25:32 +03:00
|
|
|
"/sdk/v1/stores/" + Url.Encode(storeSlug) + "/offers/" + Url.Encode(offerSlug) + "/purchase",
|
2026-08-12 14:04:55 +03:00
|
|
|
new PurchaseOfferRequest
|
|
|
|
|
{
|
|
|
|
|
StoreSlug = storeSlug,
|
2026-09-06 22:25:32 +03:00
|
|
|
OfferSlug = offerSlug,
|
2026-08-12 14:04:55 +03:00
|
|
|
IdempotencyKey = idempotencyKey ?? Guid.NewGuid().ToString()
|
|
|
|
|
},
|
|
|
|
|
cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|