Search code examples
xamarin.formsxamarin.androidxamarin.iosin-app-purchasein-app-billing

Xamarin Forms In App Billing plugin does not work


I installed the in app billing plugin in my Xamarin Forms project: Plugin.

First I want to use it on iOS but the plugin doesn't work. It shows following error: Plugin.InAppBilling.Abstractions.InAppBillingPurchaseException: Cannot connect to iTunes Store at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync (System.String productId, Plugin.InAppBilling.Abstractions.ItemType itemType, System.String payload, Plugin.InAppBilling.Abstractions.IInAppBillingVerifyPurchase verifyPurchase) ..

I think my productId or the payload is wrong, what should I put in there? Here is my Code:

          try
            {
                var productId = "mySKU";

                var connected = await CrossInAppBilling.Current.ConnectAsync();

                if (!connected)
                {
                    //Couldn't connect to billing, could be offline, alert user
                    return;
                }

                //try to purchase item
                var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription, "payload");
                if (purchase == null)
                {
                    //Not purchased, alert the user
                }
                else
                {
                    //Purchased, save this information
                    var id = purchase.Id;
                    var token = purchase.PurchaseToken;
                    var state = purchase.State;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //Something bad has occurred, alert user
            }
            finally
            {
                //Disconnect, it is okay if we never connected
                await CrossInAppBilling.Current.DisconnectAsync();
            }

I hope anybody can help me. Thanks in advance.


Solution

  • I fixed it. For all those who have the same problem: My problem was, that I created a bundle id. Then I activated the automatic signing in Visual Studio and it created another bundle id automatically. I selected it and I had to give it a name. After I clicked save, it changed back to the other id. The problem was that the ids had the same name. So I renamed the bundle id in Visual Studio and it works like a charm.