• Stars
    star
    630
  • Rank 70,940 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross-platform In App Billing Plugin for .NET

In-App Billing Plugin for .NET MAUI, Xamarin, and Windows

A simple In-App Purchase plugin for .NET MAUI, Xamarin, and Windows to query item information, purchase items, restore items, and more.

Subscriptions are supported on iOS, Android, and Mac. Windows/UWP/WinUI 3 - does not support subscriptions at this time.

Important Version Information

  • For .NET 6 & .NET MAUI you must use version 6.x+
  • For Xamarin.Forms and pre-.NET 6 it is recommended to use version 5.x
  • See migration guides below

Documentation

Get started by reading through the In-App Billing Plugin documentation.

There are changes in version 4.0 so read below.

Source code reference of non-conumables -> https://github.com/jamesmontemagno/app-ac-islandtracker/blob/master/TurnipTracker/ViewModel/ProViewModel.cs

Full blog on subscriptions: https://montemagno.com/ios-android-subscription-implemenation-strategies/

NuGet

Platform Support

Platform Version
Xamarin.iOS & iOS for .NET 10+
Xamarin.Mac, macOS for .NET, macCatlyst for .NET All
Xamarin.TVOS, tvOS for .NET 10.13.2
Xamarin.Android, Android for .NET 21+
Windows 10 UWP 10+
Windows App SDK (WinUI 3) 10+
Xamarin.Forms All
.NET MAUI All

Created By: @JamesMontemagno

Checkout my podcast on IAP

I co-host a weekly development podcast, Merge Conflict, about technology and recently covered IAP and this library:

Version 5 & 6 Major Update

  • This version of the plugins now target .NET 6! (Still including support for Xamarin). Versions 5 & 6 are the same source code, but Version 5 doesn't include 6.0. I would recommend this version for Xamarin apps.
  • Android: We now use Google Play Billing Version 4.0!
  • iOS: Beta - In version 4 we auto finalized all transactions and after testing I decided to keep this feature on in 5/6... you can no turn that off in your iOS application with InAppBillingImplementation.FinishAllTransactions = false;. This would be required if you are using consumables and don't want to auto finish. You will need to finalize manually with FinalizePurchaseAsync
  • All: There are now "Extras" for all products that give you back tons of info for each platform
  • Android: AcknowledgePurchaseAsync is now FinalizePurchaseAsync

Version 4 Major Update - Android

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 AcknowledgePurchaseAsync or the Consume API if it a consumable.
  2. You must hanle Pending Transactions from outside of you app. See docs from Google
  3. HandleActivityResult is removed from the API as it is not needed

Upgrading from 2/3 to 4

  • Remove Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;
  • Remove InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data);
  • Change: await CrossInAppBilling.Current.ConnectAsync(ItemType.InAppPurchase); to await CrossInAppBilling.Current.ConnectAsync();
  • Change: CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase, payload); to CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase);

Pending Transactions:

  • If the result of PurchaseAsync is PurchaseState.PaymentPending, store the order details locally and inform the user that they will have access to the product when the payment completes
  • When the user starts the app (and/or visits a particular page), if the stored PurchaseState is PaymentPending, call GetPurchasesAsync and query the result for a purchase that matches the stored purchase.
  • If the PurchaseState for this purchase is still PaymentPending, show the same no-access message
  • If the PurchaseState is Purchased, call ConsumePurchaseAsync or AcknowledgePurchaseAsync, depending on the product type

To respond to pending transactions you can subscribe to a listener in your Android project startup:

// Connect to the service here
await CrossInAppBilling.Current.ConnectAsync();

// Check if there are pending orders, if so then subscribe
var purchases = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.InAppPurchase);

if (purchases?.Any(p => p.State == PurchaseState.PaymentPending) ?? false)
{
  Plugin.InAppBilling.InAppBillingImplementation.OnAndroidPurchasesUpdated = (billingResult, purchases) =>
  {
       // decide what you are going to do here with purchases
       // probably acknowledge
       // probably disconnect
  };
}
else
{
  await CrossInAppBilling.Current.DisconnectAsync();
}

If you do connect the IsConnected propety will be true and when you make purchases or check purchases again you should check ahead of time and not re-connect or disconnect if there are pending purchases

I highly recommend reading the entire Google Play Billing System docs.

Consumable vs Non-consumables on Android

On Android if you purchase anything you must first Acknowledge a purchase else it will be refunded. See the android documentation.

https://developer.android.com/google/play/billing/integrate#process https://developer.android.com/google/play/billing/integrate#pending

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... ConsumePurchaseAsync will also acknowledge it, if you have a non-consumable you will need to call AcknowledgePurchaseAsync.

Version 4+ Linker Settings

For linking if you are setting Link All you may need to add:

Android:

Plugin.InAppBilling;Xamarin.Android.Google.BillingClient

iOS:

--linkskip=Plugin.InAppBilling

License

The MIT License (MIT), see LICENSE file.

Want To Support This Project?

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.

More Repositories

1

