public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			View.BackgroundColor = UIColor.White;

			stripeView = new StripeView ();
			stripeView.Frame = new CGRect (10, 100, stripeView.Frame.Width, stripeView.Frame.Height);

			buttonPay = new UIButton (UIButtonType.RoundedRect) {
				Frame = new CGRect (0, 160, View.Frame.Width, 50)
			};
			buttonPay.SetTitle ("Pay Now", UIControlState.Normal);
			buttonPay.TouchUpInside += async delegate {

				Card card = null;

				try {
					card = stripeView.Card;
				} catch (Exception ex) {
					var av = new UIAlertView ("Card Error", ex.Message, null, "OK");
					av.Show ();
					return;
				}

				var msg = string.Empty;

				try {
					var token = await StripeClient.CreateToken (card);

					msg = string.Format ("Good news! Stripe turned your credit card into a token: \n{0} \n\nYou can follow the instructions in the README to set up Parse as an example backend, or use this token to manually create charges at dashboard.stripe.com .", 
						token.Id);

				} catch (Exception ex) {
					msg = "Error: " + ex.Message;
				}

				var av2 = new UIAlertView ("Token Result", msg, null, "OK");
				av2.Show ();
			};

			View.AddSubview (stripeView);
			View.AddSubview (buttonPay);
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;

            stripeView       = new StripeView();
            stripeView.Frame = new CGRect(10, 100, stripeView.Frame.Width, stripeView.Frame.Height);

            buttonPay = new UIButton(UIButtonType.RoundedRect)
            {
                Frame = new CGRect(0, 160, View.Frame.Width, 50)
            };
            buttonPay.SetTitle("Pay Now", UIControlState.Normal);
            buttonPay.TouchUpInside += async delegate {
                Card card = null;

                try {
                    card = stripeView.Card;
                } catch (Exception ex) {
                    var av = new UIAlertView("Card Error", ex.Message, null, "OK");
                    av.Show();
                    return;
                }

                var msg = string.Empty;

                try {
                    var token = await StripeClient.CreateToken(card);

                    msg = string.Format("Good news! Stripe turned your credit card into a token: \n{0} \n\nYou can follow the instructions in the README to set up Parse as an example backend, or use this token to manually create charges at dashboard.stripe.com .",
                                        token.Id);
                } catch (Exception ex) {
                    msg = "Error: " + ex.Message;
                }

                var av2 = new UIAlertView("Token Result", msg, null, "OK");
                av2.Show();
            };

            View.AddSubview(stripeView);
            View.AddSubview(buttonPay);
        }
Esempio n. 3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Stripe.StripeClient.DefaultPublishableKey = STRIPE_PUBLISHABLE_KEY;

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            stripeView  = FindViewById <Stripe.StripeView> (Resource.Id.stripeView);
            name        = FindViewById <EditText> (Resource.Id.name);
            address1    = FindViewById <EditText> (Resource.Id.address1);
            address2    = FindViewById <EditText> (Resource.Id.address2);
            city        = FindViewById <EditText> (Resource.Id.city);
            state       = FindViewById <EditText> (Resource.Id.state);
            zip         = FindViewById <EditText> (Resource.Id.zip);
            country     = FindViewById <EditText> (Resource.Id.country);
            buttonToken = FindViewById <Button> (Resource.Id.buttonToken);

            buttonToken.Click += async delegate {
                var c = stripeView.Card;

                if (!c.IsCardValid)
                {
                    var errorMsg = "Invalid Card Information";

                    if (!c.IsNumberValid)
                    {
                        errorMsg = "Invalid Card Number";
                    }
                    else if (!c.IsValidExpiryDate)
                    {
                        errorMsg = "Invalid Card Expiry Date";
                    }
                    else if (!c.IsValidCvc)
                    {
                        errorMsg = "Invalid CVC";
                    }

                    Toast.MakeText(this, errorMsg, ToastLength.Short).Show();
                }
                else
                {
                    c.Name           = name.Text;
                    c.AddressLine1   = address1.Text;
                    c.AddressLine2   = address2.Text;
                    c.AddressCity    = city.Text;
                    c.AddressState   = state.Text;
                    c.AddressZip     = zip.Text;
                    c.AddressCountry = country.Text;

                    try {
                        var token = await StripeClient.CreateToken(c, STRIPE_PUBLISHABLE_KEY);

                        if (token != null)
                        {
                            //TODO: Send token to your server to process a payment with

                            var msg = string.Format("Good news! Stripe turned your credit card into a token: \n{0} \n\nYou can follow the instructions in the README to set up Parse as an example backend, or use this token to manually create charges at dashboard.stripe.com .",
                                                    token.Id);

                            Toast.MakeText(this, msg, ToastLength.Long).Show();
                        }
                        else
                        {
                            Toast.MakeText(this, "Failed to create Token", ToastLength.Short).Show();
                        }
                    } catch (Exception ex) {
                        Toast.MakeText(this, "Failure: " + ex.Message, ToastLength.Short).Show();
                    }
                }
            };
        }
Esempio n. 4
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			Stripe.StripeClient.DefaultPublishableKey = MainActivity.STRIPE_PUBLISHABLE_KEY;

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.CardInput);

			stripeView = FindViewById<Stripe.StripeView> (Resource.Id.stripeView);
			name = FindViewById<EditText> (Resource.Id.name);
			address1 = FindViewById<EditText> (Resource.Id.address1);
			address2 = FindViewById<EditText> (Resource.Id.address2);
			city = FindViewById<EditText> (Resource.Id.city);
			state = FindViewById<EditText> (Resource.Id.state);
			zip = FindViewById<EditText> (Resource.Id.zip);
			country = FindViewById<EditText> (Resource.Id.country);
			buttonToken = FindViewById<Button> (Resource.Id.buttonToken);

			buttonToken.Click += async delegate {
				var c = stripeView.Card;

				if (!c.IsCardValid) {
					var errorMsg = "Invalid Card Information";

					if (!c.IsNumberValid)
						errorMsg = "Invalid Card Number";
					else if (!c.IsValidExpiryDate)
						errorMsg = "Invalid Card Expiry Date";
					else if (!c.IsValidCvc)
						errorMsg = "Invalid CVC";

					Toast.MakeText(this, errorMsg, ToastLength.Short).Show();
				} else {
					c.Name = name.Text;
					c.AddressLine1 = address1.Text;
					c.AddressLine2 = address2.Text;
					c.AddressCity = city.Text;
					c.AddressState = state.Text;
					c.AddressZip = zip.Text;
					c.AddressCountry = country.Text;

					try {
						var token = await StripeClient.CreateToken (c, MainActivity.STRIPE_PUBLISHABLE_KEY);

						if (token != null) {

							//TODO: Send token to your server to process a payment with

							var msg = string.Format ("Good news! Stripe turned your credit card into a token: \n{0} \n\nYou can follow the instructions in the README to set up Parse as an example backend, or use this token to manually create charges at dashboard.stripe.com .", 
								token.Id);

							Toast.MakeText(this, msg, ToastLength.Long).Show();
						} else {
							Toast.MakeText(this, "Failed to create Token", ToastLength.Short).Show();
						}
					} catch (Exception ex) {
						Toast.MakeText (this, "Failure: " + ex.Message, ToastLength.Short).Show ();
					}
				}
			};
		}