Example #1
0
        void ConnectToService()
        {
            try
            {
                var key = Xamarin.InAppBilling.Utilities.Security.Unify(new[]
                {
                    GetNumberString(3),
                    GetNumberString(6),
                    GetNumberString(1),
                    GetNumberString(4),
                    GetNumberString(2),
                    GetNumberString(7),
                    GetNumberString(0),
                    GetNumberString(5)
                },
                                                                        new[] { 0, 1, 2, 3, 4, 5, 6, 7 }
                                                                        );

                _serviceConnection              = new InAppBillingServiceConnection(this, key);
                _serviceConnection.OnConnected += HandleOnConnected;
                _serviceConnection.Connect();
            }
            catch (Exception ex)
            {
                GaService.TrackAppException(this.Class, "ConnectToService", ex, false);
            }
        }
Example #2
0
        private void prepareServices()
        {
#if NOKIA_X
            //prepare for nokia in-app payment
            // Create a connection to the service
            nokiaIAPServiceConnection = new Nokia.Payment.IAP.NokiaIAPServiceConnection(svc =>
            {
                // Set our instance of the service on the activity
                nokiaIAPService = svc;
            }, () =>
            {
                /* Disconnected */
                nokiaIAPService = null;
            });

            // Initiate binding of the service
            BindService(NokiaIAP.GetPaymentEnabler(), nokiaIAPServiceConnection, Bind.AutoCreate);
#else
            // Create a new connection to the Google Play Service
            googleIABServiceConnection              = new InAppBillingServiceConnection(this, GOOGLE_PRODUCT_ID);
            googleIABServiceConnection.OnConnected += () =>
            {
                // Load available products and any purchases
            };

            // Attempt to connect to the service
            googleIABServiceConnection.Connect();
#endif
        }
        private Task Connect()
        {
            if (_connectTask != null)
            {
                return(_connectTask);
            }

            TaskCompletionSource <bool> completionSource = new TaskCompletionSource <bool>();

            _connectTask = completionSource.Task;

            _connection              = new InAppBillingServiceConnection(_activity, PublicKey);
            _activity                = null;
            _connection.OnConnected += delegate
            {
                var cs = completionSource;
                completionSource = null;
                cs?.SetResult(true);
            };
            _connection.OnInAppBillingError += delegate
            {
                var cs = completionSource;
                completionSource = null;
                cs?.SetException(new Exception("InAppBillingError"));
            };
            _connection.Connect();
            return(_connectTask);
        }
