//My validator
public static async Task<AppleValidationResult> ValidateReceiptAsync(string base64Receipt)
{
var requestJson = new JObject
{
["receipt-data"] = base64Receipt,
["password"] = SharedSecret
};
var content = new StringContent(requestJson.ToString(), Encoding.UTF8, "application/json");
// First try production
var response = await client.PostAsync(ProductionUrl, content);
var json = JObject.Parse(await response.Content.ReadAsStringAsync());
int status = (int) json["status"];
if (status == 21007) // Receipt from sandbox
{
response = await client.PostAsync(SandboxUrl, content);
json = JObject.Parse(await response.Content.ReadAsStringAsync());
status = (int) json["status"];
Debug.Log("status=" + status);
}
Debug.Log("status="+status);
if (status != 0)
return new AppleValidationResult { Valid = false };
// Get the last in-app purchase
var latestReceipt = json["receipt"]?["in_app"]?.Last;
Debug.Log("latest receipt = " + latestReceipt!=null);
if (latestReceipt == null)
return new AppleValidationResult { Valid = false };
return new AppleValidationResult
{
Valid = true,
TransactionId = latestReceipt["transaction_id"]?.ToString(),
ProductId = latestReceipt["product_id"]?.ToString()
};
}
Topic:
App & System Services
SubTopic:
StoreKit