Created
February 16, 2017 22:12
-
-
Save jonathanpeppers/a34dc429f41e27dd160d3c4ba975d1ab to your computer and use it in GitHub Desktop.
Azure Function for Apple IAPs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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