I'm curious about the Google Play Store payment feature in .NET MAUI.

예강 신 0 Reputation points
2023-08-17T04:02:27.1966667+00:00

I'd like to use the Google Play payment feature with .NET MAUI 7. I used to implement the payment system using the code <uses-permission android:name="com.android.vending.BILLING" />, but it has been deprecated. Please let me know how to use it.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-08-18T06:09:16.2633333+00:00

    Hello,

    Starting from Android 12 (API level 31), the billing library no longer requires this permission. Instead, it uses Play Billing Library 4.0, which handles all billing transactions internally and does not require a separate permission.

    To implement in-app billing functionality in your app, you should now use the Xamarin.Android.Google.BillingClient nugget package and implement the necessary code for purchasing and managing in-app products.

    Here is an example of how to implement in-app billing using Xamarin.Android.Google.BillingClient nugget package.

    Firstly, Initialize an instance of the BillingClient

    #if ANDROID
    		BillingClient billingClient = BillingClient
    				.NewBuilder(Microsoft.Maui.MauiApplication.Context)
                    
                    .EnablePendingPurchases().SetListener(new PerchasesUpdateListener())
                    .Build();
    		billingClient.StartConnection(ConnectionListener,DisConnectEvent);
    
    #endif
    

    ConnectionListener listens for changes in the connection status with the Google Play Billing service.

    #if ANDROID
        private void DisConnectEvent()
        {
            //throw new NotImplementedException();
        }
    
        private void ConnectionListener(BillingResult obj)
        {
           // throw new NotImplementedException();
        }
    #endif
    

    Then Implement the IPurchasesUpdatedListener interfaces: IPurchasesUpdatedListener handles the result of the purchase flow and updates the UI accordingly.

    #if ANDROID
    internal class PerchasesUpdateListener:Java.Lang.Object, IPurchasesUpdatedListener
    {
        public PerchasesUpdateListener()
        {
        }
    
        public void OnPurchasesUpdated(BillingResult p0, IList<Purchase> p1)
        {
            throw new NotImplementedException();
        }
    }
    #endif
    

    For more details, you can check this google billing document.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.