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 #2
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 #3
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 #4
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
        }
 /// <summary>
 /// Connect to billing service
 /// </summary>
 /// <returns>If Success</returns>
 public override Task <bool> ConnectAsync(ItemType itemType = ItemType.InAppPurchase)
 {
     serviceConnection = new InAppBillingServiceConnection(Context, itemType);
     tcsPurchase?.TrySetCanceled();
     tcsPurchase = null;
     return(serviceConnection.ConnectAsync());
 }
Example #6
0
        private void OnConnected()
        {
            try
            {
                _isInitializing = true;
                SAMLog.Debug($"AndroidBilling.OnConnected[1]");

                _serviceConnection.BillingHandler.QueryInventoryError        += QueryInventoryError;
                _serviceConnection.BillingHandler.BuyProductError            += BuyProductError;
                _serviceConnection.BillingHandler.OnProductPurchased         += OnProductPurchased;
                _serviceConnection.BillingHandler.OnProductPurchasedError    += OnProductPurchasedError;
                _serviceConnection.BillingHandler.OnPurchaseFailedValidation += OnPurchaseFailedValidation;

                _purchases = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product).ToList();
                SAMLog.Debug($"AndroidBilling.OnConnected[2]");


                _products = _serviceConnection.BillingHandler.QueryInventoryAsync(_productIDs.ToList(), ItemType.Product).Result.ToList();
                SAMLog.Debug($"AndroidBilling.OnConnected[3]");
            }
            catch (Exception e)
            {
                SAMLog.Info("IAB::OnConnected", e);
                _serviceConnection = null;
            }
            finally
            {
                _isInitializing = false;
            }
        }
		public void StartSetup ()
		{
			_serviceConnection = new InAppBillingServiceConnection (this, string.Empty);
			_serviceConnection.OnConnected += HandleOnConnected; 

			_serviceConnection.Connect ();
		}
Example #8
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 #9
0
 public void StartSetup()
 {
     if (InAppPurchase._products != null)
     {
         _products          = InAppPurchase._products;
         _serviceConnection = InAppPurchase._serviceConnection;
     }
 }
 public void Disconnect()
 {
     if (_connection != null)
     {
         _connection.Disconnect();
         _connection = null;
         _activity   = null;
     }
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gifaroo.Android.BillingInventory+StoreItem"/> class.
 /// </summary>
 /// <param name="itemProduct">Item product.</param>
 /// <param name="itemPurchase">Item purchase.</param>
 public StoreItem(
     global::Android.Content.Context context,
     InAppBillingServiceConnection serviceConnection,
     String itemName)
 {
     this._serviceConnection = serviceConnection;
     this._context           = context;
     this.itemName           = itemName;
 }
Example #12
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();
            }
        }
        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();
                }
            }
        }
Example #14
0
 //cosntructor
 public PremiumInterface(
     global::Android.Content.Context context,
     InAppBillingServiceConnection serviceConnection)
 {
     this.serviceConnection = serviceConnection;
     this._context          = context;
     _ProductsDictionary    = new Dictionary <string, StoreItem> ()
     {
         { PremiumInterface.SKUs.Blurs_patterns_BGPack_SKU, new StoreItem(context, serviceConnection, "Blurs & Patterns Background Bundle") },
         { PremiumInterface.SKUs.Gradients_Night_BGPack_SKU, new StoreItem(context, serviceConnection, "Gradient Nights Background Bundle") },
         { PremiumInterface.SKUs.Fonts_Pack_SKU, new StoreItem(context, serviceConnection, "All Fonts Pack") }
     };
 }
Example #15
0
        /// <summary>
        /// Creates a new instance of the <see cref="SaneInAppBillingHandler"/> class.
        /// </summary>
        /// <param name="activity">
        /// The activity you're hosting this <see cref="SaneInAppBillingHandler"/> in.
        /// </param>
        /// <param name="publicKey">The key you received from Google for your In-App purchases.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="activity"/> or <paramref name="publicKey"/> is <c>null</c>.
        /// </exception>
        public SaneInAppBillingHandler(Activity activity, string publicKey)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }

            if (publicKey == null)
            {
                throw new ArgumentNullException(publicKey);
            }

            this.serviceConnection = new InAppBillingServiceConnection(activity, publicKey);
        }
        /// <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();
        }
        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 #18
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;
        }
