Charge Currency
API to charge player's currency.
URL Verification
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
DeviceInfo Inheritance
The Req class of this API inherits from DeviceInfo. All properties of DeviceInfo are automatically included.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| items | string | Required | Currency list (JSON string) |
Response Data
Res Class
| Field | Type | Description |
|---|---|---|
| items | List<ItemModel> | Currency list after charging |
ItemModel Class
| Field | Type | Description |
|---|---|---|
| currency_code | string | Currency code |
| currency_amount | double | Currency amount owned |
Unity C# Implementation
BaseResponse Class
Base class for all API responses.
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
Field descriptions:
ErrorCode: Error codeMessage: Error messageWithdrawalKey: Key required for recovery if account is in withdrawal grace period (provided only for accounts in withdrawal grace period)BlockKey: Key provided for blocked accounts (provided only for blocked accounts)
ItemModel Class
[Serializable]
public class ItemModel
{
public string currency_code;
public double currency_amount;
}
ItemsWrapper Class
[Serializable]
public class ItemsWrapper
{
public List<ItemModel> items;
}
Charge Currency Class
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class CurrencyCharge
{
static string path = "https://service-api.playnanoo.com/currency/v20221101/currency/charge";
[Serializable]
public class Req : DeviceInfo
{
public string items;
public IEnumerator Send(List<ItemModel> itemList, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if(itemList != null && itemList.Count > 0)
{
ItemsWrapper wrapper = new ItemsWrapper { items = itemList };
this.items = JsonUtility.ToJson(wrapper);
}
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public List<ItemModel> items;
}
[Serializable]
public class ItemsWrapper
{
public List<ItemModel> items;
}
[Serializable]
public class ItemModel
{
public string currency_code;
public double currency_amount;
}
}
Usage Example
public void ChargeCurrency()
{
CurrencyCharge.Req req = new CurrencyCharge.Req();
// Create list of currencies to charge
List<CurrencyCharge.ItemModel> itemList = new List<CurrencyCharge.ItemModel>
{
new CurrencyCharge.ItemModel { currency_code = "GOLD", currency_amount = 500 },
new CurrencyCharge.ItemModel { currency_code = "GEM", currency_amount = 100 }
};
StartCoroutine(req.Send(
itemList: itemList,
onSuccess: res =>
{
Debug.Log("Currency charge successful");
foreach (var item in res.items)
{
Debug.Log($"Currency code: {item.currency_code}");
Debug.Log($"Amount owned: {item.currency_amount}");
}
},
onError: error =>
{
Debug.LogError($"Currency charge failed: [{error.ErrorCode}] {error.Message}");
}
));
}
Charge Currency
This API charges the player's currency. Multiple types of currency can be charged at once, and it returns the currency list after charging in the response.
JSON Serialization
items is wrapped with ItemsWrapper and then converted to a JSON string using JsonUtility.