Skip to content

Instantly share code, notes, and snippets.

@jonathanpeppers
Last active February 17, 2017 02:56
Show Gist options
  • Save jonathanpeppers/1c9dd0e8629f70ceddfe7a4183507048 to your computer and use it in GitHub Desktop.
Save jonathanpeppers/1c9dd0e8629f70ceddfe7a4183507048 to your computer and use it in GitHub Desktop.
Client side for calling an Azure function
//Use this as a singleton in your app
public class AzureClient
{
private const string BaseUrl = "https://YOUR_DOMAIN.azurewebsites.net/api/";
private readonly HttpClient _client = new HttpClient();
public async Task Verify(AppleReceipt receipt)
{
var content = new JsonContent(receipt);
var response = await _client.PostAsync(BaseUrl + "ios?code=YOUR_CODE_HERE", content);
response.EnsureSuccessStatusCode();
}
}
//And the remaining bit in PurchaseService
public abstract class PurchaseService
{
protected readonly AzureClient _client = new AzureClient();
public async Task Buy(Purchase purchase)
{
var receipt = await BuyNative(purchase);
var appleReceipt = receipt as AppleReceipt;
if (appleReceipt != null)
{
await _client.Verify(appleReceipt);
return;
}
//TODO: Google Play here
}
protected abstract Task<Receipt> BuyNative(Purchase purchase);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment