Validate an #IAP Receipt from #Apple
If you accept In app purchases in your app, and particularly subscription payments, then you might need to know if a user cancels their subscription, so you can close their account. To do this, you need to store the receipt returned by storekit, and periodically check it for validity.
Here is a tool to do so: http://iapreceipt.apixml.net/ – it’s written in C# and here’s the code below;
private string Verify(string receipt, string serviceUrl, string sharedSecret)
{
var json = string.Format(“{{\”receipt-data\”:\”{0}\”,\”password\”:\”{1}\”}}”, receipt, sharedSecret);
var wr = WebRequest.Create(serviceUrl);
wr.ContentType = “text/plain”;
wr.Method = “POST”;
var sw = new System.IO.StreamWriter(wr.GetRequestStream());
sw.Write(json);
sw.Flush();
sw.Close();
var wresp = wr.GetResponse();
if (wresp != null)
{
var sr = new System.IO.StreamReader(wresp.GetResponseStream());
var response = sr.ReadToEnd();
sr.Close();
return response;
}
return “no-data”;
}