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
134UFUNCTION(BlueprintCallable, Category = "Xsolla|Inventory")
135static bool IsItemInInventory(const FInventoryItemsData& Inventory, const FString& ItemSKU, FInventoryItem& FoundItem);
136
137protected:
138void GetInventory_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
139const bool bSucceeded, FOnInventoryUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
140void GetVirtualCurrencyBalance_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
141const bool bSucceeded, FOnCurrencyBalanceUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
142void GetTimeLimitedItems_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
143const bool bSucceeded, FOnTimeLimitedItemsUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
144
145void ConsumeInventoryItem_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
146const bool bSucceeded, FOnInventoryRequestSuccess SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
147
148void UpdateCouponRewards_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
149const bool bSucceeded, FOnCouponRewardsUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
150void RedeemCoupon_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
151const bool bSucceeded, FOnCouponRedeemUpdate SuccessCallback, FErrorHandlersWrapper ErrorHandlersWrapper);
152
153private:
155TSharedRef<IHttpRequest, ESPMode::ThreadSafe> CreateHttpRequest(const FString& Url, const EXsollaHttpRequestVerb Verb = EXsollaHttpRequestVerb::VERB_GET,
156const FString& AuthToken = FString(), const FString& Content = FString());
157
159FString SerializeJson(const TSharedPtr<FJsonObject> DataJson) const;
160
161UPROPERTY()
162UXsollaLoginSubsystem* LoginSubsystem;
163
164protected:
166FString ProjectID;
167};
Definition: XsollaInventorySubsystem.h:28
Definition: XsollaLoginSubsystem.h:49
Definition: XsollaInventoryDataModel.h:11
Definition: XsollaInventoryDataModel.h:51