Xamarin.Plugins

Cross-platform Native API Access from Shared Code!
1,302
star
2

MediaPlugin

Take & Pick Photos and Video Plugin for Xamarin and Windows
C#
713
star
3

mvvm-helpers

Collection of MVVM helper classes for any application
C#
673
star
4

Hanselman.Forms

The most awesome Hanselman app
C#
671
star
5

monkey-cache

Easily cache any data structure for a specific amount of time in any .NET application.
C#
629
star
6

SettingsPlugin

Read and Write Settings Plugin for Xamarin and Windows
C#
325
star
7

GeolocatorPlugin

Geolocation plugin for Xamarin and Windows
C#
293
star
8

PermissionsPlugin

Check and Request Permissions Plugin for Xamarin and Windows
C#
282
star
9

ConnectivityPlugin

Connectivity Plugin for Xamarin and Windows
C#
262
star
10

ImageCirclePlugin

Circle Images for your Xamarin.Forms Applications
C#
240
star
11

Xamarin.Forms-PullToRefreshLayout

Pull To Refresh a ScrollView or ListView in Xamarin.Forms
C#
222
star
12

StoreReviewPlugin

Request app store reviews across Xamarin and Windows applications
C#
183
star
13

MyCoffeeApp

Sample Xamarin.Forms app built live on in 101 series on YouTube
C#
153
star
14

MeetupManager

Meetup.com app to track users at events
C#
149
star
15

DeviceInfoPlugin

Device Information Plugin for Xamarin and Windows
C#
143
star
16

app-ac-islandtracker

Animal Crossing Island Tracking Mobile App
C#
135
star
17

Xamarin-Templates

Xamarin.Android Templates Pack
C#
130
star
18

xamarin.forms-toolkit

Toolkit for Xamarin.Forms (Controls, Behaviors, and Converters)
C#
128
star
19

Xam.NavDrawer

Navigation Drawer Sample + MvvmCross Sample for Xamarin.Android
C#
123
star
20

Xamarin.Forms-Awesome-Controls

Awesome controls to add to your Xamarin.Forms apps
C#
121
star
21

XamChat

SignalR Chat Xamarin App
C#
120
star
22

CurrentActivityPlugin

Always grab the current Activity of your Xamarin.Android app!
C#
115
star
23

Xamarin.Forms-Monkeys

Simple list of monkeys (master/detail) in a xamarin.forms application
C#
115
star
24

MyWeather.Forms

Xamarin.Forms Weather Demo using OpenWeatherMap
C#
110
star
25

app-monkeychat

Monkey Chat application feature Twilio IP Messaging
C#
109
star
26

MyStreamTimer

A cool app to count up or down that writes text to file for streamers
C#
99
star
27

FloatingActionButton-for-Xamarin.Android

FAB material design for Xamarin.Android
C#
91
star
28

PagerSlidingTabStrip-for-Xamarin.Android

Port of Pager Sliding Tab Strip for Xamarin.Android Material Design
C#
85
star
29

app-coffeecups

Coffee Consumption App built with Xamarin.Forms and Azure Mobile Apps
C#
82
star
30

vsts-mobile-tasks

VSTS Tasks for Mobile!
TypeScript
79
star
31

MonoDroidToolkit

A toolkit for Xamarin.Android providing a lot of awesome helpers
C#
71
star
32

TextToSpeechPlugin

Text to Speech Plugin for Xamarin and Windows
C#
62
star
33

MotzCodesLive

Sample Resources for Motz Codes Live on Twitch
C#
60
star
34

AndroidStreamingAudio

Sample of streaming audio in background service in Xamarin.Android
C#
57
star
35

MyExpenses

My Expenses Cross Platform Demo - VSToolBox
C#
54
star
36

app-pretty-weather

A very pretty weather application built with Xamarin :)
C#
54
star
37

app-essentials

Sample project highlighting Xamarin.Essentials
C#
53
star
38

AllExtensions-DI-IoC

C#
52
star
39

xamarin.forms-workshop

Xamarin.Forms Full Day Workshop
C#
49
star
40

LaunchMapsPlugin

Launch External Maps Plugin for Xamarin and Windows
C#
48
star
41

MauiApp-DI

C#
46
star
42

VibratePlugin

Vibrate Plugin for Windows and Xamarin
C#
45
star
43

TheXamarinShow

All source code from my show on Channel 9, The Xamarin Show!
C#
45
star
44

app-imagesearch-cogs

Image Search and Cognitive Service Xamarin app!
C#
45
star
45

MVVMSourceGenerators

C#
44
star
46

Coffee-Filter

Find Coffee Fast with this Xamarin.Android App
C#
43
star
47

VS2019-FirstXamarinApp

C#
40
star
48

app-myconference

Conference App Build with .NET MAUI
C#
40
star
49

BikeNow

Bike Now is the best way to enjoy Seattle's bike sharing system on Android
C#
39
star
50

MonkeysApp-Workshop

Xamarn.Forms Workshop sample monkey app for iOS, Android, and Windows
C#
39
star
51

