Skip to content

Commit

Permalink
update some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Feb 13, 2022
1 parent e1d182b commit 6c17e74
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
12 changes: 9 additions & 3 deletions docs/CheckAndRestorePurchases.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Task<IEnumerable<InAppBillingPurchase>> GetPurchasesAsync(ItemType itemType);

When you make a call to restore a purchase it will prompt for the user to sign in if they haven't yet, so take that into consideration.

Note, that on iOS this will only return your non-consumables, consumables are not tracked at all and your app should handle these situations
Note, that on iOS this will only return your non-consumables, consumables that have already been `finished` are not tracked at all and your app should handle these situations.

On iOS, we auto finish all transactions when you get purchases. If you have any consumables you should pass in a `List<string>` with ids that you do not want finished.


Example:
```csharp
Expand All @@ -30,12 +33,15 @@ public async Task<bool> WasItemPurchased(string productId)
}

//check purchases
var purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase);
var idsToNotFinish = new List<string>(new [] {"myconsumable"});

var purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase, idsToNotFinish);

//check for null just incase
if(purchases?.Any(p => p.ProductId == productId) ?? false)
{
//Purchase restored
// if on Android may be good to
return true;
}
else
Expand Down Expand Up @@ -64,7 +70,7 @@ public async Task<bool> WasItemPurchased(string productId)

## Subscriptions

On `Android` only valid on-going subscriptions will be returned. `iOS` returns all receipts for all instances of the subscripitions. Read the iOS documentation to learn more on strategies.
On `Android` only valid on-going subscriptions will be returned (with the original purchase date). `iOS` returns all receipts for all instances of the subscripitions. Read the iOS documentation to learn more on strategies.

Learn more about `IInAppBillingVerifyPurchase` in the [Securing Purchases](SecuringPurchases.md) documentation.

Expand Down
25 changes: 19 additions & 6 deletions docs/GetProductDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ After creating the in-app purchase items in the respective app store you can the
/// <returns>List of products</returns>
Task<IEnumerable<InAppBillingProduct>> GetProductInfoAsync(ItemType itemType, params string[] productIds);
```
Note that you have to specify an `ItemType` for each call. This means you have to query your `InAppPurchase` and `Subscriptio`n items in multiple calls to the API. Additionally, the `productIds` must be specified in the app, there is no way to query the In-App Billing service to just say "give me everything".
Note that you have to specify an `ItemType` for each call. This means you have to query your `InAppPurchase` and `Subscription` items in multiple calls to the API. Additionally, the `productIds` must be specified in the app, there is no way to query the In-App Billing service to just say "give me everything".

You will receive back a list of your products that you specified the `productIds` for with the following information:
You will receive back a list of your products that you specified the `productIds` for with common information including:

```csharp
/// <summary>
/// Product being offered
/// </summary>
public class InAppBillingProduct
{
/// <summary>
Expand All @@ -31,6 +28,7 @@ public class InAppBillingProduct
/// </summary>
public string Description { get; set; }


/// <summary>
/// Product ID or sku
/// </summary>
Expand All @@ -52,9 +50,24 @@ public class InAppBillingProduct
/// This value represents the localized, rounded price for a particular currency.
/// </summary>
public Int64 MicrosPrice { get; set; }

/// <summary>
/// Extra information for apple platforms
/// </summary>
public InAppBillingProductAppleExtras AppleExtras { get; set; } = null;
/// <summary>
/// Extra information for Android platforms
/// </summary>
public InAppBillingProductAndroidExtras AndroidExtras { get; set; } = null;
/// <summary>
/// Extra information for Windows platforms
/// </summary>
public InAppBillingProductWindowsExtras WindowsExtras { get; set; } = null;

}
```
```

This information should be enough for most users, however there are all sorts of special things that each platforms return. That is why there are `AppleExtras`, `AndroidExtras`, and `WindowsExtras`. Each of these return special properties for things like discounts, sales, introductory offers, and subscription group information.

Example:
```csharp
Expand Down
21 changes: 10 additions & 11 deletions docs/PurchaseConsumable.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ Each app store calls them something slightly different:
All purchases go through the `PurchaseAsync` method and you must always `ConnectAsync` before making calls and `DisconnectAsync` after making calls.

Consumables are unique and work a bit different on each platform and the `ConsumePurchaseAsync` may need to be called after making the purchase:
* Apple: As soon as you purchase they are consumed
* Apple: You must consume the purchase (this finishes the transaction), starting in 5.x and 6.x will not auto do this.
* Android: You must consume before purchasing again
* Microsoft: You must consume before purchasing again

The reason for forcing you to consume is that some platforms will not receive the consumable purchase based when getting them. For this reason, we have introduced `ItemType.InAppPurchaseConsumable` specificaly for iOS. If you pass in `ItemType.InAppPurchase` then it will auto consume the purchase. This is what used to happen in 4.0.

### Purchase Item
```csharp
/// <summary>
Expand Down Expand Up @@ -44,7 +46,7 @@ Task<InAppBillingPurchase> ConsumePurchaseAsync(string productId, string purchas

Example:
```csharp
public async Task<bool> PurchaseItem(string productId, string payload)
public async Task<bool> PurchaseItem(string productId)
{
var billing = CrossInAppBilling.Current;
try
Expand All @@ -57,7 +59,7 @@ public async Task<bool> PurchaseItem(string productId, string payload)
}

//check purchases
var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase);
var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchaseConsumable);

//possibility that a null came through.
if(purchase == null)
Expand All @@ -66,16 +68,13 @@ public async Task<bool> PurchaseItem(string productId, string payload)
}
else if(purchase.State == PurchaseState.Purchased)
{
//purchased, we can now consume the item or do it later
//If we are on iOS we are done, else try to consume the purchase
//Device.RuntimePlatform comes from Xamarin.Forms, you can also use a conditional flag or the DeviceInfo plugin
if(Device.RuntimePlatform == Device.iOS)
return true;
// purchased, we can now consume the item or do it later
// here you may want to call your backend or process something in your app.

var consumedItem = await CrossInAppBilling.Current.ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken);
var wasConsumed = await CrossInAppBilling.Current.ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken);

if(consumedItem != null)
if(wasConsumed)
{
//Consumed!!
}
Expand Down
2 changes: 1 addition & 1 deletion docs/PurchaseNonConsumable.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ On Android you must call `AcknowledgePurchaseAsync` within 3 days when a purchas

Example:
```csharp
public async Task<bool> PurchaseItem(string productId, string payload)
public async Task<bool> PurchaseItem(string productId)
{
var billing = CrossInAppBilling.Current;
try
Expand Down
2 changes: 1 addition & 1 deletion docs/PurchaseSubscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<bool> PurchaseItem(string productId, string payload)
}
else
{
//purchased!
//purchased!
if(Device.RuntimePlatform == Device.Android)
{
// Must call AcknowledgePurchaseAsync else the purchase will be refunded
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin.InAppBilling/Shared/InAppBillingProduct.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ public class InAppBillingProduct
/// </summary>
public InAppBillingProductAppleExtras AppleExtras { get; set; } = null;
/// <summary>
/// Extra infor for Android platforms
/// Extra information for Android platforms
/// </summary>
public InAppBillingProductAndroidExtras AndroidExtras { get; set; } = null;
/// <summary>
/// Extra infor for Windows platforms
/// Extra information for Windows platforms
/// </summary>
public InAppBillingProductWindowsExtras WindowsExtras { get; set; } = null;

Expand Down

0 comments on commit 6c17e74

Please sign in to comment.