PageRenderTime 11ms CodeModel.GetById 5ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/VerifyReceipt/ReceiptVerification.cs

https://bitbucket.org/johnboker/verifyreceipt
C# | 35 lines | 33 code | 2 blank | 0 comment | 2 complexity | 3154d59647a585ce44d51be6f07b2f85 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Net;
 5using System.Text;
 6
 7namespace VerifyReceipt
 8{
 9    public class ReceiptVerification
10    {
11        private const string urlProduction = "https://buy.itunes.apple.com/verifyReceipt";
12        
13        public static string Verify(string receipt)
14        {
15            var receipt64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(receipt));
16            var json = string.Format("{{\"receipt-data\":\"{0}\"}}", receipt64);
17            var wr = WebRequest.Create(urlProduction);
18            wr.ContentType = "text/plain";
19            wr.Method = "POST";
20            var sw = new System.IO.StreamWriter(wr.GetRequestStream());
21            sw.Write(json);
22            sw.Flush();
23            sw.Close();
24            var wresp = wr.GetResponse();
25            if (wresp != null)
26            {
27                var sr = new System.IO.StreamReader(wresp.GetResponseStream());
28                var response = sr.ReadToEnd();
29                sr.Close();
30                return response;
31            }
32            return "no-data";
33        }
34    }
35}