Ejemplo n.º 1
0
        public override Task StoreValuesAsync(ProviderAuthorisationResult providerAuthResult, string storagePath = null)
        {
            //Store the authorisation details for later use.
            if (providerAuthResult == null)
            {
                throw new ArgumentNullException(nameof(providerAuthResult));
            }

            ProviderAuthorisationResult = providerAuthResult;

            if (!string.IsNullOrEmpty(storagePath))
            {
                //Up to the caller to ensure appropriate permissions exist.
                File.WriteAllText(storagePath, Convert.ToBase64String(Encoding.UTF8.
                                                                      GetBytes(JsonConvert.SerializeObject(providerAuthResult))));
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        private async void DonationButton_Click(object sender, EventArgs e)
        {
            PopUpHelper popUpHelper = new PopUpHelper();
            PopupWindow popupWindow = popUpHelper.ShowLoadingPopUp(Context, View);

            string key = Context.GetString(Resource.String.paystack_secret);

            //Validate input and key before processing.

            if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(amountText.Text))
            {
                paystack = new PaystackObject(key);

                AuthorisationDetails authorisationDetails = new PaystackAuthorisationDetails
                {
                    Amount   = amountText.Text,
                    Channels = new string[] { "bank", "card" },
                    Email    = donorEmailAddress.Text
                };

                ProviderAuthorisationResult authResult = await paystack.AuthoriseAsync(authorisationDetails);

                try
                {
                    string path = System.IO.Path.Combine(PathHelper.GetOrCreateAuthDetailsPath(), "auth.exr");
                    //Important if you need to verify later.
                    await paystack.StoreValuesAsync(authResult, path);

                    Intent intent = new Intent(Context, typeof(TestActivity));

                    intent.PutExtra(PaystackOptions.PAYSTACK_TRANSFER_KEY, authResult.AuthEndpoint);

                    popupWindow.Dismiss();

                    StartActivityForResult(intent, 2500);
                }
                catch
                {
                    return;
                }
            }
        }
Ejemplo n.º 3
0
 public abstract Task StoreValuesAsync(ProviderAuthorisationResult providerAuthorisationResult, string storagePath = null);
Ejemplo n.º 4
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";
                    });
                }
            });
        }