본문으로 건너뛰기

재화 차감

플레이어의 재화를 차감하는 API입니다.

URL 확인

이 API는 service-api.playnanoo.com 도메인을 사용합니다.

API 정보

  • URL: https://service-api.playnanoo.com/currency/v20250301/subtract
  • Method: PUT
  • 인증 필요: 예
DeviceInfo 상속

이 API의 Req 클래스는 DeviceInfo를 상속받습니다. DeviceInfo의 모든 속성이 자동으로 포함됩니다.

요청 파라미터

파라미터타입필수설명
currency_codestring필수재화 코드
currency_amountdouble필수차감할 재화 수량

응답 데이터

Res 클래스

필드타입설명
currency_amountdouble차감 후 보유 재화 수량

Unity C# 구현

BaseResponse 클래스

모든 API 응답의 기본 클래스입니다.

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

필드 설명:

  • ErrorCode: 에러 코드
  • Message: 에러 메시지
  • WithdrawalKey: 탈퇴 유예 상태인 경우 복구에 필요한 키 (탈퇴 유예 중인 계정만 제공)
  • BlockKey: 차단된 계정인 경우 제공되는 키 (차단된 계정만 제공)

재화 차감 클래스

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

public class CurrencySubtract
{
static string path = "https://service-api.playnanoo.com/currency/v20250301/subtract";

[Serializable]
public class Req : DeviceInfo
{
public string currency_code;
public double currency_amount;

public IEnumerator Send(string currencyCode, double currencyAmount, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(currencyCode)) this.currency_code = currencyCode;
this.currency_amount = currencyAmount;

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public double currency_amount;
}
}

사용 예제

public void SubtractCurrency()
{
CurrencySubtract.Req req = new CurrencySubtract.Req();

StartCoroutine(req.Send(
currencyCode: "GOLD",
currencyAmount: 100,
onSuccess: res =>
{
Debug.Log("재화 차감 성공");
Debug.Log($"차감 후 GOLD 보유량: {res.currency_amount}");
},
onError: error =>
{
Debug.LogError($"재화 차감 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
재화 부족

차감할 재화가 부족한 경우 에러가 발생합니다. 차감 전에 충분한 재화를 보유하고 있는지 확인하세요.

재화 차감

이 API는 플레이어의 재화를 차감합니다. 응답으로 차감 후 남은 재화 수량을 반환합니다.