Example #4
0
        public bool Connect(string[] productIDs)
        {
            try
            {
                SAMLog.Debug("AndroidBilling.Connect");

                _purchases  = null;
                _productIDs = productIDs;

                if (IsConnected)
                {
                    Disconnect();
                }

                _serviceConnection = new InAppBillingServiceConnection(_activity, PUBLIC_KEY);

                _serviceConnection.OnConnected += OnConnected;

                _serviceConnection.Connect();                 // throws Exception
                return(true);
            }
            catch (Exception e)
            {
                SAMLog.Info("IAB::Connect", e);
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// Starts the setup of this Android application by connection to the Google Play Service
        /// to handle In-App purchases.
        /// </summary>
        public void StartSetup()
        {
            // A Licensing and In-App Billing public key is required before an app can communicate with
            // Google Play, however you DON'T want to store the key in plain text with the application.
            // The Unify command provides a simply way to obfuscate the key by breaking it into two or
            // or more parts, specifying the order to reassemlbe those parts and optionally providing
            // a set of key/value pairs to replace in the final string.
            string value = Security.Unify(
                new string[] { "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnAtEDv/z61eaiFcyVOOB+OjbV5faLPLzhn6sMNSxb+HizNsslVS4s",
                               "G5w/YfW6NJnkwMDa4BNPSMeHHlbEQDIoupU4f0U4+QqKNhdStsbu1TZ3WdpnCwqlsZALs+DGwq76NOP/IxIdSv7PX7Hd0cy9Z",
                               "yQGu9t4Mvf+CyV+Y94XPMvsQvKFSHot+UC+GdpFzKHn9LI+fqoif2hW6oh2JC2Z7bs2BS3I7gV0jXK6aJd3ZXiGuL+iiRvi5a",
                               "uzRN4wv6m1jDY7mZKL62fDVqqyRwH4Q7qRdVkezWj/mCXV0HZvpFPDtWX/X3U4dtm8d3Tw4wwVwQg6GbDHN6lw8JWYgEtcwIDAQAB" },
                new int[] { 0, 1, 2, 3 });

            // Create a new connection to the Google Play Service
            serviceConnection              = new InAppBillingServiceConnection(this, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnAtEDv/z61eaiFcyVOOB+OjbV5faLPLzhn6sMNSxb+HizNsslVS4sG5w/YfW6NJnkwMDa4BNPSMeHHlbEQDIoupU4f0U4+QqKNhdStsbu1TZ3WdpnCwqlsZALs+DGwq76NOP/IxIdSv7PX7Hd0cy9ZyQGu9t4Mvf+CyV+Y94XPMvsQvKFSHot+UC+GdpFzKHn9LI+fqoif2hW6oh2JC2Z7bs2BS3I7gV0jXK6aJd3ZXiGuL+iiRvi5auzRN4wv6m1jDY7mZKL62fDVqqyRwH4Q7qRdVkezWj/mCXV0HZvpFPDtWX/X3U4dtm8d3Tw4wwVwQg6GbDHN6lw8JWYgEtcwIDAQAB");
            serviceConnection.OnConnected += async() =>
            {
                // Attach to the various error handlers to report issues
                serviceConnection.BillingHandler.OnGetProductsError += (int responseCode, Bundle ownedItems) =>
                {
                    Console.WriteLine("Error getting products");
                    Log.Error("InAppBillingServiceConnection", "Error getting products");
                };

                serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) =>
                {
                    Console.WriteLine("Invalid owned items bundle returned");
                    Log.Error("InAppBillingServiceConnection", "Invalid owned items bundle returned");
                };

                serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) =>
                {
                    Console.WriteLine("Error purchasing item {0}", sku);
                    Log.Error("InAppBillingServiceConnection", "Error purchasing item " + sku);
                };

                serviceConnection.BillingHandler.OnPurchaseConsumedError += (int responseCode, string token) =>
                {
                    Console.WriteLine("Error consuming previous purchase");
                    Log.Error("InAppBillingServiceConnection", "Error consuming previous purchase");
                };

                serviceConnection.BillingHandler.InAppBillingProcesingError += (message) =>
                {
                    Console.WriteLine("In app billing processing error {0}", message);
                    Log.Error("InAppBillingServiceConnection", "In app billing processing error " + message);
                };

                // Load inventory or available products
                await GetInventory();

                // Load any items already purchased
                LoadPurchasedItems();
            };

            // Attempt to connect to the service
            serviceConnection.Connect();
        }
Example #6
0
        void ConnectInAppBilling()
        {
            string value = Security.Unify(Resources.GetStringArray(Resource.Array.billing_key), new int[] { 0, 1, 2, 3 });

            _serviceConnection = new InAppBillingServiceConnection(this, value);
            if (_serviceConnection != null)
            {
                _serviceConnection.OnConnected += connected;
                _serviceConnection.Connect();
            }
        }
Example #7
0
        private void LoadGooglePrices()
        {
            try
            {
                var ids = new List <string>();

                foreach (var item in availableTraps)
                {
                    ids.Add(item.KeyGoogle);
                }

                _serviceConnection.OnConnected += async() =>
                {
                    products = await _serviceConnection.BillingHandler.QueryInventoryAsync(ids, Xamarin.InAppBilling.ItemType.Product);

                    _serviceConnection.BillingHandler.OnProductPurchased += BillingHandler_OnProductPurchased;

                    _serviceConnection.BillingHandler.OnProductPurchasedError += BillingHandler_OnProductPurchasedError;

                    _serviceConnection.BillingHandler.OnUserCanceled += BillingHandler_OnUserCanceled;

                    LoadProductPrices(products.ToList());

                    var purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);

                    if (purchases != null)
                    {
                        foreach (var purchase in purchases)
                        {
                            var intent = await InsertIntent(purchase.ProductId);

                            var result = await RegisterPurchase(intent);

                            if (result)
                            {
                                _serviceConnection.BillingHandler.ConsumePurchase(purchase);
                            }
                            else
                            {
                                InvalidateBuyIntent(intent);
                            }
                        }
                    }

                    progressDialog.Cancel();
                };

                _serviceConnection.Connect();
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
Example #8
0
 static void ConnectToPlayStore()
 {
     // Attempt to connect to the service
     if (m_serviceConnection != null && !m_serviceConnection.Connected)
     {
         m_serviceConnection.Connect();
     }
     else
     {
         AfterConnection();
     }
 }
        private async void AboutPageDonateButtonOnClick(View view)
        {
            InAppBillingServiceConnection connection = null;

            try
            {
                connection = new InAppBillingServiceConnection(Activity);
                var sem = new SemaphoreSlim(0);
                connection.OnConnected += (sender, args) => sem.Release();
                connection.Connect();
                if (await sem.WaitAsync(TimeSpan.FromSeconds(5)))
                {
                    var buyIntentBundle = connection.Service.GetBuyIntent(3, Context.PackageName,
                                                                          GetProductSku(), "inapp", "");
                    var pendingIntent = buyIntentBundle.GetParcelable("BUY_INTENT") as PendingIntent;
                    MainActivity.CurrentContext.StartIntentSenderForResult(pendingIntent.IntentSender, 1001, new Intent(), 0, 0, 0, Bundle.Empty);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                ResourceLocator.MessageDialogProvider.ShowMessageDialog("Something went wrong, you can always try later ^^", "Something went wrong™");
            }
            finally
            {
                connection.Disconnected();
            }

            string GetProductSku()
            {
                switch (view.Id)
                {
                case Resource.Id.AboutPageDonate1Button:
                    return("donation1");

                case Resource.Id.AboutPageDonate2Button:
                    return("donate2");

                case Resource.Id.AboutPageDonate3Button:
                    return("donate3");

                case Resource.Id.AboutPageDonate4Button:
                    return("donate4");

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
 private void OnLicenseChecked()
 {
     try
     {
         InitConnectToGoogleStore();
         _serviceConnection.Connect();
         CreateLocalDatabase();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "OnLicenseChecked", exception, true);
     }
 }
        /// <summary>
        /// Starts the setup of this Android application by connection to the Google Play Service
        /// to handle In-App purchases.
        /// </summary>
        public void StartSetup()
        {
            // A Licensing and In-App Billing public key is required before an app can communicate with
            // Google Play, however you DON'T want to store the key in plain text with the application.
            // The Unify command provides a simply way to obfuscate the key by breaking it into two or
            // or more parts, specifying the order to reassemlbe those parts and optionally providing
            // a set of key/value pairs to replace in the final string.
            string value = Security.Unify(
                new string[] { "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtpopeFYhDOOsufNhYe2PY97azBQBJoqGSP/XxsgzQgj3M0MQQ0WE0WDwPKoxlo/MIuoadVR5q2ZRs3rTl",
                               "UsH9vYUPr/z0/O8kn5anQHshQkHkeHsA8wbyJGGmwcXqvZr1fnzFOFyHL46s47vOJBLc5x30oieJ02dNxdBcy0oFEJtJS5Ng5sm6YUv9ifgxYOqMr/K61HNw6tP0j",
                               "vi6vLv2ro/KXO0ADVxcDxEg+Pk16xVNKgnei8M09PJCgA9bWNyeSsD+85Jj9+OZGsS/DN7O7nrGuKx8oAg/lE6a2eCQHh9lXxSPlAFAMH2FB8aNxUeJxkByW+6l/S",
                               "yqvVlOeYxAwIDAQAB" },
                new int[] { 0, 1, 2, 3 });

            // Create a new connection to the Google Play Service
            _serviceConnection              = new InAppBillingServiceConnection(this, value);
            _serviceConnection.OnConnected += () => {
                // Attach to the various error handlers to report issues
                _serviceConnection.BillingHandler.OnGetProductsError += (int responseCode, Bundle ownedItems) => {
                    Console.WriteLine("Error getting products");
                };

                _serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) => {
                    Console.WriteLine("Invalid owned items bundle returned");
                };

                _serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) => {
                    Console.WriteLine("Error purchasing item {0}", sku);
                };

                _serviceConnection.BillingHandler.OnPurchaseConsumedError += (int responseCode, string token) => {
                    Console.WriteLine("Error consuming previous purchase");
                };

                _serviceConnection.BillingHandler.InAppBillingProcesingError += (message) => {
                    Console.WriteLine("In app billing processing error {0}", message);
                };

                // Load inventory or available products
                GetInventory();

                // Load any items already purchased
                LoadPurchasedItems();
            };

            // Attempt to connect to the service
            _serviceConnection.Connect();
        }
Example #12
0
        public void CreateService(Activity GelenBase, List <string> UrunListesi1)
        {
            UrunListesi = UrunListesi1;
            string value = Security.Unify(
                new string[] { "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAldTDiEEtSoBLcqpu2c1ddji30+E44DzFLDo5gd/yfxDevu1ue8HPrejHAc42OYLeP5YhNeW+",
                               "CMNSy6T7J7ocQABbw0xlANhMk7xp9xjfHFe7r8zyL0f2sjGX0CeGE7/lHCoRSxXQpH+QMkpR31phhm+3s5jX4+6iBr855rRb07Mz1ATCtfJug/psvumK",
                               "3NZLZOCCA+lTFnJ9lez0KZ+kwGB5qDx5EljGL+Kw1DTa9QZ67QPXpqf4S3Qp1DBMdje8/uf+6yGs6NWYFhaWVfRi0jFV6UiXhz23rJKTmPHFI5sAdIP7",
                               "OTxj0XBAvjVeia9mPNM4/awcSq2KJsdWZH+yYwIDAQAB" },
                new int[] { 0, 1, 2, 3 });


            _serviceConnection = new InAppBillingServiceConnection(GelenBase, value);

            _serviceConnection.Connect();
            _serviceConnection.OnConnected += _serviceConnection_OnConnected;
        }
        public void Connect()
        {
            DeviceDebugAndroid.LogToFileMethodStatic();

            if (activity != null)
            {
                inAppBillingServiceConnection = new InAppBillingServiceConnection(activity, GetPublicKey());

                // below events are unregistered in OnDisconnect()
                inAppBillingServiceConnection.OnConnected         += OnConnected;
                inAppBillingServiceConnection.OnInAppBillingError += OnInAppBillingError;
                inAppBillingServiceConnection.OnDisconnected      += OnDisconnected;

                inAppBillingServiceConnection.Connect();
            }
        }
Example #14
0
        public void StartSetup()
        {
            string value = Security.Unify(
                new string[] { "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvC1rCfTD2nVuEeLcxv7EfyjQZuX6igvBw1X/V2",
                               "kJ+zx4HuiBIk6V6FIpFifIFcyfkvrxzzPat8yWg8cUGU5HEfh+rhypv+zeTZsSbPDDBB/pgAv47UtPFXk2FFnrVZoxML5050Lu",
                               "Tn+nTJ++n5OBoubvM8wtkyNjKuuXyWTRW2yyslKPpIPAS7Q9AHUmSPZFHf0NybR5EGADdoqxnh4qr7sU5kS94J7y5K3HdtYHOidU59",
                               "m7bmvMyjUN7uwXgjBWRi1HywJR/yZeyZDekDASGuJCSKlbjjItDfR0K3BcoH4ti4SHsD+T2v",
                               "26cEoqGHGiICllySrqwhMUfgdm58b57QIDAQAB" },
                new int[] { 0, 1, 2, 3, 4 });

            _serviceConnection              = new InAppBillingServiceConnection(this, value);
            _serviceConnection.OnConnected += () =>
            {
                _serviceConnection.BillingHandler.OnGetProductsError += (int responseCode, Bundle ownedItems) => {
                    //Console.WriteLine("Error getting products");
                    Toast.MakeText(this, "Error getting products", ToastLength.Long).Show();
                };

                _serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) => {
                    //Console.WriteLine("Invalid owned items bundle returned");
                    Toast.MakeText(this, "Invalid owned items bundle returned", ToastLength.Long).Show();
                };

                _serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) => {
                    //Console.WriteLine("Error purchasing item {0}",sku);
                    Toast.MakeText(this, "Error purchasing item {0}" + sku, ToastLength.Long).Show();
                };

                _serviceConnection.BillingHandler.OnPurchaseConsumedError += (int responseCode, string token) => {
                    //Console.WriteLine("Error consuming previous purchase");
                    Toast.MakeText(this, "Error consuming previous purchase", ToastLength.Long).Show();
                };

                _serviceConnection.BillingHandler.InAppBillingProcesingError += (message) => {
                    //Console.WriteLine("In app billing processing error {0}",message);

                    Toast.MakeText(this, "In app billing processing error {0}" + message, ToastLength.Long).Show();
                };

                GetInventory();
                LoadPurchasedItems();
            };
            // Attempt to connect to the service
            _serviceConnection.Connect();
        }
Example #15
0
        public InAppBillingManager(Activity activity)
        {
            string value = Security.Unify(activity.Resources.GetStringArray(Resource.Array.billing_key), new int[] {
                0,
                1,
                2,
                3
            });

            _productId = activity.Resources.GetString(Resource.String.ads_product_id);

            _serviceConnection = new InAppBillingServiceConnection(activity, value);
            if (_serviceConnection != null)
            {
                _serviceConnection.OnConnected += OnConnected;
                _serviceConnection.Connect();
            }
        }
Example #16
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SatinAlTest);
            _buyButton        = FindViewById <Button>(Resource.Id.button1);
            _buyButton.Click += _buyButton_Click;
            string value = Security.Unify(
                new string[] { "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAldTDiEEtSoBLcqpu2c1ddji30+E44DzFLDo5gd/yfxDevu1ue8HPrejHAc42OYLeP5YhNeW+",
                               "CMNSy6T7J7ocQABbw0xlANhMk7xp9xjfHFe7r8zyL0f2sjGX0CeGE7/lHCoRSxXQpH+QMkpR31phhm+3s5jX4+6iBr855rRb07Mz1ATCtfJug/psvumK",
                               "3NZLZOCCA+lTFnJ9lez0KZ+kwGB5qDx5EljGL+Kw1DTa9QZ67QPXpqf4S3Qp1DBMdje8/uf+6yGs6NWYFhaWVfRi0jFV6UiXhz23rJKTmPHFI5sAdIP7",
                               "OTxj0XBAvjVeia9mPNM4/awcSq2KJsdWZH+yYwIDAQAB" },
                new int[] { 0, 1, 2, 3 });


            _serviceConnection = new InAppBillingServiceConnection(this, value);

            _serviceConnection.Connect();
            _serviceConnection.OnConnected += _serviceConnection_OnConnected;
        }
