Skip to content

Commit

Permalink
Merge pull request #381 from jamesmontemagno/android-obfuscated
Browse files Browse the repository at this point in the history
Add in obfuscated properties
  • Loading branch information
jamesmontemagno committed May 6, 2021
2 parents a85ae03 + d483ce6 commit c7362a8
Show file tree
Hide file tree
Showing 10 changed files with 963 additions and 6,610 deletions.
4 changes: 3 additions & 1 deletion docs/PurchaseConsumable.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ Consumables are unique and work a bit different on each platform and the `Consum
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="verifyPurchase">Verify Purchase implementation</param>
/// <param name="obfuscatedAccountId">Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.</param>
/// <param name="obfuscatedProfileId">Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.</param>
/// <returns>Purchase details</returns>
/// <exception cref="InAppBillingPurchaseException">If an error occures during processing</exception>
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null);
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string obfuscatedAccountId = null, string obfuscatedProfileId = null);
```

### Consume Purchase
Expand Down
4 changes: 3 additions & 1 deletion docs/PurchaseSubscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ All purchases go through the `PurchaseAsync` method and you must always `Connect
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="verifyPurchase">Verify Purchase implementation</param>
/// <param name="obfuscatedAccountId">Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.</param>
/// <param name="obfuscatedProfileId">Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.</param>
/// <returns>Purchase details</returns>
/// <exception cref="InAppBillingPurchaseException">If an error occures during processing</exception>
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null);
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string obfuscatedAccountId = null, string obfuscatedProfileId = null);
```

On Android you must call `AcknowledgePurchaseAsync` within 3 days when a purchase is validated. Please read the [Android documentation on Pending Transactions](https://developer.android.com/google/play/billing/integrate#pending) for more information.
Expand Down
7,474 changes: 902 additions & 6,572 deletions src/InAppBillingTests/InAppBillingTests.Android/Resources/Resource.designer.cs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Plugin.InAppBilling/Converters.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public static InAppBillingPurchase ToIABPurchase(this Purchase purchase)
Payload = purchase.DeveloperPayload,
ProductId = purchase.Sku,
PurchaseToken = purchase.PurchaseToken,
TransactionDateUtc = DateTimeOffset.FromUnixTimeMilliseconds(purchase.PurchaseTime).DateTime
TransactionDateUtc = DateTimeOffset.FromUnixTimeMilliseconds(purchase.PurchaseTime).DateTime,
ObfuscatedAccountId = purchase.AccountIdentifiers?.ObfuscatedAccountId,
ObfuscatedProfileId = purchase.AccountIdentifiers?.ObfuscatedProfileId
};

