본문으로 건너뛰기

iOS 영수증 검증

iOS 인앱 결제(IAP) 영수증을 검증하는 API입니다.

URL 확인

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

API 정보

  • URL: https://service-api.playnanoo.com/iap/v20221001/unity/ios
  • Method: PUT
  • 인증 필요: 예

요청 파라미터

파라미터타입필수설명
receiptstring필수영수증 정보
product_idstring필수결제 상품 아이디
currencystring필수화폐 코드 (KRW, JPY, USD, CNY...)
pricestring필수결제 금액
duplicate_allowstring필수영수증 중복 검증 허용 여부 (Y/N)

응답 데이터

Res 클래스

필드타입설명
UserIDstring사용자 ID
PackageNamestring패키지 이름
OrderIDstring주문 ID
ProductIDstring상품 ID
Currencystring통화 코드
Pricestring가격

Unity C# 구현

BaseResponse 클래스

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

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

필드 설명:

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

iOS IAP 검증 클래스

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

public class IAPUnityIOS
{
static string path = "https://service-api.playnanoo.com/iap/v20221001/unity/ios";

[Serializable]
public class Req
{
public string receipt; // 영수증 정보
public string product_id; // 결제 상품 아이디
public string currency; // 화폐 코드 (KRW, JPY, USD, CNY...)
public string price; // 결제 금액
public string duplicate_allow; // 영수증 중복 검증 허용 여부

public IEnumerator Send(string receipt, string product_id, string currency, string price, bool duplicate_allow, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(receipt)) this.receipt = receipt;
if (!string.IsNullOrEmpty(product_id)) this.product_id = product_id;
if (!string.IsNullOrEmpty(currency)) this.currency = currency;
if (!string.IsNullOrEmpty(price)) this.price = price;
this.duplicate_allow = duplicate_allow ? "Y" : "N";

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

[Serializable]
public class Res : BaseResponse
{
public string UserID;
public string PackageName;
public string OrderID;
public string ProductID;
public string Currency;
public string Price;
}
}

사용 예제

public void ValidateIOSIAP()
{
IAPUnityIOS.Req req = new IAPUnityIOS.Req();

// App Store 결제 정보
string receipt = "Base64EncodedReceiptData==";
string productId = "com.example.game.gold_100";
string currency = "USD";
string price = "0.99";

StartCoroutine(req.Send(
receipt: receipt,
product_id: productId,
currency: currency,
price: price,
duplicate_allow: false, // 중복 영수증 허용 안 함
onSuccess: res =>
{
Debug.Log($"IAP 검증 성공");
Debug.Log($"사용자 ID: {res.UserID}");
Debug.Log($"주문 ID: {res.OrderID}");
Debug.Log($"상품 ID: {res.ProductID}");
Debug.Log($"가격: {res.Price} {res.Currency}");
},
onError: (error) =>
{
Debug.LogError($"IAP 검증 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
영수증 중복 검증

duplicate_allow를 false로 설정하면 동일한 영수증으로 중복 검증이 불가능합니다. 테스트 환경에서는 true로 설정하여 중복 검증을 허용할 수 있습니다.

App Store 영수증

receipt는 StoreKit에서 제공하는 Base64로 인코딩된 영수증 데이터입니다. 영수증 데이터는 appStoreReceiptURL을 통해 얻을 수 있습니다.

가격 정보

price는 실제 결제된 금액을 문자열로 전달해야 합니다. currency는 ISO 4217 통화 코드를 사용합니다.