Пример #1
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            clientName = Android.OS.Build.Manufacturer + " " + Android.OS.Build.Model;
            SetContentView(Resource.Layout.premium);

            Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

            InitElements();

            if (_databaseMethods.UserExists())
            {
                if (!_methods.IsConnected())
                {
                    NoConnectionActivity.ActivityName = this;
                    StartActivity(typeof(NoConnectionActivity));
                    Finish();
                    return;
                }
                var purchaseInfo = await _accounts.AccountAuthorize(_databaseMethods.GetAccessJwt(), clientName);

                //var deserialized_info = JsonConvert.DeserializeObject<AuthorizeRootObject>(purchase_info);
                AuthorizeAfterPurchase(purchaseInfo);
            }

            FindViewById <RelativeLayout>(Resource.Id.backRL).Click += (s, e) => OnBackPressed();

            _monthBn.Click += async(s, e) =>
            {
                if (!_databaseMethods.UserExists())
                {
                    call_login_menu();
                    return;
                }

                if (!_methods.IsConnected())
                {
                    NoConnectionActivity.ActivityName = this;
                    StartActivity(typeof(NoConnectionActivity));
                    Finish();
                    return;
                }

                _monthActivityIndicator.Visibility = ViewStates.Visible;
                _monthBn.Visibility = ViewStates.Gone;

                string productId = "month_auto_subscription";
                InAppBillingService  inAppBillingService = new InAppBillingService();
                InAppBillingPurchase purchase            = new InAppBillingPurchase();

                var authorizeCheck = await _accounts.AccountAuthorize(_databaseMethods.GetAccessJwt(), clientName);

                if (/*res_card_data == Constants.status_code409 ||*/ authorizeCheck == Constants.status_code401)
                {
                    ShowSeveralDevicesRestriction();
                    return;
                }
                var deserialized = JsonConvert.DeserializeObject <AuthorizeRootObject>(authorizeCheck);
                if (deserialized != null)
                {
                    var jsonObj   = JsonConvert.SerializeObject(new { accountID = deserialized.accountID.ToString() });
                    var textBytes = Encoding.UTF8.GetBytes(jsonObj);
                    var base64    = Convert.ToBase64String(textBytes);

                    if (deserialized.accountID != null)
                    {
                        purchase = await inAppBillingService.PurchaseSubscription(productId, base64);
                    }
                }
                //else
                //purchase = await inAppBillingService.PurchaseSubscription(product_id, String.Empty);
                if (purchase != null)
                {
                    Toast.MakeText(this, TranslationHelper.GetString("waitServerSync", _ci), ToastLength.Short).Show();
                    // Inform our server.

                    var notifyServer = await _accounts.AccountSubscribeAndroid(_databaseMethods.GetAccessJwt(),
                                                                               3,
                                                                               purchase.ProductId,
                                                                               purchase.PurchaseToken);

                    //var notify_server = await accounts.AccountSubscribe(
                    //databaseMethods.GetAccessJwt(),
                    //Constants.personalGoogle.ToString(),
                    //purchase,
                    //DateTime.UtcNow.AddDays(1), // ATTENTION with days.
                    //NativeMethods.GetDeviceId()
                    //);

                    var authorizeCheckAfterPurchase = await _accounts.AccountAuthorize(_databaseMethods.GetAccessJwt(), clientName);

                    AuthorizeAfterPurchase(authorizeCheckAfterPurchase);
                    _monthActivityIndicator.Visibility = ViewStates.Gone;
                    Toast.MakeText(this, TranslationHelper.GetString("syncDoneSuccessfully", _ci), ToastLength.Short).Show();
                    return;
                }
                _monthActivityIndicator.Visibility = ViewStates.Gone;
                _monthBn.Visibility = ViewStates.Visible;
            };

            _yearBn.Click += async(s, e) =>
            {
                if (!_databaseMethods.UserExists())
                {
                    call_login_menu();
                    return;
                }

                if (!_methods.IsConnected())
                {
                    NoConnectionActivity.ActivityName = this;
                    StartActivity(typeof(NoConnectionActivity));
                    Finish();
                    return;
                }

                _yearActivityIndicator.Visibility = ViewStates.Visible;
                _yearBn.Visibility = ViewStates.Gone;

                string productId = "year_auto_subscription";
                InAppBillingService  inAppBillingService = new InAppBillingService();
                InAppBillingPurchase purchase            = new InAppBillingPurchase();

                var authorizeCheck = await _accounts.AccountAuthorize(_databaseMethods.GetAccessJwt(), clientName);

                if (/*res_card_data == Constants.status_code409 ||*/ authorizeCheck == Constants.status_code401)
                {
                    ShowSeveralDevicesRestriction();
                    return;
                }
                var deserialized = JsonConvert.DeserializeObject <AuthorizeRootObject>(authorizeCheck);
                if (deserialized != null)
                {
                    var jsonObj   = JsonConvert.SerializeObject(new { accountID = deserialized.accountID.ToString() });
                    var textBytes = Encoding.UTF8.GetBytes(jsonObj);
                    var base64    = Convert.ToBase64String(textBytes);

                    if (deserialized.accountID != null)
                    {
                        purchase = await inAppBillingService.PurchaseSubscription(productId, base64);
                    }
                }
                //else
                //purchase = await inAppBillingService.PurchaseSubscription(product_id, String.Empty);
                if (purchase != null)
                {
                    Toast.MakeText(this, TranslationHelper.GetString("waitServerSync", _ci), ToastLength.Short).Show();
                    // Inform our server.

                    var notifyServer = await _accounts.AccountSubscribeAndroid(_databaseMethods.GetAccessJwt(),
                                                                               3,
                                                                               purchase.ProductId,
                                                                               purchase.PurchaseToken);

                    //var notify_server = await accounts.AccountSubscribe(
                    //databaseMethods.GetAccessJwt(),
                    //Constants.personalGoogle.ToString(),
                    //purchase,
                    //DateTime.UtcNow.AddDays(1), // ATTENTION with days.
                    //NativeMethods.GetDeviceId()
                    //);

                    var authorizeCheckAfterPurchase = await _accounts.AccountAuthorize(_databaseMethods.GetAccessJwt(), clientName);

                    AuthorizeAfterPurchase(authorizeCheckAfterPurchase);
                    _yearActivityIndicator.Visibility = ViewStates.Gone;
                    Toast.MakeText(this, TranslationHelper.GetString("syncDoneSuccessfully", _ci), ToastLength.Short).Show();
                    return;
                }
                _yearActivityIndicator.Visibility = ViewStates.Gone;
                _yearBn.Visibility = ViewStates.Visible;
            };

            _termsBn.Click += (s, e) =>
            {
                var uri = Android.Net.Uri.Parse("https://myqrcards.com/agreement/ru");
                StartActivity(new Intent(Intent.ActionView, uri));
            };
            _politicsBn.Click += (s, e) =>
            {
                var uri = Android.Net.Uri.Parse("https://myqrcards.com/privacy-policy/ru");
                StartActivity(new Intent(Intent.ActionView, uri));
            };
        }
