쿠폰 사용
쿠폰 코드를 사용하여 보상을 받는 API입니다.
URL 확인
이 API는 service-api.playnanoo.com 도메인을 사용합니다.
API 정보
- URL:
https://service-api.playnanoo.com/coupon/v20240301/search - Method:
PUT - 인증 필요: 예
요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
| code | string | 필수 | 사용할 쿠폰 코드 |
응답 데이터
Res 클래스
| 필드 | 타입 | 설명 |
|---|---|---|
| Items | SerializeReward[] | 보상 아이템 목록 |
SerializeReward 구조
| 필드 | 타입 | 설명 |
|---|---|---|
| item_code | string | 아이템 코드 |
| item_count | double | 아이템 수량 |
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 System.Collections.Generic;
using UnityEngine.Networking;
public class CouponUse
{
static string url = "https://service-api.playnanoo.com/coupon/v20240301/search";
[Serializable]
public class Req : DeviceInfo
{
public string code;
public IEnumerator Send(
string coupon_code,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(coupon_code)) this.code = coupon_code;
// PUT 방식 호출
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
url,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public List<SerializeReward> Items;
}
[Serializable]
public class SerializeReward
{
public string item_code;
public double item_count;
}
}
사용 예제
public void UseCoupon()
{
CouponUse.Req req = new CouponUse.Req();
StartCoroutine(req.Send(
coupon_code: "PLAYNANOO2024",
onSuccess: res =>
{
// 보상 정보
foreach (var item in res.Items)
{
Debug.Log($"보상: {item.item_code} x{item.item_count}");
}
},
onError: (error) =>
{
Debug.LogError($"쿠폰 사용 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
쿠폰 코드
쿠폰 코드는 대소문자를 구분하며, 일회성 또는 다회성으로 설정될 수 있습니다.