Skip to main content

iOS Receipt Validation

API for validating iOS In-App Purchase (IAP) receipts.

URL Verification

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

When using Unity IAP 5.0 (StoreKit 2)

This API (v20221001) validates Base64 receipts from Unity IAP 4.x (StoreKit 1). If you have migrated to Unity IAP 5.0 (StoreKit 2), use iOS Receipt Validation (StoreKit 2) which validates the signed transaction (JWS).

API Information

  • URL: https://service-api.playnanoo.com/iap/v20221001/unity/ios
  • Method: PUT
  • Authentication Required: Yes

Request Parameters

ParameterTypeRequiredDescription
receiptstringRequiredReceipt information
product_idstringRequiredProduct ID for payment
currencystringRequiredCurrency code (KRW, JPY, USD, CNY...)
pricestringRequiredPayment amount
duplicate_allowstringRequiredAllow duplicate receipt validation (Y/N)

Response Data

Res Class

FieldTypeDescription
UserIDstringUser ID
PackageNamestringPackage name
OrderIDstringOrder ID
ProductIDstringProduct ID
CurrencystringCurrency code
PricestringPrice

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 when account is in withdrawal grace period (provided only for accounts in withdrawal grace period)
  • BlockKey: Key provided when account is blocked (provided only for blocked accounts)

iOS IAP Validation Class

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; // Receipt information
public string product_id; // Product ID for payment
public string currency; // Currency code (KRW, JPY, USD, CNY...)
public string price; // Payment amount
public string duplicate_allow; // Allow duplicate receipt validation

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

Usage Example

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

// App Store payment information
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, // Do not allow duplicate receipts
onSuccess: res =>
{
Debug.Log($"IAP validation successful");
Debug.Log($"User ID: {res.UserID}");
Debug.Log($"Order ID: {res.OrderID}");
Debug.Log($"Product ID: {res.ProductID}");
Debug.Log($"Price: {res.Price} {res.Currency}");
},
onError: (error) =>
{
Debug.LogError($"IAP validation failed: [{error.ErrorCode}] [{error.Message}]");
}
));
}
Duplicate Receipt Validation

If duplicate_allow is set to false, duplicate validation with the same receipt is not possible. In a test environment, you can set it to true to allow duplicate validation.

App Store Receipt

The receipt is Base64-encoded receipt data provided by StoreKit. Receipt data can be obtained through appStoreReceiptURL.

Price Information

The price must be passed as a string with the actual payment amount. Currency uses ISO 4217 currency codes.