ゲームサーバーにフルフィルメントを実装する
Overview
This article walks you through how to implement code redemption and how to enable your game server to grant items to your players.
Code Redemption
A player can redeem a campaign code to receive entitlements, such as games, in-game items, or coins. To redeem a code, call RedeemCode from the Fulfillment API. The code will be redeemed and the player will receive their entitlements under the following conditions:
- The code exists in the game namespace
- The maximum redemption limit hasn't been reached
- The time and date of the redemption falls within the redemption period
- Unreal Engine
- Unity
FString Code = FString("MyRedeemCode");
FString Region = FString("US"); // Leave it blank if you want to use the default value from user token
FString Language = FString("en"); // Leave it blank if you want to use the default value from user token
FRegistry::Fulfillment.RedeemCode(Code, Region, Language, THandler<FAccelByteModelsFulfillmentResult>::CreateLambda([](const FAccelByteModelsFulfillmentResult& Result)
{
// Do something if RedeemCode has been successful
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if RedeemCode has an error
UE_LOG(LogTemp, Log, TEXT("Error RedeemCode, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string code= "some-code";
string region = "US";
string language = "en";
AccelByteSDK.GetClientRegistry().GetApi().GetFulfillment().RedeemCode(code, region, language, result =>
{
if (result.IsError)
{
// Do something if RedeemCode has an error
Debug.Log($"Error RedeemCode, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if RedeemCode has been successful
}
});
Game server grants items to players
The FulfillUserItem() function can be used to allow the game server to trigger the Fulfillment service and grant an item to a player. This can be used to immediately grant a player an item when they earn a particular achievement, or to grant every player in a match a special item for a particular game mode but have that item disappear from the player's inventory when the match is over.
- Unreal Engine
- Unity
#include "GameServerApi/AccelByteServerEcommerceApi.h"
...
FString UserId = FString("SomeUserId");
FAccelByteModelsFulfillmentRequest FulfillmentRequest;
FulfillmentRequest.ItemId = FString("SomeItemId");
FulfillmentRequest.OrderNo = FString("SomeOrderNo");
FulfillmentRequest.Language = FString("en");
FulfillmentRequest.Region = FString("US");
FulfillmentRequest.Quantity = 1;
FulfillmentRequest.Source = EAccelByteItemSource::ACHIEVEMENT;
FRegistry::ServerEcommerce.FulfillUserItem(UserId, FulfillmentRequest, THandler<FAccelByteModelsFulfillmentResult>::CreateLambda([](const FAccelByteModelsFulfillmentResult& Result)
{
// Do something if FulfillUserItem has been successful
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if FulfillUserItem has an error
UE_LOG(LogTemp, Log, TEXT("Error FulfillUserItem, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
using AccelByte.Server;
...
string userId = "SomeUserId";
FulfillmentRequest fulfillmentRequest = new FulfillmentRequest
{
itemId = "SomeItemId",
orderNo = "SomeOrderNo",
language = "en",
region = "US",
quantity = 1,
source = ItemSource.ACHIEVEMENT
};
AccelByteSDK.GetServerRegistry().GetApi().GetEcommerce().FulfillUserItem(userId, fulfillmentRequest, result =>
{
if (result.IsError)
{
// Do something if FulfillUserItem has an error
Debug.Log($"Error FulfillUserItem, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if FulfillUserItem has been successful
}
});