Skip to content

Instantly share code, notes, and snippets.

@jonathanpeppers
Created February 16, 2017 22:12
Show Gist options
  • Save jonathanpeppers/a34dc429f41e27dd160d3c4ba975d1ab to your computer and use it in GitHub Desktop.
Save jonathanpeppers/a34dc429f41e27dd160d3c4ba975d1ab to your computer and use it in GitHub Desktop.
Azure Function for Apple IAPs
#r "Newtonsoft.Json"
#load "models.csx"
#load "AppleReceipt.cs"
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
private const string AppleProductionUrl = "https://buy.itunes.apple.com/verifyReceipt";
private const string AppleTestUrl = "https://sandbox.itunes.apple.com/verifyReceipt";
private static HttpClient _client = new HttpClient();
private static JsonSerializer _serializer = new JsonSerializer();
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var receipt = await req.Content.ReadAsAsync<AppleReceipt>();
if (string.IsNullOrEmpty(receipt.Id) || string.IsNullOrEmpty(receipt.TransactionId) || receipt.Data == null)
return req.CreateResponse(HttpStatusCode.BadRequest);
log.Info($"IAP receipt: {receipt.Id}, {receipt.TransactionId}");
//Code here either returns 200 OK or 400 Bad Request
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment