Exemple #1
0
        private async void MakePayment()
        {
            FragmentTransaction transaction  = FragmentManager.BeginTransaction();
            ProgressDialog      progressDiag = new ProgressDialog();

            progressDiag.Show(transaction, "dialog fragment");

            string paymentAmount = _edtPaymentAmount.Text == string.Empty ? "-" : _edtPaymentAmount.Text;
            string nfcReaderId   = NFCSettings.GetSettings(ApplicationContext, "nfc_id");
            string json          = string.Format("{{ \"nfc_id\": \"{0}\", \"amount\": \"{1}\"}}", nfcReaderId, paymentAmount);

            try
            {
                Log.Warn(_tag, json);
                string response = await Http.Request("https://thawing-ocean-8598.herokuapp.com/create-order", json, _seller.stripeToken);

                NFCSettings.SaveSettings(ApplicationContext, "sellerToken", _seller.stripeToken);
                OpenDialog(typeof(Beam), "Apmokejimas sukurtas sekmnigai!");
            }
            catch (Exception ex)
            {
                Log.Warn(_tag, ex.Message);
                OpenDialog(null, ex.Message);
            }
            finally
            {
                progressDiag.Dismiss();
            }
        }
        private async void MakePayment(string token)
        {
            string nfcReaderId = NFCSettings.GetSettings(ApplicationContext, "nfc_id");
            string sellerToken = NFCSettings.GetSettings(ApplicationContext, "sellerToken");
            string json        = string.Format("{{ \"nfc_id\": \"{0}\", \"buyer_auth_token\": \"{1}\"}}", nfcReaderId, token);

            try
            {
                string response = await Http.Request("https://thawing-ocean-8598.herokuapp.com/pay-order", json, sellerToken);

                OpenDialog();
            }
            catch (Exception ex)
            {
                Log.Warn(_tag, ex.Message);
            }
        }
Exemple #3
0
        protected async void Login()
        {
            FragmentTransaction transaction  = FragmentManager.BeginTransaction();
            ProgressDialog      progressDiag = new ProgressDialog();

            progressDiag.Show(transaction, "dialog fragment");

            string email    = _emailInput.Text == string.Empty ? "-" : _emailInput.Text;
            string password = _passwordInput.Text == string.Empty ? "-" : _passwordInput.Text;
            //check the input
            string json = string.Format("{{ \"user\": {{ \"email\":\"{0}\", \"password\":\"{1}\"}} }}", email, password);

            try
            {
                string response = await Http.Request("https://thawing-ocean-8598.herokuapp.com/login", json, null);

                if (response != string.Empty && response.Contains("auth_token"))
                {
                    //string temp = response.Split(':')[1].Trim();
                    //string token = temp.Substring(1, temp.Length - 3);
                    JObject dict  = JObject.Parse(response);                    //NuGet packet: Newtonsoft.Json
                    string  token = dict["auth_token"].ToString();
                    string  group = dict["type"].ToString();
                    Log.Warn(_tag, "tocken: " + token);
                    User user = new User(email, password, token);
                    user.group = group;

                    Intent userActivity;
                    if (group == "seller")
                    {
                        string sellerInfo = Http.GetRequest("https://thawing-ocean-8598.herokuapp.com/register-nfc", token);
                        userActivity = new Intent(this, typeof(SellerMainActivity));
                        if (NFCSettings.GetSettings(ApplicationContext, "nfc_id") == "no-id")
                        {
                            Log.Warn(_tag, "not yet registered");
                            JObject seller = JObject.Parse(sellerInfo);
                            string  nfc_id = seller["device_id"].ToString();
                            NFCSettings.SaveSettings(ApplicationContext, "nfc_id", nfc_id);
                            Log.Warn(_tag, "nfc id: " + nfc_id);
                        }
                    }
                    else
                    {
                        userActivity = new Intent(this, typeof(UserMainActivity));
                    }



                    userActivity.PutExtra("User", Json.Serialize(user));
                    StartActivity(userActivity);
                }
                else
                {
                    new Exception("Nepavyko prisijungti");
                }
            }
            catch (Exception ex)
            {
                Log.Warn(_tag, ex.Message);
                OpenDialog(null, ex.Message);
            }
            finally
            {
                progressDiag.Dismiss();
            }
        }