Пример #1
0
        public override async void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            if (requestCode == 2500)
            {
                if (paystack != null)
                {
                    //Verify the transaction.
                    string storedReference = paystack.GetReference();

                    var result = await paystack.VerifyTransactionAsync(storedReference);

                    if (result.status)
                    {
                        //Transaction was successful.
                        //Save user donation.
                        //var editor = sharedPreferences.Edit();
                        //editor.PutBoolean(ExtractRAdManager.USER_DONATION_KEY, true);
                        //editor.Apply();
                        ////User has donated.
                        ///
                        ExtractRAdManager.SetUserHasDonated(this.Context);
                    }

                    if (null != result)
                    {
                        Toast.MakeText(Context, $"{result.message} {result.data.amount}", ToastLength.Long).Show();
                    }

                    else
                    {
                        Toast.MakeText(Context, "Error occurred", ToastLength.Short).Show();
                    }
                }
            }

            base.OnActivityResult(requestCode, resultCode, data);
        }
Пример #2
0
        private async void DonationRefreshButton_Click(object sender, EventArgs e)
        {
            await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    mainActivity.RunOnUiThread(() =>
                    {
                        donationRefreshButton.Text = "Verifying....";
                    });
                    //Try to refresh the user's transaction.
                    string file = System.IO.File.ReadAllText(System.IO.Path.Combine(PathHelper.GetOrCreateAuthDetailsPath(), "auth.exr"));
                    string json = Encoding.UTF8.GetString(Convert.FromBase64String(file));

                    ProviderAuthorisationResult providerAuthorisationResult =
                        JsonConvert.DeserializeObject <ProviderAuthorisationResult>(json);

                    if (providerAuthorisationResult.Status.ToLower() == "ok")
                    {
                        mainActivity.RunOnUiThread(() =>
                        {
                            GetDialogBuilder()
                            .SetTitle("Transaction Successfully Verified")
                            .SetMessage("Congratulations! We have successfully verified your transaction. " +
                                        "You should restart the application for the changes to take effect. " +
                                        "Sorry for the inconvenience.")
                            .SetCancelable(false)
                            .SetNeutralButton("OK", (s, e) => { return; })
                            .Show();

                            donationRefreshButton.Text = "I have Donated";
                        });

                        ExtractRAdManager.SetUserHasDonated(this.Context);
                    }
                    else
                    {
                        mainActivity.RunOnUiThread(() =>
                        {
                            GetDialogBuilder()
                            .SetTitle("Transaction Failed")
                            .SetMessage("We are unable to verify your transaction. It looks like your transaction was not successful.")
                            .SetCancelable(false)
                            .SetNeutralButton("OK", (s, e) => { return; })
                            .Show();
                            donationRefreshButton.Text = "I have Donated";
                        });
                    }
                }
                catch
                {
                    mainActivity.RunOnUiThread(() =>
                    {
                        GetDialogBuilder()
                        .SetTitle("An Error Occured")
                        .SetMessage("We are unable to validate the transaction right now. Please try again later.")
                        .SetCancelable(false)
                        .SetNeutralButton("OK", (s, e) => { return; })
                        .Show();


                        donationRefreshButton.Text = "I have Donated";
                    });
                }
            });
        }