Example #17
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            PreferenceManager.SetDefaultValues(this, Resource.Xml.preferences, false);

            _pager         = FindViewById <ViewPager>(Resource.Id.pager);
            _pager.Adapter = new SectionsPagerAdapter(SupportFragmentManager);
            _pager.SetOnPageChangeListener(this);

            ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
            ActionBar.AddTab(ActionBar.NewTab().SetText("New").SetTabListener(this).SetTag("New"));
            ActionBar.AddTab(ActionBar.NewTab().SetText("Favorites").SetTabListener(this).SetTag("Favorites"));

            _serviceConnection              = new InAppBillingServiceConnection(this, PublicKey);
            _serviceConnection.OnConnected += HandleOnConnected;
            _serviceConnection.Connect();
        }
Example #18
0
        private void ConnectToService()
        {
            var key = Xamarin.InAppBilling.Utilities.Security.Unify(new[]
            {
                GetNumberString(3),
                GetNumberString(6),
                GetNumberString(1),
                GetNumberString(4),
                GetNumberString(2),
                GetNumberString(7),
                GetNumberString(0),
                GetNumberString(5)
            },
                                                                    new[] { 0, 1, 2, 3, 4, 5, 6, 7 }
                                                                    );

            _serviceConnection                      = new InAppBillingServiceConnection(this, key);
            _serviceConnection.OnConnected         += HandleOnConnected;
            _serviceConnection.OnInAppBillingError += ServiceConnectionOnInAppBillingError;
            _serviceConnection.Connect();
        }
