private async Task <PaymentResponse> PayWithCC(CreditCard cc) { PaymentResponse paymentResponse = new PaymentResponse(); try { StripeServices stripe = new StripeServices(); CardValidate ccValidate = stripe.CardToToken(cc).Result; if (!String.IsNullOrEmpty(ccValidate.ccConfirm)) { cc.token = ccValidate.ccConfirm; string strMoneyValue = TotalTextBox.Text; decimal decimalMoneyValue = decimal.Parse(strMoneyValue, NumberStyles.Currency); paymentResponse = await MakeStripePayment(cc, decimalMoneyValue); //paymentResponse = p.Result; paymentResponse.ccConfirm = ccValidate.ccConfirm; } else { paymentResponse.Messages.Add("Stripe", ccValidate.ErrorMessages); } } catch (Exception ex) { //CANNOT save cc data to db Exception ex2 = new Exception("PayWithCC", ex); ((App)App.Current).LogError(ex2.Message, "Card holder name is " + NameOnCardTextBox.Text); } return(paymentResponse); }
/// <summary> /// 验证 /// </summary> /// <param name="passStr"></param> /// <returns></returns> public bool ValidateInfo(string inputInfo) { Validate validate = null; string prefix = inputInfo.Substring(0, 2); /*验证密码*/ if (prefix.Equals("pa")) //以pa开头才是有效的密码信息 { validate = new PassWordValidate(passWord, inputInfo); return(validate.Check()); } /*验证胸卡*/ else if (prefix.Equals("ca")) //以ca开头才是有效的胸卡信息 { validate = new CardValidate(card, inputInfo); return(validate.Check()); } else { return(false); } }
public async Task <CardValidate> CardToToken(CreditCard creditCard) { CardValidate ccValidate = new CardValidate(); try { var options = new TokenCreateOptions { Card = new TokenCardOptions { Number = creditCard.Numbers, ExpYear = Convert.ToInt64(creditCard.Year), ExpMonth = Convert.ToInt64(creditCard.Month), Cvc = creditCard.Cvc, //Currency = "usd" } }; var tokenService = new TokenService(); Token stripeToken = tokenService.CreateAsync(options).Result; ccValidate.ccConfirm = stripeToken.Id; } catch (Exception ex) { string stackTrace = Environment.StackTrace; StripeException stripeException = ex.InnerException as StripeException; if (stripeException != null) { ccValidate.ErrorMessages.Add(HandleStripeException(stripeException)); } } return(ccValidate); }
private void PayWithCC() { Pay.IsEnabled = false; CreditCard cc = new CreditCard() { Cvc = CVV.Text, HolderName = NameOnCard.Text, Numbers = CardNumber.Text, Month = ExpirationMonth.Text, Year = ExpirationYear.Text }; List <string> msgs = cc.VerifyCreditCardInfo(); if (msgs.Count == 0) { try { StripeServices stripe = new StripeServices(); CardValidate ccValidate = stripe.CardToToken(cc).Result; if (!String.IsNullOrEmpty(ccValidate.ccConfirm)) { cc.token = ccValidate.ccConfirm; string strMoneyValue = Total.Text; decimal decimalMoneyValue = decimal.Parse(strMoneyValue, NumberStyles.Currency); PaymentResponse response = MakeStripePayment(cc, decimalMoneyValue); if (response.success) { //what should we do if the card is successfully charged but the payment record isn't saved? bool paymentSaved = SavePaymentRecord(response.StripeChargeId).Result; if (paymentSaved) { PaymentSuccess(); } } else { //add message let them try again? Send email? DisplayAlert("Error", "Payment Unsuccessful", "OK"); Pay.IsEnabled = true; } } else { DisplayAlert("Error", ccValidate.ErrorMessages[0], "OK"); Pay.IsEnabled = true; } } catch (Exception ex) { //CANNOT save cc data to db Exception ex2 = new Exception("PayWithCC", ex); ((App)App.Current).LogError(ex2.Message, "Card holder name is " + NameOnCard.Text); } } else { string errorMsg = String.Empty; foreach (string msg in msgs) { errorMsg += msg + "\n"; } //ErrorMessages.Text = errorMsg; Pay.IsEnabled = true; } }
private void Pay_Clicked(object sender, EventArgs e) { Pay.IsEnabled = false; CreditCard cc = new CreditCard() { Cvc = CVV.Text, HolderName = NameOnCard.Text, Numbers = CardNumber.Text, Month = ExpirationMonth.Text, Year = ExpirationYear.Text }; List <string> msgs = cc.VerifyCreditCardInfo(); if (msgs.Count == 0) { StripeServices stripe = new StripeServices(); CardValidate ccValidate = stripe.CardToToken(cc).Result; if (!String.IsNullOrEmpty(ccValidate.ccConfirm)) { cc.token = ccValidate.ccConfirm; PaymentResponse response = MakeStripePayment(cc, workOrderPayment.WorkOrderPaymentAmount); if (response.success) { //what should we do if the card is successfully charged but the payment record isn't saved? bool paymentSaved = SavePaymentRecord(response.StripeChargeId).Result; if (paymentSaved) { //DisplayAlert("Success", "Payment Successful", "OK").Wait(); //navigate back to WorkOrder and clear all fields PopUntilDestination(typeof(WorkOrderPage)); //Navigation.RemovePage(this); //CCPaymentPage //Task<Page> p = Navigation.PopModalAsync(); //PaymentPage //if (p.Result is ContentPage) //{ // ContentPage cp = p.Result as ContentPage; // if (cp != null) // { // if (cp is WorkOrderPage) // { // //clear fields // ((WorkOrderPage)cp).OnClear(this, null); // } // } //} } } else { //add message let them try again? DisplayAlert("Error", "Payment Unsuccessful", "OK"); Pay.IsEnabled = true; } } else { DisplayAlert("Error", ccValidate.ErrorMessages[0], "OK"); Pay.IsEnabled = true; } } else { string errorMsg = String.Empty; foreach (string msg in msgs) { errorMsg += msg + "\n"; } //ErrorMessages.Text = errorMsg; Pay.IsEnabled = true; } }