Skip to content

Commit

Permalink
Merge branch 'master' into mk/symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Feb 13, 2022
2 parents fbaa178 + cda438b commit ee0b93f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Get started by reading through the [In-App Billing Plugin documentation](https:/

There are changes in version 4.0 so read below.

Source code reference -> https://github.com/jamesmontemagno/app-ac-islandtracker/blob/freemium/TurnipTracker/ViewModel/ProViewModel.cs
Source code reference of non-conumables -> https://github.com/jamesmontemagno/app-ac-islandtracker/blob/freemium/TurnipTracker/ViewModel/ProViewModel.cs
Full blog on subscriptions: https://montemagno.com/ios-android-subscription-implemenation-strategies/

## NuGet
* NuGet: [Plugin.InAppBilling](https://www.nuget.org/packages/Plugin.InAppBilling) [![NuGet](https://img.shields.io/nuget/v/Plugin.InAppBilling.svg?label=NuGet)](https://www.nuget.org/packages/Plugin.InAppBilling/)
Expand Down
1 change: 1 addition & 0 deletions docs/PurchaseSubscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public async Task<bool> PurchaseItem(string productId, string payload)
}
```

* [The Ultimate Guide to iOS Subscription Testing](https://www.revenuecat.com/blog/the-ultimate-guide-to-subscription-testing-on-ios) **PLEASE READ for iOS Testing**
Learn more about `IInAppBillingVerifyPurchase` in the [Securing Purchases](SecuringPurchases.md) documentation.

Expand Down
3 changes: 3 additions & 0 deletions docs/TestingAndTroubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ Integrating and testing In-App Purchases is not an easy task and should go throu


## iOS Testing & Troubleshooting
* [The Ultimate Guide to iOS Subscription Testing](https://www.revenuecat.com/blog/the-ultimate-guide-to-subscription-testing-on-ios) **PLEASE READ**
* Read the iOS developer [In App Purchases API Docs](https://developer.apple.com/in-app-purchase/)
* Read all parts of the [setup from Xamarin documentation](https://developer.xamarin.com/guides/ios/application_fundamentals/in-app_purchasing/part_1_-_in-app_purchase_basics_and_configuration/), which are great.
* You must setup an in app purchase and understand what each of them are.
* Read through the [testing documentation](https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnectInAppPurchase_Guide/Chapters/TestingInAppPurchases.html#//apple_ref/doc/uid/TP40013727-CH4-SW1)



### Ensure Contracts are Signed
You will not be able to test any StoreKit functionality until you have an iOS Paid Applications contract – StoreKit calls in your code will fail until Apple has processed your Contracts, Tax, and Banking information.

Expand Down
17 changes: 17 additions & 0 deletions src/Plugin.InAppBilling/Converters.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,22 @@ public static InAppBillingPurchase ToIABPurchase(this Purchase purchase)
};
return finalPurchase;
}

public static InAppBillingPurchase ToIABPurchase(this PurchaseHistoryRecord purchase)
{
return new InAppBillingPurchase
{
ConsumptionState = ConsumptionState.NoYetConsumed,
OriginalJson = purchase.OriginalJson,
Signature = purchase.Signature,
Payload = purchase.DeveloperPayload,
ProductId = purchase.Skus.FirstOrDefault(),
Quantity = purchase.Quantity,
ProductIds = purchase.Skus,
PurchaseToken = purchase.PurchaseToken,
TransactionDateUtc = DateTimeOffset.FromUnixTimeMilliseconds(purchase.PurchaseTime).DateTime,
State = PurchaseState.Unknown
};
}
}
}
23 changes: 22 additions & 1 deletion src/Plugin.InAppBilling/InAppBilling.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,32 @@ public override Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemTy
return Task.FromResult(purchasesResult.PurchasesList.Select(p => p.ToIABPurchase()));
}

/// <summary>
/// Android only: Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
/// </summary>
/// <param name="itemType">Type of product</param>
/// <returns>The current purchases</returns>
public override async Task<IEnumerable<InAppBillingPurchase>> GetPurchasesHistoryAsync(ItemType itemType)
{
if (BillingClient == null)
throw new InAppBillingPurchaseException(PurchaseError.ServiceUnavailable, "You are not connected to the Google Play App store.");

var skuType = itemType switch
{
ItemType.InAppPurchase => BillingClient.SkuType.Inapp,
_ => BillingClient.SkuType.Subs
};

var purchasesResult = await BillingClient.QueryPurchaseHistoryAsync(skuType);


return purchasesResult?.PurchaseHistoryRecords?.Select(p => p.ToIABPurchase()) ?? new List<InAppBillingPurchase>();
}

/// <summary>
/// (Android specific) Upgrade/Downgrade/Change a previously purchased subscription
/// </summary>
/// <param name="newProductId">Sku or ID of product that will replace the old one</param>
/// <param name="oldProductId">Sku or ID of product that needs to be upgraded</param>
/// <param name="purchaseTokenOfOriginalSubscription">Purchase token of original subscription</param>
/// <param name="prorationMode">Proration mode (1 - ImmediateWithTimeProration, 2 - ImmediateAndChargeProratedPrice, 3 - ImmediateWithoutProration, 4 - Deferred)</param>
/// <returns>Purchase details</returns>
Expand Down
10 changes: 10 additions & 0 deletions src/Plugin.InAppBilling/Shared/BaseInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public abstract class BaseInAppBilling : IInAppBilling, IDisposable
/// <returns>The current purchases</returns>
public abstract Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemType itemType);



/// <summary>
/// Android only: Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
/// </summary>
/// <param name="itemType">Type of product</param>
/// <returns>The current purchases</returns>
public virtual Task<IEnumerable<InAppBillingPurchase>> GetPurchasesHistoryAsync(ItemType itemType) =>
Task.FromResult<IEnumerable<InAppBillingPurchase>>(new List<InAppBillingPurchase>());

/// <summary>
/// Purchase a specific product or subscription
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/Plugin.InAppBilling/Shared/IInAppBilling.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ public interface IInAppBilling : IDisposable
/// Get all current purchases for a specific product type. If you use verification and it fails for some purchase, it's not contained in the result.
/// </summary>
/// <param name="itemType">Type of product</param>
/// <param name="verifyPurchase">Verify purchase implementation</param>
/// <returns>The current purchases</returns>
Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemType itemType);


/// <summary>
/// Android only: Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
/// </summary>
/// <param name="itemType">Type of product</param>
/// <returns>The current purchases</returns>
Task<IEnumerable<InAppBillingPurchase>> GetPurchasesHistoryAsync(ItemType itemType);

/// <summary>
/// Purchase a specific product or subscription
/// </summary>
Expand Down

0 comments on commit ee0b93f

Please sign in to comment.