Example #19
0
        private string _publickey = "Include your Public Key using the Google Play Console for Developers"; //Insert here your Public Key

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button btnShowItems = FindViewById <Button>(Resource.Id.btnShowItems);

            btnShowItems.Click += BtnShowItems_Click;

            Button btnBuyFake = FindViewById <Button>(Resource.Id.btnBuyFake);

            btnBuyFake.Click += BtnBuyFake_Click;

            Button btnBuyLevel1 = FindViewById <Button>(Resource.Id.btnBuyLevel1);

            btnBuyLevel1.Click += BtnBuyLevel1_Click;

            try
            {
                // Create a new connection to the Google Play Service
                _serviceConnection              = new InAppBillingServiceConnection(this, _publickey);
                _serviceConnection.OnConnected += _serviceConnection_OnConnected;

                // Attempt to connect to the service
                _serviceConnection.Connect();
            }
            catch (Exception exc)
            {
                throw exc;
            }
            //Remember to unbind from the In-app Billing service when you are done with your Activity
        }
Example #20
0
        public void Initialize()
        {
            // A Licensing and In-App Billing public key is required before an app can communicate with
            // Google Play, however you DON'T want to store the key in plain text with the application.
            // The Unify command provides a simply way to obfuscate the key by breaking it into two or
            // or more parts, specifying the order to reassemlbe those parts and optionally providing
            // a set of key/value pairs to replace in the final string.
            string value = Security.Unify(
                new string[] {
                "Insert part 0",
                "Insert part 3",
                "Insert part 2",
                "Insert part 1"
            },
                new int[] { 0, 3, 2, 1 });

            // Create a new connection to the Google Play Service
            _serviceConnection              = new InAppBillingServiceConnection(MainActivity.Instance, value);
            _serviceConnection.OnConnected += () =>
            {
                this._serviceConnection.BillingHandler.OnProductPurchased += (int response, Purchase purchase, string purchaseData, string purchaseSignature) =>
                {
                    // Record what we purchased
                    var epoch        = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    var purchaseTime = epoch.AddMilliseconds(purchase.PurchaseTime);
                    var newPurchase  = new InAppPurchase
                    {
                        OrderId      = purchase.OrderId,
                        ProductId    = purchase.ProductId,
                        PurchaseTime = purchaseTime
                    };
                    App.ViewModel.Purchases.Add(newPurchase);

                    // Let anyone know who is interested that purchase has completed
                    if (this.OnPurchaseProduct != null)
                    {
                        this.OnPurchaseProduct();
                    }
                };
                this._serviceConnection.BillingHandler.QueryInventoryError += (int responseCode, Bundle skuDetails) =>
                {
                    if (this.OnQueryInventoryError != null)
                    {
                        this.OnQueryInventoryError(responseCode, null);
                    }
                };
                this._serviceConnection.BillingHandler.BuyProductError += (int responseCode, string sku) =>
                {
                    // Note, BillingResult.ItemAlreadyOwned, etc. can be used to determine error

                    if (this.OnPurchaseProductError != null)
                    {
                        this.OnPurchaseProductError(responseCode, sku);
                    }
                };
                this._serviceConnection.BillingHandler.InAppBillingProcesingError += (string message) =>
                {
                    if (this.OnInAppBillingProcesingError != null)
                    {
                        this.OnInAppBillingProcesingError(message);
                    }
                };
                this._serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) =>
                {
                    if (this.OnInvalidOwnedItemsBundleReturned != null)
                    {
                        this.OnInvalidOwnedItemsBundleReturned(null);
                    }
                };
                this._serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) =>
                {
                    if (this.OnPurchaseProductError != null)
                    {
                        this.OnPurchaseProductError(responseCode, sku);
                    }
                };
                this._serviceConnection.BillingHandler.OnPurchaseFailedValidation += (Purchase purchase, string purchaseData, string purchaseSignature) =>
                {
                    if (this.OnPurchaseFailedValidation != null)
                    {
                        this.OnPurchaseFailedValidation(null, purchaseData, purchaseSignature);
                    }
                };
                this._serviceConnection.BillingHandler.OnUserCanceled += () =>
                {
                    if (this.OnUserCanceled != null)
                    {
                        this.OnUserCanceled();
                    }
                };

                this._connected = true;

                // Load inventory or available products
                this.QueryInventory();
            };

            /* Uncomment these if you want to be notified for these events
             * _serviceConnection.OnDisconnected += () =>
             * {
             *  System.Diagnostics.Debug.WriteLine("Remove");
             * };
             *
             * _serviceConnection.OnInAppBillingError += (error, message) =>
             *  {
             *      System.Diagnostics.Debug.WriteLine("Remove");
             *  };
             */

            // Are we connected to a network?
            ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.Instance.GetSystemService(MainActivity.ConnectivityService);
            NetworkInfo         activeConnection    = connectivityManager.ActiveNetworkInfo;

            if ((activeConnection != null) && activeConnection.IsConnected)
            {
                // Ok, carefully attempt to connect to the in-app service
                try
                {
                    _serviceConnection.Connect();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Exception trying to connect to in app service: " + ex);
                }
            }
        }
