Skip to content

Commit

Permalink
Update PurchaseSubscription.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno authored Apr 27, 2021
1 parent 4069011 commit 8fcfcb8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/PurchaseSubscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ All purchases go through the `PurchaseAsync` method and you must always `Connect
/// </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>
/// <returns>Purchase details</returns>
/// <exception cref="InAppBillingPurchaseException">If an error occures during processing</exception>
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, string payload, IInAppBillingVerifyPurchase verifyPurchase = null);
Task<InAppBillingPurchase> PurchaseAsync(string productId, ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase = null);
```

The `payload` attribute is a special payload that is sent and then returned from the server for additional validation. It can be whatever you want it to be, but should be a constant that is used anywhere the `payload` is used.
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.

Example:
```csharp
Expand All @@ -31,15 +30,15 @@ public async Task<bool> PurchaseItem(string productId, string payload)
var billing = CrossInAppBilling.Current;
try
{
var connected = await billing.ConnectAsync(ItemType.Subscription);
var connected = await billing.ConnectAsync();
if (!connected)
{
//we are offline or can't connect, don't try to purchase
return false;
}

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

//possibility that a null came through.
if(purchase == null)
Expand All @@ -49,6 +48,10 @@ public async Task<bool> PurchaseItem(string productId, string payload)
else
{
//purchased!
if(Device.RuntimePlatform == Device.Android)
{
// Must call AcknowledgePurchaseAsync else the purchase will be refunded
}
}
}
catch (InAppBillingPurchaseException purchaseEx)
Expand All @@ -67,6 +70,7 @@ public async Task<bool> PurchaseItem(string productId, string payload)
}
```


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


Expand Down

0 comments on commit 8fcfcb8

Please sign in to comment.