SDK for / Overview

XsollaInventorySubsystem.h

1// Copyright 2024 Xsolla Inc. All Rights Reserved.
2
3#pragma once
4
5#include "XsollaInventoryDataModel.h"
6
7#include "XsollaUtilsHttpRequestHelper.h"
8
9#include "Subsystems/GameInstanceSubsystem.h"
10#include "Subsystems/SubsystemCollection.h"
11#include "XsollaUtilsDataModel.h"
12
13#include "XsollaInventorySubsystem.generated.h"
14
15enum class EXsollaPublishingPlatform : uint8;
16class FJsonObject;
18
19DECLARE_DYNAMIC_DELEGATE(FOnInventoryRequestSuccess);
20DECLARE_DYNAMIC_DELEGATE_OneParam(FOnInventoryUpdate, const FInventoryItemsData&, InventoryData);
21DECLARE_DYNAMIC_DELEGATE_OneParam(FOnCurrencyBalanceUpdate, const FVirtualCurrencyBalanceData&, CurrencyBalanceData);
22DECLARE_DYNAMIC_DELEGATE_OneParam(FOnTimeLimitedItemsUpdate, const FTimeLimitedItemsData&, TimeLimitedItemsData);
23DECLARE_DYNAMIC_DELEGATE_OneParam(FOnCouponRewardsUpdate, FInventoryCouponRewardData, RewardsData);
24DECLARE_DYNAMIC_DELEGATE_OneParam(FOnCouponRedeemUpdate, FInventoryRedeemedCouponData, RewardData);
25
26UCLASS()
27class XSOLLAINVENTORY_API UXsollaInventorySubsystem : public UGameInstanceSubsystem
28{
29GENERATED_BODY()
30
31public:
33
34// Begin USubsystem
35virtual void Initialize(FSubsystemCollectionBase& Collection) override;
36virtual void Deinitialize() override;
37// End USubsystem
38
44UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory")
45void Initialize(const FString& InProjectId);
46
58UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory", meta = (AutoCreateRefTerm = "SuccessCallback, ErrorCallback"))
59void GetInventory(const FString& AuthToken, const EXsollaPublishingPlatform Platform,
60const FOnInventoryUpdate& SuccessCallback, const FOnError& ErrorCallback, const int Limit = 50, const int Offset = 0);
61
71UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory|VirtualCurrency", meta = (AutoCreateRefTerm = "SuccessCallback, ErrorCallback"))
72void GetVirtualCurrencyBalance(const FString& AuthToken, const EXsollaPublishingPlatform Platform,
73const FOnCurrencyBalanceUpdate& SuccessCallback, const FOnError& ErrorCallback);
74
84UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory|TimeLimitedItems", meta = (AutoCreateRefTerm = "SuccessCallback, ErrorCallback"))
85void GetTimeLimitedItems(const FString& AuthToken, const EXsollaPublishingPlatform Platform,
86const FOnTimeLimitedItemsUpdate& SuccessCallback, const FOnError& ErrorCallback);
87
100UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory", meta = (AutoCreateRefTerm = "SuccessCallback, ErrorCallback"))
101void ConsumeInventoryItem(const FString& AuthToken, const FString& ItemSKU, const int32 Quantity,
102const FString& InstanceID, const EXsollaPublishingPlatform Platform,
103const FOnInventoryRequestSuccess& SuccessCallback, const FOnError& ErrorCallback);
104
114UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory|Coupons", meta = (AutoCreateRefTerm = "SuccessCallback, ErrorCallback"))
115void GetCouponRewards(const FString& AuthToken, const FString& CouponCode,
116const FOnCouponRewardsUpdate& SuccessCallback, const FOnError& ErrorCallback);
117
129UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory|Coupons", meta = (AutoCreateRefTerm = "SuccessCallback, ErrorCallback"))
130void RedeemCoupon(const FString& AuthToken, const FString& CouponCode,
131const FOnCouponRedeemUpdate& SuccessCallback, const FOnError& ErrorCallback);
132
133protected:
134void GetInventory_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
135const bool bSucceeded, FOnInventoryUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
136void GetVirtualCurrencyBalance_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
137const bool bSucceeded, FOnCurrencyBalanceUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
138void GetTimeLimitedItems_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
139const bool bSucceeded, FOnTimeLimitedItemsUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
140
141void ConsumeInventoryItem_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
142const bool bSucceeded, FOnInventoryRequestSuccess SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
143
144void UpdateCouponRewards_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
145const bool bSucceeded, FOnCouponRewardsUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
146void RedeemCoupon_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
147const bool bSucceeded, FOnCouponRedeemUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
148
149private:
151TSharedRef<IHttpRequest, ESPMode::ThreadSafe> CreateHttpRequest(const FString& Url, const EXsollaHttpRequestVerb Verb = EXsollaHttpRequestVerb::VERB_GET,
152const FString& AuthToken = FString(), const FString& Content = FString());
153
155FString SerializeJson(const TSharedPtr<FJsonObject> DataJson) const;
156
157UPROPERTY()
158UXsollaLoginSubsystem* LoginSubsystem;
159
160protected:
162FString ProjectID;
163};
Definition: XsollaInventorySubsystem.h:28
Definition: XsollaLoginSubsystem.h:49