public async Task <string> GetCardToken(string cardName, string cardNumber, int expiryMonth, int expiryYear, string cvc) { var card = new Card { Name = cardName, Number = cardNumber, ExpiryMonth = expiryMonth, ExpiryYear = expiryYear, CVC = cvc }; Console.WriteLine("stripe credit card request params:\n" + card.ToString()); try { var token = await StripeClient.CreateToken(card); return(token.Id); } catch (Exception ex) { Console.WriteLine(ex); } return(null); }
async Task HandlePaymentAuthorization(PKPayment payment, Action <PKPaymentAuthorizationStatus> completion, bool isTest = false, bool shouldTestFail = false) { try { Token token = null; if (isTest) { token = await StripeClient.CreateTestToken(payment, shouldTestFail); } else { token = await StripeClient.CreateToken(payment); } 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); var avMsg = new UIAlertView("Todo: Submit this token to your backend", msg, null, "OK"); avMsg.Show(); completion(PKPaymentAuthorizationStatus.Success); } catch (Exception ex) { var avMsg = new UIAlertView("Payment Failed", ex.Message, null, "OK"); avMsg.Show(); } }
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 async Task ExecuteSaveCardDetailsCommand() { if (IsBusy) { return; } IsBusy = true; card = new Card { Number = _cardNumber, ExpiryMonth = int.Parse(_expirationDateM), ExpiryYear = int.Parse(_expirationDateY), CVC = _CVC.ToString() }; try { var token = await StripeClient.CreateToken(card); var stripeService = (StripeService)ServiceLocator.Instance.Resolve <IStripeProvider>(); StripeTempToken stripeToken = new StripeTempToken(token); StripeResponse response = await stripeService.CreateCreditCard(stripeToken); var loginProvider = DependencyService.Get <ILoginProvider>(); Account acc = loginProvider.RetreiveAccountFromSecureStore(); acc.Properties.Add(Constants.stripeAccountIdPropertyName, response.ObjectJson); loginProvider.SaveAccountInSecureStore(acc); Console.WriteLine("Response: " + response.RequestDate); // Slightly different for non-Apple Pay use, see // 'Sending the token to your server' for more info //await CreateBackendCharge(token); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Items Not Loaded", ex.Message, "OK"); } finally { IsBusy = false; } }
private async void SaveCard(Models.Card card) { var stripeCard = new Stripe.Card { Name = card.Name, Number = card.Number, ExpiryMonth = card.ExpiryMonth, ExpiryYear = card.ExpiryYear, CVC = card.CVC }; try { await StripeClient.CreateToken(stripeCard, StripeClient.DefaultPublishableKey); StripeConfiguration.SetApiKey(StripeClientConstants.ApiKey); //"sk_test_BQokikJOvBiI2HlWgH4olfQ2"); } catch (Exception ex) { // Handle a failure Console.WriteLine(ex); } }
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(); } } }; }