Charge Currency
Charges the player's currency.
URL Confirmation
This API uses the service-api.playnanoo.com domain.
API Information
- URL:
https://service-api.playnanoo.com/currency/v20221101/currency/charge - Method:
PUT - Authentication Required: Yes
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| items | string | Required | Currency list (JSON string) |
Response Data
| Field | Type | Description |
|---|---|---|
| items | array | Currency list after charging |
Items Array Elements
| Field | Type | Description |
|---|---|---|
| currency_code | string | Currency code |
| currency_amount | number | Owned currency quantity |
Code Example
void UMyGame::ChargeCurrency(const FString& CurrencyCode, double Amount)
{
// Create items JSON
TSharedPtr<FJsonObject> ItemWrapper = MakeShareable(new FJsonObject());
TArray<TSharedPtr<FJsonValue>> ItemsArray;
TSharedPtr<FJsonObject> Item = MakeShareable(new FJsonObject());
Item->SetStringField(TEXT("currency_code"), CurrencyCode);
Item->SetNumberField(TEXT("currency_amount"), Amount);
ItemsArray.Add(MakeShareable(new FJsonValueObject(Item)));
ItemWrapper->SetArrayField(TEXT("items"), ItemsArray);
FString ItemsJson;
TSharedRef<TJsonWriter<>> ItemsWriter = TJsonWriterFactory<>::Create(&ItemsJson);
FJsonSerializer::Serialize(ItemWrapper.ToSharedRef(), ItemsWriter);
// Create request body with player information
TSharedPtr<FJsonObject> Body = FPlayNANOOHelper::CreateRequestBody();
Body->SetStringField(TEXT("items"), ItemsJson);
// Convert to JSON string
FString JsonBody = FPlayNANOOHelper::ToJsonString(Body);
// HTTP request
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->SetURL(TEXT("https://service-api.playnanoo.com/currency/v20221101/currency/charge"));
Request->SetVerb(TEXT("PUT"));
FPlayNANOOHelper::SetCommonHeaders(Request, true); // Include auth token
Request->SetContentAsString(JsonBody);
Request->OnProcessRequestComplete().BindLambda(
[](FHttpRequestPtr Req, FHttpResponsePtr Res, bool bSuccess)
{
if (bSuccess && Res.IsValid())
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Res->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
const TArray<TSharedPtr<FJsonValue>>* Items;
if (JsonObject->TryGetArrayField(TEXT("items"), Items))
{
for (const auto& ItemVal : *Items)
{
TSharedPtr<FJsonObject> Currency = ItemVal->AsObject();
FString Code = Currency->GetStringField(TEXT("currency_code"));
double Amt = Currency->GetNumberField(TEXT("currency_amount"));
UE_LOG(LogTemp, Log, TEXT("Currency charged: %s = %f"), *Code, Amt);
}
}
}
}
});
Request->ProcessRequest();
}
Charging Multiple Currencies
You can charge multiple types of currencies at once.