Cross platform in app billing library for Android, IOS and UWP.
Nuget: https://www.nuget.org/packages/XFInAppBilling/
it uses billingclient api of Android and StoreContext from UWP. See below, function references implemented.
| Function | Android | Amazon | UWP | IOS |
|---|---|---|---|---|
| PurchaseAsync | launchBillingFlow | Purchase | RequestPurchaseAsync | |
| GetProductsAsync | querySkuDetailsAsync | GetProductData | GetAssociatedStoreProductsAsync | |
| GetPurchases /CheckIfUserHasActiveSubscriptionAsync | queryPurchaseHistoryAsync | GetPurchaseUpdates | GetAppLicenseAsync | |
| na | acknowledgePurchase | NotifyFulfillment | na | |
| na | GetUserData |
This Nuget package is using CurrentActivity Plugin https://github.com/jamesmontemagno/CurrentActivityPlugin Please, follow the steps as it is stated in this Plugin description
Add a new C# class file in your project called "MainApplication.cs". Override the OnCreate method and call the Init method
#if DEBUG
[Application(Debuggable = true)]
#else
[Application(Debuggable = false)]
#endif
public class MainApplication : Application
{
public MainApplication(IntPtr handle, JniHandleOwnership transer)
: base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
CrossCurrentActivity.Current.Init(this);
}
}
If you already have an "Application" class in your project simply add the Init call.
The benefit of adding it at the Application level is to get the first events for the application.
Amazon Iap implementation isn't included into the Nuget package. Because Amazon app is also an android project and using plugin, it is currently not possible to implement 2 android project, especially multi-targeting doesn't seem to allow it (if anyone knows how to do it, please feel free to implement and send PR)
I could include AmazonIAP dll and implementation into the nuget package but why should I? it is messy you will have Google billingclient and amazon iap dll unnecessarily included into same project.
In general you should create another android project for Amazon (see the test project in the source code) and separate from google Android project, if you have shared resources, code and other things, create and Android Library project and reference on Main Google Android and Amazon Android projects. So you will have a shared Android Library project. Thus you can keep Google specific implementation and Amazon specific implementation clean and separate.
If you follow above suggestion,
- install the XFInAppBilling Nuget on .net standard, android, uwp and ios projects (dont install on amazon project)
- Copy this folder into your amazon android project
- reference the AmazonIapV2Android.dll using add reference
- Adjust the namespace inside this class InAppBillingImplementation.cs You should be good to go :)
Here is how you can work with it
if you are using AndroidX with Xamarin.forms 4.5 and above, you can try 2.0.x-pre release version. this version is using Android BillingClient 2.2.1 version and above. There arent major changes between 1.x.x version but 2.2.1 and above are using AndroidX libraries thats why wont work for old Android Support libraries