Retrieving offers
E-commerce functionality is provided via the IOnlineStoreV2, IOnlineEntitlements and IOnlinePurchase interfaces. Retrieving the available offers is done via the IOnlineStoreV2 interface.
Platform support
- Epic Games Store
- Steam
- Google Play
When querying offers for Epic Games Store, there are a few things to note:
- The
QueryCategoriesoperation isn't supported, because Epic Games Store offers don't have categories. - Both
QueryOffersByIdandQueryOffersByFilteroperations work. Underneath they both just query all offers though, and forQueryOffersByIdit then filters the results so only the offers you were interested in are returned. - The Epic Games Store integration supports both durable and consumable purchases.
Epic Games Store e-commerce only works from packaged games. You must packaged the game on Windows so that the EOS bootstrapper launches the game, and then test Epic Games Store e-commerce from there.
Querying a list of offers via a filter
Querying by filter only works on Epic Games Store and Steam. To query on other platforms, refer to Querying a list of offers by ID.
- C++
- Blueprints
To query for offers via a filter, first get the online store interface:
#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlineStoreInterfaceV2.h"
// ...
IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineStoreV2Ptr StoreV2 = Subsystem->GetStoreV2Interface();
Then, use QueryOffersByFilter to cache all the available offers.
StoreV2->QueryOffersByFilter(
*Identity->GetUniquePlayerId(0).Get(), // The local player to get offers for.
FOnlineStoreFilter(), // Filters are ignored for Steam.
FOnQueryOnlineStoreOffersComplete::CreateLambda([
StoreV2Wk = TWeakPtr<IOnlineStoreV2, ESPMode::ThreadSafe>(StoreV2)](
bool bWasSuccessful,
const TArray<FUniqueOfferId>& OfferIds,
const FString& Error)
{
if (auto StoreV2 = StoreV2Wk.Pin())
{
if (bWasSuccessful && StoreV2.IsValid())
{
TArray<FOnlineStoreOfferRef> Offers;
StoreV2->GetOffers(Offers);
// Offers now contains a list of offers. You can call
// GetOffers from anywhere to get the cached list of
// offers.
}
}
})
)
Querying a list of offers via ID
Querying by ID only works on Epic Games Store and Google Play. To query on other platforms, refer to Querying a list of offers by a filter.
- C++
- Blueprints
To query for offers by ID, first get the online store interface:
#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlineStoreInterfaceV2.h"
// ...
IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineStoreV2Ptr StoreV2 = Subsystem->GetStoreV2Interface();
Then, use QueryOffersById to cache all the available offers.
TArray<FUniqueOfferId> OfferIds;
OfferIds.Add(TEXT("test_iap"));
StoreV2->QueryOffersById(
*Identity->GetUniquePlayerId(0).Get(), // The local player to get offers for.
OfferIds,
FOnQueryOnlineStoreOffersComplete::CreateLambda([
StoreV2Wk = TWeakPtr<IOnlineStoreV2, ESPMode::ThreadSafe>(StoreV2)](
bool bWasSuccessful,
const TArray<FUniqueOfferId>& OfferIds,
const FString& Error)
{
if (auto StoreV2 = StoreV2Wk.Pin())
{
if (bWasSuccessful && StoreV2.IsValid())
{
TArray<FOnlineStoreOfferRef> Offers;
StoreV2->GetOffers(Offers);
// Offers now contains a list of offers. You can call
// GetOffers from anywhere to get the cached list of
// offers.
}
}
})
)