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
//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); | |
} | |
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"; |
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"; |
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
//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); |
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
# Google Play Billing | |
-keep class com.android.vending.billing.** |
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
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; |
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
public class BillingConnection : Java.Lang.Object, IServiceConnection | |
{ | |
private TaskCompletionSource<bool> _connectSource; | |
public IInAppBillingService Service | |
{ | |
get; | |
private set; | |
} |
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
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; } |
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
#!/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" |
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
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 |