Example #19
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 #20
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 #21
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 #22
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();
        }
        protected override void OnCreate(Bundle bundle)
        {
            _bundle = bundle;
            base.OnCreate(bundle);

            FrameLayout Layout = new FrameLayout(this);

            _game = new Game1();
            SetContentView(_game.Services.GetService <View>());

            Data.Profile.Settings.Identity = (Settings.Secure.GetString(this.ContentResolver, Settings.Secure.AndroidId));

            UrlProvider.PackageName = ApplicationContext.PackageName;

            SwitchToBrowser = false;

            _game.Run();

            NetManager = (ConnectivityManager)GetSystemService(ConnectivityService);
            BillingServiceConnection = null;
        }
Example #24
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 #25
0
        private 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 [] {
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0KP6VqbDwzb7oMLyX4HAP/SaKiBFxeyG54WHZdNaYY2jzVIYoyYeyLloraXWG3qDtJsvH1d2Gs",
                "Y24QzTWU5Qkm91LcUHJBsTbjYdzO/d9oEtbHeMQ+2HQbQiC1WDX01R39R+sccm+J5uC+MHOKzugnwLerHM8IuULKqHI8NLiz7cwSP1hXXMjCIo1sNeXiBG",
                "GvViHBu8tm4rB48De1yUGU+q5v2SnrShKLRGVmuKg8OlJ/O7TpMWliWZOekPGUPjM4c60uFvvRCPD4snfwyMuYb2BlWJM8CHqblpbsp5P9BKSse/oXOSzq",
                "G3r9t4lJasSYsCXT6+laH6sSwTi3m4mwIDAQAB"
            },
                new [] { 0, 1, 2, 3 });

            // Create a new connection to the Google Play Service
            _serviceConnection                      = new InAppBillingServiceConnection(Forms.Context as Activity, value);
            _serviceConnection.OnConnected         += OnConnected;
            _serviceConnection.OnDisconnected      += OnDisconnected;
            _serviceConnection.OnInAppBillingError += OnInAppBillingError;
        }
Example #26
0
        private 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 [] {
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuYyJLgxpwNLhsqzkGw/qA0j",
                "335u7gCKh1aWCAmoDgNJYmFdLxpYcgJJWFfnZbWiAHoivRwk9qvRxq8Lea1nXNMIBkQY5LnFM",
                "QzaGPzculqFssramTWizDEIR8ptelluUzr1qtVOoSeyjjrIXgqmHwSCILJ7knKr823lfaimeJNPorR",
                "Z+0xxJ3zPSf/DGIO4Kkzk/aLSvRqREiIYX0XB2leYJJxFJ5nJapJ7uS+BgsOCJSaM9aKbtNORmf7pPLIzvjpWl",
                "GcAhp+bFnu93zVDf9OKhW28/lHypIa9y4eKx12ojwr1+E1ogDX/CjivEWMve66xbp0+znuwyT2nj0ExCKwIDAQAB"
            },
                new [] { 0, 1, 2, 3, 4 });

            // Create a new connection to the Google Play Service
            _serviceConnection                      = new InAppBillingServiceConnection(MainActivity.Current, value);
            _serviceConnection.OnConnected         += OnConnected;
            _serviceConnection.OnDisconnected      += OnDisconnected;
            _serviceConnection.OnInAppBillingError += OnInAppBillingError;
        }
 private void InitConnectToGoogleStore()
 {
     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.BindErrors();
         _serviceConnection.OnConnected += _serviceConnection_OnConnected;
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class.Name, "InitConnectToGoogleStore", exception, false);
     }
 }
        public override void Activate()
        {
            _returnToGame = NextSceneParameters.Get <bool>("return-to-game");

            Type[]        types                 = Assembly.GetExecutingAssembly().GetTypes();
            List <string> providers             = new List <string>();
            Dictionary <string, string> lookups = new Dictionary <string, string>();

            foreach (Type t in types)
            {
                PropertyInfo pi = t.GetProperty(Bopscotch.Definitions.KeyChain, BindingFlags.NonPublic | BindingFlags.Static);
                if (pi != null)
                {
                    providers.Add(t.FullName);
                    lookups.Add(t.FullName, pi.GetValue(null).ToString());
                }
            }
            providers = providers.OrderBy(x => x.LastIndexOf('.')).ToList();

            string sk = "";

            foreach (string p in providers)
            {
                sk = sk + lookups[p];
            }

            _connection              = new InAppBillingServiceConnection(Bopscotch.Game1.Activity, sk);
            _connection.OnConnected += LoadProducts;

            MainActivity.BillingServiceConnection = _connection;

            base.Activate();

            MusicManager.StopMusic();

            ActivateDialog("loading-store");
        }
Example #29
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 #30
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);
                }
            }
        }
 /// <summary>
 /// Default Constructor for In App Billing Implemenation on Android
 /// </summary>
 public InAppBillingImplementation()
 {
     serviceConnection = new InAppBillingServiceConnection(Context);
 }