Skip to content

Instantly share code, notes, and snippets.

View jonathanpeppers's full-sized avatar
🌶️
spicy!

Jonathan Peppers jonathanpeppers

🌶️
spicy!
View GitHub Profile
@jonathanpeppers
jonathanpeppers / ApplePurchaseService.cs
Last active February 16, 2017 22:56
ApplePurchaseService - Buy
//NOTE: should be a singleton for your entire app
public class ApplePurchaseService : PurchaseService
{
private readonly ObserverDelegate _observer = new ObserverDelegate();
public ApplePurchaseService()
{
SKPaymentQueue.DefaultQueue.AddTransactionObserver(_observer);
}
@jonathanpeppers
jonathanpeppers / run.csx
Last active February 16, 2017 22:13
Apple IAP receipt verification
#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";
@jonathanpeppers
jonathanpeppers / run.csx
Created February 16, 2017 22:12
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";
@jonathanpeppers
jonathanpeppers / AzureClient.cs
Last active February 17, 2017 02:56
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);
@jonathanpeppers
jonathanpeppers / Proguard.cfg
Created March 16, 2017 12:36
Proguard file for Google Play Billing
# Google Play Billing
-keep class com.android.vending.billing.**
@jonathanpeppers
jonathanpeppers / BillingConstants.cs
Created March 21, 2017 17:25
BillingConstants for Google Play
public class BillingConstants
{
public const int ApiVersion = 3;
// Billing response codes
public const int ResultOk = 0;
public const int ResultUserCancelled = 1;
public const int ResultBillingUnavailable = 3;
public const int ResultItemUnavailable = 4;
public const int ResultDeveloperError = 5;
@jonathanpeppers
jonathanpeppers / BillingConnection.cs
Created March 21, 2017 17:28
BillingConnection for Google Play
public class BillingConnection : Java.Lang.Object, IServiceConnection
{
private TaskCompletionSource<bool> _connectSource;
public IInAppBillingService Service
{
get;
private set;
}
@jonathanpeppers
jonathanpeppers / GooglePlayPurchaseService.cs
Last active June 7, 2019 19:15
GooglePlayPurchaseService - GetPrices
public class GooglePlayPurchaseService : PurchaseService
{
private BillingConnection _connection;
private sealed class Product
{
public string Title { get; set; }
public string Price { get; set; }
public string Type { get; set; }
public string Description { get; set; }
@jonathanpeppers
jonathanpeppers / debug.sh
Created May 5, 2017 16:09
Android debug key generator - takes a Google Play keystore and converts it to one that can be used for debugging
#!/bin/bash
# Change these variables for your keystore
KEYSTORE="iap.keystore"
ALIAS="iap"
PASSWORD="YOUR_KEYSTORE_PASSWORD"
# These are variables that Xamarin.Android expects
OUT_KEYSTORE="debug.keystore"
OUT_ALIAS="androiddebugkey"
@jonathanpeppers
jonathanpeppers / GooglePlayPurchaseService.cs
Last active May 5, 2017 19:41
Google Play PurchaseService.BuyNative
protected async override Task<Receipt> BuyNative(Purchase purchase)
{
var context = (Activity)Xamarin.Forms.Forms.Context;
string developerPayload = Guid.NewGuid().ToString("N");
var buyIntent = _connection.Service.GetBuyIntent(BillingConstants.ApiVersion, context.PackageName, purchase.Id, BillingConstants.ItemTypeInApp, developerPayload);
int response = buyIntent.GetInt(BillingConstants.ResponseCode);
if (response != BillingConstants.ResultOk)
{
//NOTE: see my full example for handling BillingConstants.ResultItemAlreadyOwned