iOS Receipt Validation
API for validating iOS In-App Purchase (IAP) receipts.
This API uses the service-api.playnanoo.com domain.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
| receipt | string | Required | Receipt information |
| product_id | string | Required | Product ID for payment |
| currency | string | Required | Currency code (KRW, JPY, USD, CNY...) |
| price | string | Required | Payment amount |
| duplicate_allow | string | Required | Allow duplicate receipt validation (Y/N) |
Response Data
Res Class
| Field | Type | Description |
|---|---|---|
| UserID | string | User ID |
| PackageName | string | Package name |
| OrderID | string | Order ID |
| ProductID | string | Product ID |
| Currency | string | Currency code |
| Price | string | Price |
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 codeMessage: Error messageWithdrawalKey: 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}]");
}
));
}
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.
The receipt is Base64-encoded receipt data provided by StoreKit. Receipt data can be obtained through appStoreReceiptURL.
The price must be passed as a string with the actual payment amount. Currency uses ISO 4217 currency codes.