Example #21
0
        public void StartSetup()
        {
            // A Licensing and In-App Billing public key is required before an app can communicate with
            // Google Play, however you DON'T want to store the key in plain text with the application.
            // The Unify command provides a simply way to obfuscate the key by breaking it into two or
            // or more parts, specifying the order to reassemlbe those parts and optionally providing
            // a set of key/value pairs to replace in the final string.
            string value = Security.Unify(Constants.IN_APP_BILLING_PUBLIC_KEY, new int[] { 0, 1, 2, 3 });

            // Create a new connection to the Google Play Service
            _serviceConnection              = new InAppBillingServiceConnection(this, value);
            _serviceConnection.OnConnected += () =>
            {
                // Attach to the various error handlers to report issues
                _serviceConnection.BillingHandler.OnGetProductsError += (int responseCode, Bundle ownedItems) =>
                {
                    Console.WriteLine("Error getting products");
                };

                _serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) =>
                {
                    Console.WriteLine("Invalid owned items bundle returned");
                };

                _serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) =>
                {
                    Console.WriteLine("Error purchasing item {0}", sku);
                };

                _serviceConnection.BillingHandler.OnPurchaseConsumedError += (int responseCode, string token) =>
                {
                    Console.WriteLine("Error consuming previous purchase");
                };

                _serviceConnection.BillingHandler.InAppBillingProcesingError += (message) =>
                {
                    Console.WriteLine("In app billing processing error {0}", message);
                };

                _serviceConnection.BillingHandler.OnProductPurchased += (int response, Purchase purchase, string purchaseData, string purchaseSignature) =>
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Your Operation successed!");
                    alert.SetMessage("Purchased drop --- .");
                    alert.SetPositiveButton("Ok", (senderAlert, args) =>
                    {
                        Toast.MakeText(this, "OK!", ToastLength.Short).Show();
                    });

                    alert.SetNegativeButton("Cancel", (senderAlert, args) =>
                    {
                        Toast.MakeText(this, "Cancelled!", ToastLength.Short).Show();
                    });

                    Dialog dialog = alert.Create();
                    dialog.Show();
                };

                GetInventory();
            };

            // Attempt to connect to the service
            _serviceConnection.Connect();
        }