finalPurchase.State = purchase.PurchaseState switch
Expand Down
24 changes: 16 additions & 8 deletions src/Plugin.InAppBilling/InAppBilling.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ public override Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemTy
/// </summary>
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="payload">Developer specific payload (can not be null)</param>
/// <param name="verifyPurchase">Interface to verify purchase</param>
/// <param name="obfuscatedAccountId">Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.</param>
/// <param name="obfuscatedProfileId">Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.</param>
/// <returns></returns>
public async override Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null)
public async override Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string obfuscatedAccountId = null, string obfuscatedProfileId = null)
{
if (BillingClient == null || !IsConnected)
{
Expand All @@ -213,18 +214,18 @@ public async override Task<InAppBillingPurchase> PurchaseAsync(string productId,
switch (itemType)
{
case ItemType.InAppPurchase:
return await PurchaseAsync(productId, BillingClient.SkuType.Inapp, verifyPurchase);
return await PurchaseAsync(productId, BillingClient.SkuType.Inapp, verifyPurchase, obfuscatedAccountId, obfuscatedProfileId);
case ItemType.Subscription:

var result = BillingClient.IsFeatureSupported(BillingClient.FeatureType.Subscriptions);
ParseBillingResult(result);
return await PurchaseAsync(productId, BillingClient.SkuType.Subs, verifyPurchase);
return await PurchaseAsync(productId, BillingClient.SkuType.Subs, verifyPurchase, obfuscatedAccountId, obfuscatedProfileId);
}

return null;
}

async Task<InAppBillingPurchase> PurchaseAsync(string productSku, string itemType, IInAppBillingVerifyPurchase verifyPurchase)
async Task<InAppBillingPurchase> PurchaseAsync(string productSku, string itemType, IInAppBillingVerifyPurchase verifyPurchase, string obfuscatedAccountId = null, string obfuscatedProfileId = null)
{

var skuDetailsParams = SkuDetailsParams.NewBuilder()
Expand All @@ -240,9 +241,16 @@ async Task<InAppBillingPurchase> PurchaseAsync(string productSku, string itemTyp
if (skuDetails == null)
throw new ArgumentException($"{productSku} does not exist");

var flowParams = BillingFlowParams.NewBuilder()
.SetSkuDetails(skuDetails)
.Build();
var flowParamsBuilder = BillingFlowParams.NewBuilder()
.SetSkuDetails(skuDetails);

if (!string.IsNullOrWhiteSpace(obfuscatedAccountId))
flowParamsBuilder.SetObfuscatedAccountId(obfuscatedAccountId);

if (!string.IsNullOrWhiteSpace(obfuscatedProfileId))
flowParamsBuilder.SetObfuscatedProfileId(obfuscatedProfileId);

var flowParams = flowParamsBuilder.Build();

tcsPurchase = new TaskCompletionSource<(BillingResult billingResult, IList<Android.BillingClient.Api.Purchase> purchases)>();
var responseCode = BillingClient.LaunchBillingFlow(Activity, flowParams);
Expand Down
19 changes: 10 additions & 9 deletions src/Plugin.InAppBilling/InAppBilling.apple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,16 @@ static SKPaymentTransaction FindOriginalTransaction(SKPaymentTransaction transac



/// <summary>
/// Purchase a specific product or subscription
/// </summary>
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="payload">Developer specific payload</param>
/// <param name="verifyPurchase">Interface to verify purchase</param>
/// <returns></returns>
public async override Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null)
/// <summary>
/// Purchase a specific product or subscription
/// </summary>
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="verifyPurchase">Interface to verify purchase</param>
/// <param name="obfuscatedAccountId">Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.</param>
/// <param name="obfuscatedProfileId">Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.</param>
/// <returns></returns>
public async override Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string obfuscatedAccountId = null, string obfuscatedProfileId = null)
{
var p = await PurchaseAsync(productId);

Expand Down
5 changes: 3 additions & 2 deletions src/Plugin.InAppBilling/InAppBilling.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ public async override Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(
/// </summary>
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="payload">Developer specific payload</param>
/// <param name="verifyPurchase">Verify purchase implementation</param>
/// <param name="obfuscatedAccountId">Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.</param>
/// <param name="obfuscatedProfileId">Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.</param>
/// <returns></returns>
/// <exception cref="InAppBillingPurchaseException">If an error occurs during processing</exception>
public async override Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null)
public async override Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string obfuscatedAccountId = null, string obfuscatedProfileId = null)
{
// Get purchase result from store or simulator
var purchaseResult = await CurrentAppMock.RequestProductPurchaseAsync(InTestingMode, productId);
Expand Down
21 changes: 11 additions & 10 deletions src/Plugin.InAppBilling/Shared/BaseInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ public abstract class BaseInAppBilling : IInAppBilling, IDisposable
/// <returns>The current purchases</returns>
public abstract Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemType itemType);

/// <summary>
/// Purchase a specific product or subscription
/// </summary>
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="payload">Developer specific payload</param>
/// <param name="verifyPurchase">Verify Purchase implementation</param>
/// <returns>Purchase details</returns>
/// <exception cref="InAppBillingPurchaseException">If an error occures during processing</exception>
public abstract Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null);
/// <summary>
/// Purchase a specific product or subscription
/// </summary>
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="verifyPurchase">Verify Purchase implementation</param>
/// <param name="obfuscatedAccountId">Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.</param>
/// <param name="obfuscatedProfileId">Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.</param>
/// <returns>Purchase details</returns>
/// <exception cref="InAppBillingPurchaseException">If an error occures during processing</exception>
public abstract Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string obfuscatedAccountId = null, string obfuscatedProfileId = null);

/// <summary>
/// Consume a purchase with a purchase token.
Expand Down
5 changes: 3 additions & 2 deletions src/Plugin.InAppBilling/Shared/IInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ public interface IInAppBilling : IDisposable
/// </summary>
/// <param name="productId">Sku or ID of product</param>
/// <param name="itemType">Type of product being requested</param>
/// <param name="payload">Developer specific payload (can not be null)</param>
/// <param name="verifyPurchase">Verify Purchase implementation</param>
/// <param name="obfuscatedAccountId">Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.</param>
/// <param name="obfuscatedProfileId">Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.</param>
/// <returns>Purchase details</returns>
/// <exception cref="InAppBillingPurchaseException">If an error occures during processing</exception>
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null);
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null, string obfuscatedAccountId = null, string obfuscatedProfileId = null);

