Skip to main content

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

ParameterTypeRequiredDescription
itemsstringRequiredCurrency list (JSON string)

Response Data

Res Class

FieldTypeDescription
itemsList<ItemModel>Currency list after charging

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;
}

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.