From fc0cc0fc4d3f250aec11a2823ccc6580513b4f21 Mon Sep 17 00:00:00 2001 From: stevewinn74 <69214831+stevewinn74@users.noreply.github.com> Date: Tue, 1 Sep 2020 21:26:29 +0200 Subject: [PATCH 1/2] Update InAppBilling.apple.cs Hopefully will return a Token for a restored purchase on iOS --- src/Plugin.InAppBilling/InAppBilling.apple.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Plugin.InAppBilling/InAppBilling.apple.cs b/src/Plugin.InAppBilling/InAppBilling.apple.cs index f0caf42..db632ca 100644 --- a/src/Plugin.InAppBilling/InAppBilling.apple.cs +++ b/src/Plugin.InAppBilling/InAppBilling.apple.cs @@ -505,15 +505,24 @@ public static InAppBillingPurchase ToIABPurchase(this SKPaymentTransaction trans if (p == null) return null; + string _purchaseToken = null; + if (String.IsNullOrEmpty(p.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None))) + { + _purchaseToken = transaction.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None); + } + else + { + _purchaseToken = p.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None); + } - return new InAppBillingPurchase + return new InAppBillingPurchase { TransactionDateUtc = NSDateToDateTimeUtc(transaction.TransactionDate), Id = p.TransactionIdentifier, ProductId = p.Payment?.ProductIdentifier ?? string.Empty, State = p.GetPurchaseState(), - PurchaseToken = p.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None) ?? string.Empty - }; + PurchaseToken = _purchaseToken + }; } static DateTime NSDateToDateTimeUtc(NSDate date) From fb190945071094ffae8500fa71763f7194ce73c8 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Tue, 1 Sep 2020 13:47:39 -0700 Subject: [PATCH 2/2] Simplify logic --- src/Plugin.InAppBilling/InAppBilling.apple.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Plugin.InAppBilling/InAppBilling.apple.cs b/src/Plugin.InAppBilling/InAppBilling.apple.cs index db632ca..c85cb5d 100644 --- a/src/Plugin.InAppBilling/InAppBilling.apple.cs +++ b/src/Plugin.InAppBilling/InAppBilling.apple.cs @@ -505,15 +505,9 @@ public static InAppBillingPurchase ToIABPurchase(this SKPaymentTransaction trans if (p == null) return null; - string _purchaseToken = null; - if (String.IsNullOrEmpty(p.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None))) - { - _purchaseToken = transaction.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None); - } - else - { - _purchaseToken = p.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None); - } + var finalToken = p.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None); + if (string.IsNullOrEmpty(finalToken)) + finalToken = transaction.TransactionReceipt?.GetBase64EncodedString(NSDataBase64EncodingOptions.None); return new InAppBillingPurchase { @@ -521,8 +515,8 @@ public static InAppBillingPurchase ToIABPurchase(this SKPaymentTransaction trans Id = p.TransactionIdentifier, ProductId = p.Payment?.ProductIdentifier ?? string.Empty, State = p.GetPurchaseState(), - PurchaseToken = _purchaseToken - }; + PurchaseToken = finalToken + }; } static DateTime NSDateToDateTimeUtc(NSDate date)