/// <summary>
/// Consume a purchase with a purchase token.
Expand Down
13 changes: 9 additions & 4 deletions src/Plugin.InAppBilling/Shared/InAppBillingPurchase.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public InAppBillingPurchase()
{
}


/// <summary>
/// Purchase/Order Id
/// </summary>
Expand Down Expand Up @@ -62,6 +63,10 @@ public InAppBillingPurchase()

public bool IsAcknowledged { get; set; }

public string ObfuscatedAccountId { get; set; }

public string ObfuscatedProfileId { get; set; }

/// <summary>
/// Developer payload
/// </summary>
Expand All @@ -77,18 +82,18 @@ public InAppBillingPurchase()
(obj is InAppBillingPurchase purchase) && Equals(purchase);

public bool Equals(InAppBillingPurchase other) =>
(Id, TransactionDateUtc, IsAcknowledged, ProductId, AutoRenewing, PurchaseToken, State, Payload) ==
(other.Id, other.TransactionDateUtc, other.IsAcknowledged, other.ProductId, other.AutoRenewing, other.PurchaseToken, other.State, other.Payload);
(Id, TransactionDateUtc, IsAcknowledged, ProductId, AutoRenewing, PurchaseToken, State, Payload, ObfuscatedAccountId, ObfuscatedProfileId) ==
(other.Id, other.TransactionDateUtc, other.IsAcknowledged, other.ProductId, other.AutoRenewing, other.PurchaseToken, other.State, other.Payload, other.ObfuscatedAccountId, other.ObfuscatedProfileId);

public override int GetHashCode() =>
(Id, TransactionDateUtc, IsAcknowledged, ProductId, AutoRenewing, PurchaseToken, State, Payload).GetHashCode();
(Id, TransactionDateUtc, IsAcknowledged, ProductId, AutoRenewing, PurchaseToken, State, Payload, ObfuscatedAccountId, ObfuscatedProfileId).GetHashCode();

/// <summary>
/// Prints out product
/// </summary>
/// <returns></returns>
public override string ToString() =>
$"ProductId:{ProductId}| IsAcknowledged:{IsAcknowledged} | AutoRenewing:{AutoRenewing} | State:{State} | Id:{Id}";
$"{nameof(ProductId)}:{ProductId}| {nameof(IsAcknowledged)}:{IsAcknowledged} | {nameof(AutoRenewing)}:{AutoRenewing} | {nameof(State)}:{State} | {nameof(Id)}:{Id} | {nameof(ObfuscatedAccountId)}:{ObfuscatedAccountId} | {nameof(ObfuscatedProfileId)}:{ObfuscatedProfileId} ";

}

Expand Down

0 comments on commit c7362a8

Please sign in to comment.