Пример #2
0
        private void BuySubs(string product_id)
        {
            if (!databaseMethods.userExists())
            {
                call_login_menu();
                return;
            }
            activityIndicator.Hidden    = false;
            month_bn.Hidden             = true;
            month_subscriptionTV.Hidden = true;
            year_bn.Hidden             = true;
            year_subscriptionTV.Hidden = true;
            InvokeInBackground(async() =>
            {
                InAppBillingService inAppBillingService = new InAppBillingService();
                //var gkgj = await inAppBillingService.PurchaseItemAsync();
                //var detais = await inAppBillingService.GetProductDetails(product_id);
                //var was_purchased_before = await inAppBillingService.WasItemPurchasedAsync(product_id);
                InAppBillingPurchase purchase = new InAppBillingPurchase();
                //if (!was_purchased_before)
                {
                    InvokeOnMainThread(() =>
                    {
                        activityIndicator.Hidden    = false;
                        month_bn.Hidden             = true;
                        month_subscriptionTV.Hidden = true;
                        InvokeInBackground(async() =>
                        {
                            string authorize_check = null;
                            try
                            {
                                authorize_check = await accounts.AccountAuthorize(databaseMethods.GetAccessJwt(), UDID);
                            }
                            catch
                            {
                                if (!methods.IsConnected())
                                {
                                    InvokeOnMainThread(() =>
                                    {
                                        NoConnectionViewController.view_controller_name = GetType().Name;
                                        this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                                        return;
                                    });
                                }
                                return;
                            }
                            if (/*res_card_data == Constants.status_code409 ||*/ authorize_check == Constants.status_code401)
                            {
                                InvokeOnMainThread(() =>
                                {
                                    ShowSeveralDevicesRestriction();
                                    return;
                                });
                                return;
                            }
                            var deserialized = JsonConvert.DeserializeObject <AuthorizeRootObject>(authorize_check);
                            if (deserialized != null)
                            {
                                var jsonObj   = JsonConvert.SerializeObject(new { accountID = deserialized.accountID.ToString() });
                                var textBytes = Encoding.UTF8.GetBytes(jsonObj);
                                var base64    = Convert.ToBase64String(textBytes);

                                if (deserialized.accountID != null)
                                {
                                    purchase = await inAppBillingService.PurchaseSubscription(product_id, base64);
                                }
                            }
                            //else
                            //purchase = await inAppBillingService.PurchaseSubscription(product_id, String.Empty);
                            if (purchase != null)
                            {
                                InvokeOnMainThread(() =>
                                {
                                    ShowAttentionSyncWaiting();
                                });
                                // Inform our server.
                                var UDID = UIDevice.CurrentDevice.IdentifierForVendor.ToString();
                                string authorize_check_after_purchase = null;
                                try
                                {
                                    var notify_server = await accounts.AccountSubscribe(
                                        databaseMethods.GetAccessJwt(),
                                        Constants.personalApple.ToString(),
                                        purchase,
                                        DateTime.UtcNow.AddDays(1),             // ATTENTION with days.
                                        UDID);

                                    authorize_check_after_purchase = await accounts.AccountAuthorize(databaseMethods.GetAccessJwt(), UDID);
                                }
                                catch
                                {
                                    if (!methods.IsConnected())
                                    {
                                        InvokeOnMainThread(() =>
                                        {
                                            NoConnectionViewController.view_controller_name = GetType().Name;
                                            this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                                            return;
                                        });
                                    }
                                    return;
                                }
                                InvokeOnMainThread(() =>
                                {
                                    AuthorizeAfterPurchase(authorize_check_after_purchase);
                                    ShowSyncSuccessful();
                                });
                            }

                            InvokeOnMainThread(() =>
                            {
                                activityIndicator.Hidden    = true;
                                month_bn.Hidden             = false;
                                month_subscriptionTV.Hidden = false;
                                year_bn.Hidden             = false;
                                year_subscriptionTV.Hidden = false;
                            });
                        });
                    });
                }
            });
        }