Player Wallet
1. What Is the Player Wallet?
The player wallet is designed to help you manage the currencies held by players. You can view the balances and consumption of the currency that players purchased and received in their wallets. For security reasons, we only provide APIs that grant currency to wallets for game servers and virtual servers.
2. Using the Wallet in the Portal
Go to Portal -> Players and find the desired player. In the Economy tab of the player details, you can find the player's wallet. Here, you can see all the currencies held by the player.
- Currency Code: The unique identifier of a currency.
- Type: Only Virtual Currency is supported currently.
- Amount: The balance of this currency.
- Total Spend: The amount of this currency spent by the player.
In some circumstances, you may have to directly place currency in a player's wallet or remove a specified amount from a player's wallet. To do this, go to the Portal, find the player in the Player Query area, and open the player wallet page:
Click Operation -> “+‘’ to grant the specified currency to the player.
Click Operation -> ”-“ to subtract the specified currency from the player.
3. Using Balances Through the Client SDK
3.1 Acquire Balances
This operation acquires player balances. Call the GetBalances method of the Client Economy module:
- UE C++
- UE BP
#include "PgosSDKCpp/Public/PgosSDKCpp.h"
#include "PgosSDKCpp/Public/Core/PgosErrorCode.h"
void SomeUObjectClass::GetBalances()
{
auto economy = IPgosSDKCpp::Get().GetClientEconomyAPI();
if (economy)
{
economy->GetBalances(
[](const FPgosResult& Ret, const FClientGetBalancesResult* Response) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("GetBalances Success"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("GetBalances Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}
#include "PgosSDKBp/Public/PgosClientEconomyAPI.h"
void SomeUObjectClass::GetBalances()
{
PGOS_CALL_ASYNC_API(UPgosClientAPIGetBalances::GetBalances,
this,
&SomeUObjectClass::GetBalancesSuccess,
&SomeUObjectClass::GetBalancesFailed);
}
void SomeUObjectClass::GetBalancesSuccess(FPgosResult Error, FClientGetBalancesResult Result)
{
UE_LOG(LogTemp, Log, TEXT("GetBalances Success"));
}
void SomeUObjectClass::GetBalancesFailed(FPgosResult Error)
{
UE_LOG(LogTemp, Log, TEXT("GetBalances Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
4. Using Balances Through the DS SDK
4.1 Grant Currency
This operation grants specified currencies to specified players.
Call the GrantCurrencyToPlayer method of the Server Economy module:
- UE C++
- UE BP
#include "PgosSDKCpp/Public/PgosSDKCpp.h"
#include "PgosSDKCpp/Public/Core/PgosErrorCode.h"
void SomeUObjectClass::GrantCurrencyToPlayer()
{
auto economy = IPgosSDKCpp::Get().GetServerEconomyAPI();
if (economy)
{
FString PlayerId = "13148";
FServerGrantCurrency Currency;
Currency.currency_code = "DIAMOND";
Currency.amount = 888;
economy->GrantCurrencyToPlayer(
PlayerId, Currency,
[](const FPgosResult& Ret, const FServerGrantCurrencyResult* Response) {
if (Ret.err_code == (int32)Pgos::PgosErrCode::kSuccess)
{
UE_LOG(LogTemp, Log, TEXT("GrantCurrencyToPlayer Success"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("GrantCurrencyToPlayer Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
});
}
}
#include "PgosSDKBp/Public/PgosServerEconomyAPI.h"
void SomeUObjectClass::GrantCurrencyToPlayer()
{
FString PlayerId = "13148";
FServerGrantCurrency Currency;
Currency.currency_code = "DIAMOND";
Currency.amount = 888;
PGOS_CALL_ASYNC_API(UPgosServerAPIGrantCurrencyToPlayer::GrantCurrencyToPlayer,
this,
&SomeUObjectClass::GrantCurrencyToPlayerSuccess,
&SomeUObjectClass::GrantCurrencyToPlayerFailed,
PlayerId,
Currency);
}
void SomeUObjectClass::GrantCurrencyToPlayerSuccess(FPgosResult Error, FServerGrantCurrencyResult Result)
{
UE_LOG(LogTemp, Log, TEXT("GrantCurrencyToPlayer Success"));
}
void SomeUObjectClass::GrantCurrencyToPlayerFailed(FPgosResult Error)
{
UE_LOG(LogTemp, Log, TEXT("GrantCurrencyToPlayer Failed: err_code=%d, err_msg=%s"), Ret.err_code, *Ret.msg);
}
6. Key Errors Handling
Error Code | Relevant API | Handling Suggestion |
---|---|---|
kBackendThrottling | GrantCurrencyToPlayer | Too many operations for current player detected, please retry shortly. |
kBackendShouldRetry | GrantCurrencyToPlayer | The failure request can be retried for a success. |
kBackendIdempotentParamsMismatch | GrantCurrencyToPlayer | A idempotency_token input parameter was reused with an operation, but at least one of the other input parameters is different from the previous call to the operation. By now the error will be returned when player id is not consistent. |