https://github.com/flagbug/saneinappbillinghandler
A sane wrapper over the Xamarin.InAppBilling library
https://github.com/flagbug/saneinappbillinghandler
Last synced: 12 months ago
JSON representation
A sane wrapper over the Xamarin.InAppBilling library
- Host: GitHub
- URL: https://github.com/flagbug/saneinappbillinghandler
- Owner: flagbug
- Created: 2015-06-10T17:25:01.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-05-17T16:11:41.000Z (almost 10 years ago)
- Last Synced: 2025-04-13T09:54:57.849Z (12 months ago)
- Language: C#
- Size: 18.6 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Overview
SaneInAppBillingHandler is a sane wrapper over the [Xamarin.InAppBilling](http://components.xamarin.com/gettingstarted/xamarin.inappbilling) component. Note that you have to install the Xamarin.InAppBilling component manually from the Xamarin component store, and the [SaneInAppBillingHandler package](https://www.nuget.org/packages/SaneInAppBillingHandler/) from NuGet
## Why
The Xamarin.InAppBilling API is, let's say, a bit strange to use.
For example: to buy a product through the API, you have to handle the following events:
- `OnProductPurchased`
- `OnProductPurchasedError`
- `BuyProductError`
- `InAppBillingProcesingError` [sic!]
- `OnUserCanceled`
- `OnPurchaseFailedValidation`
SaneInAppBillingHandler exposes a convenient asynchronous method instead.
## Quickstart
### Creating the billing handler
```csharp
using SaneInAppBillingHandler;
var handler = new SaneInAppBillingHandler(yourActivity, "API key that you receive from Google");
// Call this method when creating your activity
try
{
await handler.Connect();
}
catch (InAppBillingException ex)
{
// Thrown if the commection fails for whatever reason (device doesn't support In-App billing, etc.)
// All methods (except for Disconnect()) may throw this exception,
// handling it is omitted for brevity in the rest of the samples
}
```
### Getting available purchases
```csharp
// Retrieve the product infos for "myItem1" and "myItem2"
// (these are the IDs that you give your products in the Google Play Developer Console)
// The second argument specifies if those products are subscriptions or normal one-time purchases
IReadOnlyList products = await handler.QueryInventory(new[]{"myItem1", "myItem2", ItemType.Product);
```
### Getting a list of products that the user has purchased
```csharp
IReadOnlyList purchases = await handler.GetPurchases(ItemType.Product);
```
### Buying a product
```csharp
// Buys the product and returns a billing result. Look this up in the BillingResult class.
int result = await handler.BuyProduct(product);
```
### Consuming a purchase
```csharp
await handler.ConsumePurchase(purchase);
```
### Disconnecting the handler
```csharp
// Call this method when destroying your activity
handler.Disconnect();
```