Example #22
0
        public void Initialize()
        {
            // A Licensing and In-App Billing public key is required before an app can communicate with
            // Google Play, however you DON'T want to store the key in plain text with the application.
            // The Unify command provides a simply way to obfuscate the key by breaking it into two or
            // or more parts, specifying the order to reassemlbe those parts and optionally providing
            // a set of key/value pairs to replace in the final string.
            string value = Security.Unify(
                new string[] {
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoCgVnYrLIlkOF4tZoX4bS8LJYtn2gzPQa68Csfgi33Q/v6AdB85rFsdZ0HMwdxkcN7mOkW2ktf19bD",
                "t+BT94sAxbry1qO9hD6QIDAQAB",
                "JI7qCFzXsCJ1/LV/hXSHAsiQOShE83sQnmk2FiwDi1yuj6SlA0uN8nO175o1rsTMmKE12CDCWH01eCaJSvwnpKI2xaJZ0wlPjRpnnup/6Flmsd7zTNa3Lw3fvK",
                "nzp5pSshUmQJhxQhXvVdXXGjQYsV6ai7SdQ4APvBT9abKMo7ZsnmC7wxohDFfk+3nHXOxZyYi9PKH6XpVTqgEfhzGi5/O7YivHT04/CphwCXUSYHMSZ/mLi60C"
            },
                new int[] { 0, 3, 2, 1 });

            // Create a new connection to the Google Play Service
            _serviceConnection              = new InAppBillingServiceConnection(MainActivity.Instance, value);
            _serviceConnection.OnConnected += () =>
            {
                this._serviceConnection.BillingHandler.OnProductPurchased += (int response, Purchase purchase, string purchaseData, string purchaseSignature) =>
                {
                    // Record what we purchased
                    var epoch        = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    var purchaseTime = epoch.AddMilliseconds(purchase.PurchaseTime);
                    var newPurchase  = new InAppPurchase
                    {
                        OrderId      = purchase.OrderId,
                        ProductId    = purchase.ProductId,
                        PurchaseTime = purchaseTime
                    };
                    App.ViewModel.Purchases.Add(newPurchase);

                    // Let anyone know who is interested that purchase has completed
                    if (this.OnPurchaseProduct != null)
                    {
                        this.OnPurchaseProduct();
                    }
                };
                this._serviceConnection.BillingHandler.QueryInventoryError += (int responseCode, Bundle skuDetails) =>
                {
                    if (this.OnQueryInventoryError != null)
                    {
                        this.OnQueryInventoryError(responseCode, null);
                    }
                };
                this._serviceConnection.BillingHandler.BuyProductError += (int responseCode, string sku) =>
                {
                    // Note, BillingResult.ItemAlreadyOwned, etc. can be used to determine error

                    if (this.OnPurchaseProductError != null)
                    {
                        this.OnPurchaseProductError(responseCode, sku);
                    }
                };
                this._serviceConnection.BillingHandler.InAppBillingProcesingError += (string message) =>
                {
                    if (this.OnInAppBillingProcesingError != null)
                    {
                        this.OnInAppBillingProcesingError(message);
                    }
                };
                this._serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) =>
                {
                    if (this.OnInvalidOwnedItemsBundleReturned != null)
                    {
                        this.OnInvalidOwnedItemsBundleReturned(null);
                    }
                };
                this._serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) =>
                {
                    if (this.OnPurchaseProductError != null)
                    {
                        this.OnPurchaseProductError(responseCode, sku);
                    }
                };
                this._serviceConnection.BillingHandler.OnPurchaseFailedValidation += (Purchase purchase, string purchaseData, string purchaseSignature) =>
                {
                    if (this.OnPurchaseFailedValidation != null)
                    {
                        this.OnPurchaseFailedValidation(null, purchaseData, purchaseSignature);
                    }
                };
                this._serviceConnection.BillingHandler.OnUserCanceled += () =>
                {
                    if (this.OnUserCanceled != null)
                    {
                        this.OnUserCanceled();
                    }
                };

                this._connected = true;

                // Load inventory or available products
                //  this.QueryInventory();
            };

            /* Uncomment these if you want to be notified for these events
             * _serviceConnection.OnDisconnected += () =>
             * {
             *  System.Diagnostics.Debug.WriteLine("Remove");
             * };
             *
             * _serviceConnection.OnInAppBillingError += (error, message) =>
             *  {
             *      System.Diagnostics.Debug.WriteLine("Remove");
             *  };
             */

            // Are we connected to a network?
            ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.Instance.GetSystemService(MainActivity.ConnectivityService);
            NetworkInfo         activeConnection    = connectivityManager.ActiveNetworkInfo;

            if ((activeConnection != null) && activeConnection.IsConnected)
            {
                // Ok, carefully attempt to connect to the in-app service
                try
                {
                    _serviceConnection.Connect();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Exception trying to connect to in app service: " + ex);
                }
            }
        }
 private void ConnectToStore()
 {
     _connection.Connect();
 }
        private async void AboutPageDonateButtonOnClick(View view)
        {
            InAppBillingServiceConnection connection = null;

            try
            {
                connection = new InAppBillingServiceConnection(Activity);
                var sem = new SemaphoreSlim(0);
                connection.OnConnected += (sender, args) => sem.Release();
                connection.Connect();
                if (await sem.WaitAsync(TimeSpan.FromSeconds(5)))
                {
                    //first try to redeem all existing ones
                    var ownedItems = connection.Service.GetPurchases(3, Context.PackageName, "inapp", null);
                    if (ownedItems.GetInt("RESPONSE_CODE") != 0)
                    {
                        throw new Exception();
                    }

                    // Get the list of purchased items
                    foreach (var purchaseData in ownedItems.GetStringArrayList("INAPP_PURCHASE_DATA_LIST"))
                    {
                        var o             = new JSONObject(purchaseData);
                        var purchaseToken = o.OptString("token", o.OptString("purchaseToken"));
                        // Consume purchaseToken, handling any errors
                        connection.Service.ConsumePurchase(3, Context.PackageName, purchaseToken);
                    }

                    var buyIntentBundle = connection.Service.GetBuyIntent(3, Context.PackageName,
                                                                          GetProductSku(), "inapp", "");
                    var pendingIntent = buyIntentBundle.GetParcelable("BUY_INTENT") as PendingIntent;
                    MainActivity.CurrentContext.StartIntentSenderForResult(pendingIntent.IntentSender, 1001,
                                                                           new Intent(), 0, 0, 0, Bundle.Empty);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                ResourceLocator.MessageDialogProvider.ShowMessageDialog(
                    "Something went wrong, you can always try later ^^", "Something went wrong™");
            }
            finally
            {
                connection?.Disconnected();
            }

            string GetProductSku()
            {
                switch (view.Id)
                {
                case Resource.Id.AboutPageDonate1Button:
                    return("donation1");

                case Resource.Id.AboutPageDonate2Button:
                    return("donate2");

                case Resource.Id.AboutPageDonate3Button:
                    return("donate3");

                case Resource.Id.AboutPageDonate4Button:
                    return("donate4");

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Example #25
0
 private Task <bool> Connect()
 {
     _tcsConnection = new TaskCompletionSource <bool> ();
     _serviceConnection.Connect();
     return(_tcsConnection.Task);
 }