private async Task ConsumePurchaseAsync(string token) { ConsumeParams consumeParams = ConsumeParams.NewBuilder() .SetPurchaseToken(token) .Build(); // Consume the Consumable Product ConsumeResult consumeResult = await _billingClient.ConsumeAsync(consumeParams); BillingResult result = consumeResult?.BillingResult; if (result == null) { // Failed to get result back. throw new InAppPurchaseException(PurchaseError.Unknown, "BillingResult is null"); } if (result.ResponseCode != BillingResponseCode.Ok) { throw new InAppPurchaseException( result.ResponseCode.ToPurchaseError(), result.DebugMessage); } // Otherwise, the ConsumeAsync succeeded. }
private void ConsumePurchase(Purchase purchase) { if (!purchase.IsAcknowledged) { var cParams = ConsumeParams.NewBuilder() .SetPurchaseToken(purchase.PurchaseToken) .Build(); billingClient.Consume(cParams, this); } }
/// <summary> /// Completes Consume purchase with Api request /// </summary> /// <param name="purchaseToken"></param> /// <param name="payload"></param> /// <returns></returns> private async Task <PurchaseResult> CompleteConsume(string purchaseToken, string payload = null) { _tcsConsume = new TaskCompletionSource <PurchaseResult>(); var consumeParams = ConsumeParams.NewBuilder().SetPurchaseToken(purchaseToken); if (payload != null) { consumeParams.SetDeveloperPayload(payload); } BillingClient.ConsumeAsync(consumeParams.Build(), this); return(await _tcsConsume?.Task); }
public Task <ConsumeResult> ConsumeAsync(ConsumeParams consumeParams) { var tcs = new TaskCompletionSource <ConsumeResult>(); var listener = new InternalConsumeResponseListener { ConsumeResponseHandler = (r, s) => tcs.TrySetResult(new ConsumeResult { BillingResult = r, PurchaseToken = s }) }; Consume(consumeParams, listener); return(tcs.Task); }