メインコンテンツまでスキップ

Integrate with flexible pricing bundle

Last updated on October 7, 2023

Overview

The AccelByte Gaming Services (AGS) flexible pricing bundle allows you to provide more reasonable pricing for player who already owned some items in the bundle and more consistent discounting experience as pricing will be in-sync when contents of a bundle go on sale

As demonstrated below, the final bundle price are calculated by the following factors: whether owned an item, item has a discount and bundle has a discount.

Player_Portal

Integrate with Game Client

Login

Login to AGS, so that you have access to call other endpoints

Before you start, please make sure you have the correct configuration and have integrated with OSS. For more information, please refer to https://docs.accelbyte.io/gaming-services/category/game-sdk-guides/.
IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
FOnlineIdentityAccelBytePtr IdentityInterface = StaticCastSharedPtr<FOnlineIdentityAccelByte>(OnlineSubsystem->GetIdentityInterface());
if (!IdentityInterface.IsValid())
{
return;
}

const int32 LocalUserNum = 0;
auto AccelByteLoginCompletehandle = IdentityInterface->AddAccelByteOnLoginCompleteDelegate_Handle(LocalUserNum
, FAccelByteOnLoginCompleteDelegate::CreateLambda(
[this]
(int32 LoggedInLocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId,
const FOnlineErrorAccelByte& Error)
{
UE_LOG(LogTemp, Log, TEXT("Get AccelByteOnLoginComplete: LocalUserNum=%d"), LoggedInLocalUserNum);
})
);

const EAccelByteLoginType Type = EAccelByteLoginType::AccelByte;
const FString ID = TEXT("username");
const FString Password = TEXT("password");
IdentityInterface->Login(LocalUserNum, FOnlineAccelByteAccountCredentials{ Type , ID, Password });

Get Flexible Pricing Bundle

To get flexible pricing bundles, make sure you have already created them in Admin Portal. You can check the boolean field "Flexible" from the response to determine whether it is a flexible pricing bundle

Before you start, please make sure you have the correct configuration and have integrated with OSS. For more information, please refer to https://docs.accelbyte.io/gaming-services/category/game-sdk-guides/.
const FOnlineStoreV2AccelBytePtr OnlineStoreV2AccelByte = StaticCastSharedPtr<FOnlineStoreV2AccelByte>(StoreInterface);
const FOnlinePurchaseAccelBytePtr OnlinePurchaseAccelByte = StaticCastSharedPtr<FOnlinePurchaseAccelByte>(PurchaseInterface);

// GetItemsByCriteria to get flexible bundle item
FAccelByteModelsItemPagingSlicedResult ItemPagingSlicedResult{};
OnlineStoreV2AccelByte->AddOnGetItemsByCriteriaCompleteDelegate_Handle(FOnGetItemsByCriteriaCompleteDelegate::CreateLambda(
[this, &ItemPagingSlicedResult]
(bool bWasSuccessful, const FAccelByteModelsItemPagingSlicedResult& Value, const FOnlineError& Error) {
if (bWasSuccessful)
{
ItemPagingSlicedResult = Value;
}
}));

const FString Region = TEXT("US");
FAccelByteModelsItemCriteria ItemCriteria;
ItemCriteria.Language = TEXT("en");
ItemCriteria.Region = Region;
ItemCriteria.ItemType = EAccelByteItemType::BUNDLE;
ItemCriteria.CategoryPath = ECommerceTestFlexibleBundleItemCategoryPath;
auto UserId = IdentityInterface->GetUniquePlayerId(LocalUserNum).Get();
OnlineStoreV2AccelByte->GetItemsByCriteria(*UserId, ItemCriteria);


FString ItemId = ItemPagingSlicedResult.Data[0].ItemId;

Get Estimated Price

As the price can be varied by who and when to buy a flexible pricing bundle, game client need to call this endpoint to get the latest pricing for players