Censored

A .NET Profanity Censoring Library
C#
38
star
52

work-from-home-setup

Equipment and Setup recommended for Work From Home
37
star
53

app-peloton

Peloton app clone built with Xamarin.Forms
C#
35
star
54

dotnet-conferences

A comprehensive community built list of .NET Conferences around the world!
34
star
55

app-compass

Creating a simple compass application with Xamarin.Forms and Xamarin.Essentials.
C#
32
star
56

CircleImageView-Xamarin.Android

A fast circle image for Xamarin.Android
C#
32
star
57

Xamarin.Forms-PullToRefreshListView

Implementation of pull to refresh for Xamarin.Forms ListView
C#
31
star
58

Mvx.Plugins.Settings

Settings plug-in for MvvmCross.
C#
30
star
59

app-SimpleSignalR

Xamarin app to listen to new items from SignalR and ASP.NET Core
C#
30
star
60

mycadence-arduino

With this DIY project and a simple $18 ESP32 Arduino board you will have a budget Cadence display for your indoor cycling bike for Peloton or Apple Fitness+
C++
29
star
61

PlanetXamarin

Planet Xamarin
C#
28
star
62

BatteryPlugin

Battery Plugin for Xamarin and Windows
C#
27
star
63

iBeaconsEverywhere

iBeacon example on iOS and Android
C#
26
star
64

app-monkeys

C#
25
star
65

LocalizationSample

C#
25
star
66

GifImageView-Xamarin.Android

Animated ImageView for your Xamarin.Android apps
C#
25
star
67

ContactsPlugin

Contacts Plugin For Xamarin and Windows
C#
24
star
68

plugin-template

Plugin for .NET Template
C#
23
star
69

xamarin-workshop

Xamarin workshops for building a Xamarin.Android and Xamarin.Forms App
C#
19
star
70

app-ocr-functions

Cognitive Services, Azure Functions, Azure Mobile Apps, and Xamarin
C#
19
star
71

MyStocks.Forms

Xamarin.Forms example of querying stock quotes and using text to speech apis.
C#
18
star
72

AirQualityApps

C#
18
star
73

Xamarin.Forms-Android-CustomProgressBar

Using a custom renderer to display and bind to my custom progress bar
C#
18
star
74

build2017-future-of-mobile

Live Player Demos from Future of Mobile at Build 2017
C#
18
star
75

XamDroid.StickyListHeaders

Xamarin.Android Port of StickyListHeaders
C#
17
star
76

FiveLetters

A clone of a clone of Wordle built with .NET MAUI
C#
17
star
77

BetterTogether

Blazor, ASP.NET Core, Xamarin, .NET Standard <3
C#
16
star
78

XamarinDNR

Dot Net Rocks, PCL, Azure!
C#
16
star
79

FrenchPressTimer

Cross Platform timer that counts down from 4 minutes
C#
16
star
80

forms-native-embedding

Xamarin.Forms Native Embedding Sample
C#
16
star
81

embeddinator-weather

C#
15
star
82

Covid19Stats

Desktop app to retrieve COVID-19 Stats and download them to files on disk for OBS/SLOBS with a timer :)
C#
14
star
83

PuppyKittyOverflow

PuppyKittyOverflow
C#
14
star
84

Jeffsum.NET

Jeff Goldblum text placeholder generator of pure amazingness. (Unofficial .NET version of Jeffsum.com by @seanehalpin)
C#
13
star
85

MyFirstOouiApp

C#
13
star
86

MarshmallowSamples

Get ready for Android 6.0 with these Marshmallow Samples
C#
13
star
87

Xamarin.Android-AppCompat

App compat for android
C#
13
star
88

ToolkitMessenger

Esample of .NET Toolkit Messenger
C#
13
star
89

build2021-intro-csharp-python

C# and Python are two of the most popular programming languages for developers in all areas of tech. From making web apps to doing machine learning, you can't go wrong with either of them! James and Christopher are here to introduce you to these two powerful languages, explore some “Hello, World” examples, and show you the docs, tools, and frameworks that can help students and beginners get started on coding today!
Jupyter Notebook
13
star
90

blog-samples

All code samples from http://motzcod.es and http://blog.xamarin.com
C#
12
star
91

jamesmontemagno

12
star
92

XamDroid.RobotoText

Roboto text everywhere!
C#
12
star
93

dotnet-maui-template

Default template idea for .NET MAUI
C#
12
star
94

app-tictactoe

A Xamarin.Forms Tic-Tac-Toe example
C#
12
star
95

embeddinator-hellosharedui

C#
11
star
96

OfficeLightControl

Workshop for building an office light switch app with IFTTT and Hues
C#
11
star
97

FormsAnimations

Sample application shown during the Xamarin.Forms webinar for animations.
C#
11
star
98

MonkeyFinder6000

C#
10
star
99

app-simplestocks

C#
10
star
100

MonoDroid.ActionBar

A port of https://github.com/johannilsson/android-actionbar
C#
10
star