Cross-platform In App Billing Plugin for Xamarin
A simple In-App Purchase plugin for Xamarin and Windows to query item information, purchase items, restore items, and more.
Get started by reading through the In-App Billing Plugin documentation.
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
|Platform|Version| | ------------------- | :------------------: | |Xamarin.iOS|iOS 8+| |tvOS - Apple TV|All| |Xamarin.Android|API 14+| |Windows 10 UWP|10+|
We now use Xamarin.Essentials for getting access to the current activity. So ensure you initialize Xamarin.Essentials in your Android app.
Also if you get a null exception the linker is being aggressive so write the following code in your MainActivity:
var context = Xamarin.Essentials.Platform.AppContext; var activity = Xamarin.Essentials.Platform.CurrentActivity;
Version 4.X updates to the new Android billing client. This means there are few important changes: 1. You must acknowledge all purchases within 3 days, by calling
AcknowledgePurchaseAsyncor the Consume API if it a consumable. 2. You must hanle Pending Transactions from outside of you app. See docs from Google 3.
HandleActivityResultis removed from the API as it is not needed
Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;
InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data);
CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase, payload);to
I highly recommend reading the entire Google Play Billing System docs.
On Android if you purchase anything you must first Acknowledge a purchase else it will be refunded. See the android documentation.
For consumables, the consumeAsync() method fulfills the acknowledgement requirement and indicates that your app has granted entitlement to the user. This method also enables your app to make the one-time product available for purchase again.
So, if you have a consumable...
ConsumePurchaseAsyncwill also acknowledge it, if you have a non-consumable you will need to call
For linking if you are setting Link All you may need to add:
The MIT License (MIT), see LICENSE file.
All I have ever asked is to be active by submitting bugs, features, and sending those pull requests down! Want to go further? Make sure to subscribe to my weekly development podcast Merge Conflict, where I talk all about awesome Xamarin goodies and you can optionally support the show by becoming a supporter on Patreon.