Before you start, please make sure you have the correct configuration and have integrated with OSS. For more information, please refer to https://docs.accelbyte.io/gaming-services/category/game-sdk-guides/.
// GetEstimatedPrice to get the proper price when creating order
bool bGettingEstimatedPriceDone = false;
bool bGettingEstimatedPriceSuccess = false;
TArray<FAccelByteModelsEstimatedPrices> EstimatedPrices{};
OnlineStoreV2AccelByte->AddOnGetEstimatedPriceCompleteDelegate_Handle(FOnGetEstimatedPriceCompleteDelegate::CreateLambda(
[this, &EstimatedPrices]
(bool bWasSuccessful, const TArray<FAccelByteModelsEstimatedPrices>& Value, const FOnlineErrorAccelByte& Error) {
if (bWasSuccessful)
{
EstimatedPrices = Value;
}
}));
auto UserId = IdentityInterface->GetUniquePlayerId(LocalUserNum).Get();
OnlineStoreV2AccelByte->GetEstimatedPrice(*UserId, {ItemId}, Region);

Create Order

This is similar to normal create order flow, but make sure estimated price is used when placing an order for flexible pricing bundle

Before you start, please make sure you have the correct configuration and have integrated with OSS. For more information, please refer to https://docs.accelbyte.io/gaming-services/category/game-sdk-guides/.
// Create Order to enabling OrderBundleItemInfos
const FString CurrencyCode = EstimatedPrices[0].EstimatedPrices[0].CurrencyCode;
const int32 DiscountedPrice = EstimatedPrices[0].EstimatedPrices[0].DiscountedPrice;
const int32 Price = EstimatedPrices[0].EstimatedPrices[0].Price;

FString OrderNo{};
constexpr int32 Quantity = 1;
FAccelByteModelsOrderCreate OrderCreate;
OrderCreate.CurrencyCode = CurrencyCode;
OrderCreate.DiscountedPrice = DiscountedPrice * Quantity;
OrderCreate.Price = Price * Quantity;
OrderCreate.Quantity = Quantity;
OrderCreate.ReturnUrl = TEXT("https://sdk.example.com");
OrderCreate.ItemId = ItemId;
OrderCreate.Region = Region;
OrderCreate.Language = TEXT("en");

bool bCreatingOrderDone = false;
bool bCreatingOrderSuccess = false;
FAccelByteModelsOrderInfo OrderInfo{};
OnlinePurchaseAccelByte->AddOnCreateNewOrderCompleteDelegate_Handle(FOnCreateNewOrderCompleteDelegate::CreateLambda(
[this, &OrderInfo]
(bool bWasSuccessful, FAccelByteModelsOrderInfo Value, const FOnlineErrorAccelByte& Error) {
if (bWasSuccessful)
{
OrderInfo = Value;
}
}));
auto UserId = IdentityInterface->GetUniquePlayerId(LocalUserNum).Get();
OnlinePurchaseAccelByte->CreateNewOrder(*UserId, OrderCreate);

Query Order

Before you start, please make sure you have the correct configuration and have integrated with OSS. For more information, please refer to https://docs.accelbyte.io/gaming-services/category/game-sdk-guides/.

Query order details for flexible pricing bundle
// QueryUserOrders to check OrderBundleItemInfos exist 
bool bGettingUserOrdersDone = false;
bool bGettingUserOrdersSuccess = false;
FAccelByteModelsPagedOrderInfo PagedOrderInfo{};
OnlinePurchaseAccelByte->AddOnQueryUserOrdersCompleteDelegate_Handle(FOnQueryUserOrdersCompleteDelegate::CreateLambda(
[this, &PagedOrderInfo]
(bool bWasSuccessful, const FAccelByteModelsPagedOrderInfo& Value, const FOnlineErrorAccelByte& Error) {
if (bWasSuccessful)
{
PagedOrderInfo = Value;
}
}));
FAccelByteModelsUserOrdersRequest UserOrdersRequest{};
UserOrdersRequest.ItemId = ItemId;
auto UserId = IdentityInterface->GetUniquePlayerId(LocalUserNum).Get();
OnlinePurchaseAccelByte->QueryUserOrders(*UserId, UserOrdersRequest);

The related information can be found in OrderBundleItemInfos variable

auto BundleInfo = PagedOrderInfo.Data[0].OrderBundleItemInfos;