Skip to content

Commit

Permalink
Merge pull request #185 from jamesmontemagno/bug/issue-102
Browse files Browse the repository at this point in the history
Add FinishTransaction to force a FinishTransaction on iOS if things g…
  • Loading branch information
jamesmontemagno committed Sep 28, 2018
2 parents 08571bc + 675e374 commit 91e35bb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Plugin.InAppBilling.Abstractions/BaseInAppBilling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,9 @@ public virtual void Dispose(bool disposing)
disposed = true;
}
}
}

public virtual Task<bool> FinishTransaction(InAppBillingPurchase purchase) => Task.FromResult(true);

public virtual Task<bool> FinishTransaction(string purchaseId) => Task.FromResult(true);
}
}
7 changes: 6 additions & 1 deletion src/Plugin.InAppBilling.Abstractions/IInAppBilling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ public interface IInAppBilling : IDisposable
/// <returns>If consumed successful</returns>
/// <exception cref="InAppBillingPurchaseException">If an error occures during processing</exception>
Task<InAppBillingPurchase> ConsumePurchaseAsync(string productId, ItemType itemType, string payload, IInAppBillingVerifyPurchase verifyPurchase = null);
}

Task<bool> FinishTransaction(InAppBillingPurchase purchase);

Task<bool> FinishTransaction(string purchaseId);

}
}
24 changes: 23 additions & 1 deletion src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Task<IEnumerable<SKProduct>> GetProductAsync(string[] productId)


/// <summary>
/// Get all current purhcase for a specifiy product type.
/// Get all current purchase for a specifiy product type.
/// </summary>
/// <param name="itemType">Type of product</param>
/// <param name="verifyPurchase">Interface to verify purchase</param>
Expand Down Expand Up @@ -310,6 +310,28 @@ Task<SKPaymentTransaction> PurchaseAsync(string productId)
public override Task<InAppBillingPurchase> ConsumePurchaseAsync(string productId, ItemType itemType, string payload, IInAppBillingVerifyPurchase verifyPurchase = null) =>
null;

public override Task<bool> FinishTransaction(InAppBillingPurchase purchase) =>
FinishTransaction(purchase?.Id);

public override async Task<bool> FinishTransaction(string purchaseId)
{
if (string.IsNullOrWhiteSpace(purchaseId))
throw new ArgumentException("PurchaseId must be valid", nameof(purchaseId));

var purchases = await RestoreAsync();

if (purchases == null)
return false;

var transaction = purchases.Where(p => p.TransactionIdentifier == purchaseId).FirstOrDefault();
if (transaction == null)
return false;

SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);

return true;
}

PaymentObserver paymentObserver;

static DateTime NSDateToDateTimeUtc(NSDate date)
Expand Down

0 comments on commit 91e35bb

Please sign in to comment.