Skip to main content

Grant Currency

API to grant currency to the player.

URL Verification

This API uses the service-api.playnanoo.com domain.

API Information

  • URL: https://service-api.playnanoo.com/currency/v20221101/currency/put
  • 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

ParameterTypeRequiredDescription
itemsstringRequiredCurrency list (JSON string)

Response Data

Res Class

FieldTypeDescription
itemsList<ItemModel>Currency list after granting

ItemModel Class

FieldTypeDescription
currency_codestringCurrency code
currency_amountdoubleCurrency 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 code
  • Message: Error message
  • WithdrawalKey: 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;
}

Grant Currency Class

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class CurrencyPut
{
static string path = "https://service-api.playnanoo.com/currency/v20221101/currency/put";

[Serializable]
public class Req : DeviceInfo
{
public string items;

public IEnumerator Send(List<ItemModel> itemsList, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if(itemsList != null && itemsList.Count > 0)
{
ItemsWrapper wrapper = new ItemsWrapper { items = itemsList };
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 PutCurrency()
{
CurrencyPut.Req req = new CurrencyPut.Req();

// Create list of currencies to grant
List<CurrencyPut.ItemModel> itemList = new List<CurrencyPut.ItemModel>
{
new CurrencyPut.ItemModel { currency_code = "GOLD", currency_amount = 1000 },
new CurrencyPut.ItemModel { currency_code = "GEM", currency_amount = 50 }
};

StartCoroutine(req.Send(
itemsList: itemList,
onSuccess: res =>
{
Debug.Log("Grant currency 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($"Grant currency failed: [{error.ErrorCode}] {error.Message}");
}
));
}
Grant Currency

This API grants currency to the player. Multiple types of currency can be granted at once, and it returns the currency list after granting in the response.

JSON Serialization

items is wrapped with ItemsWrapper and then converted to a JSON string using JsonUtility.