Exemplo n.º 1
0
        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.
        }
Exemplo n.º 2
0
 private void ConsumePurchase(Purchase purchase)
 {
     if (!purchase.IsAcknowledged)
     {
         var cParams =
             ConsumeParams.NewBuilder()
             .SetPurchaseToken(purchase.PurchaseToken)
             .Build();
         billingClient.Consume(cParams, this);
     }
 }
Exemplo n.º 3
0
        /// <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);
        }