public void SetCard(string customerId, string number, int month, int year, string cvc) { Stripe.TokenService tokenService = new Stripe.TokenService(); var options = new Stripe.TokenCreateOptions() { Card = new CreditCardOptions() { Number = number, ExpMonth = month, ExpYear = year, Cvc = cvc } }; Stripe.Token token = tokenService.Create(options); var customerOptions = new CustomerUpdateOptions() { SourceToken = token.Id }; var customerService = new CustomerService(); Stripe.Customer customer = customerService.Update(customerId, customerOptions); }
public CreditCardProcess(string cardNumber, string cardExpMonth, string cardExpYear, string cardCVC) { InitializeComponent(); StripeConfiguration.SetApiKey("pk_live_HTl5JEEmjEbq772AbJ3N6Ahl"); var tokenOptions = new Stripe.TokenCreateOptions() { Card = new Stripe.CreditCardOptions() { Number = cardNumber, ExpYear = long.Parse(cardExpYear), ExpMonth = long.Parse(cardExpMonth), Cvc = cardCVC } }; var tokenService = new Stripe.TokenService(); Stripe.Token stripeToken = tokenService.Create(tokenOptions); var customerOptions = new CustomerCreateOptions(); var customerService = new CustomerService(); customerOptions.SourceToken = stripeToken.Id; customerOptions.Email = App.newUser.eMailAddress; Customer newCustomer = customerService.Create(customerOptions); Console.WriteLine(newCustomer.Id); //Console.WriteLine("Token is"+stripeToken.Id); }
public string Post([FromBody] PaymentModel payment) { StripeConfiguration.ApiKey = ("pk_test_DaPhATJ0sS0GJYJnXbgubW6C00oJqhvxio"); var tokenOptions = new Stripe.TokenCreateOptions() { Card = new Stripe.CreditCardOptions() { Number = payment.CreditCard.CreditCardNumber, ExpYear = payment.CreditCard.ExpYear, ExpMonth = payment.CreditCard.ExpMonth, Cvc = payment.CreditCard.CVV } }; var tokenService = new Stripe.TokenService(); Stripe.Token stripeToken; try { stripeToken = tokenService.Create(tokenOptions); } catch (StripeException ex) { StripeError stripeError = ex.StripeError; return(stripeError.Message); } string token = stripeToken.Id; // This is the token // You can optionally create a customer first, and attached this to the CustomerId StripeConfiguration.ApiKey = ("sk_test_02wLfkfPFikWAuf5q8QwhcEb00RHbAsnJc"); var charge = new Stripe.ChargeCreateOptions { Amount = Convert.ToInt32(payment.CreditCard.amount * 100), // Ocekuje request u najmanjoj jedinici pa *100 da se pretvori Currency = "EUR", // or the currency you are dealing with Description = "Informacijski sistem za nogometni stadion", Source = token }; var service = new ChargeService(); try { var response = service.Create(charge); // Record or do something with the charge information } catch (StripeException ex) { StripeError stripeError = ex.StripeError; // Handle error return(stripeError.Message); } // Ideally you would put in additional information, but you can just return true or false for the moment0 StripeError stripeError1 = new StripeError() { Message = "UspjeĆĄna uplata" }; return(stripeError1.Message); }
private Token CreateToken(CreditCardOptions card) { //Assign Card to Token Object and create Token Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions(); token.Card = card; Stripe.TokenService serviceToken = new Stripe.TokenService(); Stripe.Token newToken = serviceToken.Create(token); return(newToken); }
public async Task <OrderModel> PayAsync(PaymentModel model) { StripeConfiguration.ApiKey = _key; var card = new CreditCardOptions { Number = model.CardNumber, ExpMonth = model.Month, ExpYear = model.Year, Cvc = model.CVC }; var optionsToken = new TokenCreateOptions { Card = card }; var serviceToken = new Stripe.TokenService(); var stripeToken = await serviceToken.CreateAsync(optionsToken); var options = new ChargeCreateOptions { Amount = model.Value * Constants.Numbers.CONVERT_TO_PRICE, Currency = CurrencyType.USD.ToString(), Description = model.Description, Source = stripeToken.Id }; var service = new ChargeService(); var charge = await service.CreateAsync(options); var payment = await _orderRepository.GetPaymentByOrderIdAsync(model.OrderId); payment.TransactionId = charge.Id; await _paymentRepository.UpdateAsync(payment); var order = await _orderRepository.GetOrderByIdAsync(model.OrderId); order.Description = model.Description; order.Status = StatusType.Paid; await _orderRepository.UpdateAsync(order); if (!charge.Paid) { throw new ServerException(Constants.Success.UNPAID_ORDER); } var orderModel = _mapper.Map <OrderModel>(order); return(orderModel); }
public static stripe.Charge CreateCharge(this ProcessPaymentRequest processPaymentRequest, StripePaymentSettings stripePaymentSettings, CurrencySettings currencySettings, Store store, ICustomerService customerService, ICurrencyService currencyService, IGenericAttributeService genericAttributeService) { int substep = 0; try { var customer = customerService.GetCustomerById(processPaymentRequest.CustomerId); if (customer == null) { throw new NopException("Customer cannot be loaded"); } substep = 1; var currency = currencyService.GetCurrencyById(currencySettings.PrimaryStoreCurrencyId); if (currency == null) { throw new NopException("Primary store currency cannot be loaded"); } substep = 2; if (!Enum.TryParse(currency.CurrencyCode, out StripeCurrency stripeCurrency)) { throw new NopException($"The {currency.CurrencyCode} currency is not supported by Stripe"); } substep = 3; var stripeCustomerService = new stripe.CustomerService(stripePaymentSettings.GetStripeClient()); var chargeService = new stripe.ChargeService(stripePaymentSettings.GetStripeClient()); var tokenService = new stripe.TokenService(stripePaymentSettings.GetStripeClient()); substep = 4; var stripeCustomer = stripeCustomerService.GetOrCreateCustomer(customer, genericAttributeService, stripePaymentSettings); substep = 5; var tokenOptions = processPaymentRequest.CreateTokenOptions(customer, stripeCurrency); substep = 6; var token = tokenService.Create(tokenOptions); substep = 7; var chargeOptions = processPaymentRequest.CreateChargeOptions(store, token, stripePaymentSettings.TransactionMode, stripeCurrency); substep = 8; var charge = chargeService.Create(chargeOptions); substep = 9; return(charge); } catch (Exception ex) { throw new Exception($"Failed at substep {substep}", ex); } }
private Token Token() { var options = new TokenCreateOptions { Card = new TokenCardOptions { Name = "Nahed Kadih", Number = "4242424242424242", ExpMonth = 1, ExpYear = 2021, Cvc = "234" } }; var service = new Stripe.TokenService(); return(service.Create(options)); }
public static stripe.Charge CreateCharge(this ProcessPaymentRequest processPaymentRequest, StripePaymentSettings stripePaymentSettings, CurrencySettings currencySettings, Store store, ICustomerService customerService, IStateProvinceService stateProvinceService, ICountryService countryService, ICurrencyService currencyService, IGenericAttributeService genericAttributeService) { var customer = customerService.GetCustomerById(processPaymentRequest.CustomerId); if (customer == null) { throw new NopException("Customer cannot be loaded"); } var currency = currencyService.GetCurrencyById(currencySettings.PrimaryStoreCurrencyId); if (currency == null) { throw new NopException("Primary store currency cannot be loaded"); } if (!Enum.TryParse(currency.CurrencyCode, out StripeCurrency stripeCurrency)) { throw new NopException($"The {currency.CurrencyCode} currency is not supported by Stripe"); } var stripeCustomerService = new stripe.CustomerService(stripePaymentSettings.GetStripeClient()); var chargeService = new stripe.ChargeService(stripePaymentSettings.GetStripeClient()); var tokenService = new stripe.TokenService(stripePaymentSettings.GetStripeClient()); var stripeCustomer = stripeCustomerService.GetOrCreateCustomer(customer, genericAttributeService, stripePaymentSettings); var tokenOptions = processPaymentRequest.CreateTokenOptions(customerService, stateProvinceService, countryService, stripeCurrency); var token = tokenService.Create(tokenOptions); var chargeOptions = processPaymentRequest.CreateChargeOptions(store, token, stripePaymentSettings.TransactionMode, stripeCurrency); var charge = chargeService.Create(chargeOptions); return(charge); }
public async Task <dynamic> PayAsync(string cardNumber, int month, int year, string cvc, long value) { try { var optionsToken = new TokenCreateOptions { Card = new TokenCardOptions { Number = cardNumber, ExpMonth = month, ExpYear = year, Cvc = cvc } }; var serviceToken = new Stripe.TokenService(); Token stripeToken = await serviceToken.CreateAsync(optionsToken); var option = new ChargeCreateOptions { Amount = value, Currency = "eur", Description = "droga", Source = stripeToken.Id }; var service = new ChargeService(); Charge charge = await service.CreateAsync(option); if (charge.Paid) { return("Success"); } else { return("Failed"); } } catch (Exception e) { return(e.Message); } }
private async Task <Charge> MakePayment2(PaymentInputModel payModel) { try { StripeConfiguration.ApiKey = this.SecretKey;; // "pk_test_51HiQuVAFZv6rpRFk3K1JeutsplKLBU7nFnti3wi6xZ6YW7sHUPJl433JQF4K9kSO0VsxX3edkIgrJrrbdzFPSGdt00a6LlFJ7W"; var optionsToken = new TokenCreateOptions { Card = new TokenCardOptions { Number = payModel.cardNumber, ExpMonth = payModel.month, ExpYear = payModel.year, Cvc = payModel.cvc }, }; var serviceToken = new Stripe.TokenService(); Token stripeToken = await serviceToken.CreateAsync(optionsToken); var options = new ChargeCreateOptions { Amount = GetFormattedAmount((long)payModel.value), Currency = "USD", Description = $"Payment taken by Moo-In at {payModel.RestaurantName}", Source = stripeToken.Id, Metadata = new Dictionary <string, string> { { "OrderId", payModel.Order.rec_id.ToString() }, }, ApplicationFeeAmount = GetShareAmount(payModel.value) }; var service = new ChargeService(); Charge charge = await service.CreateAsync(options, new RequestOptions { StripeAccount = payModel.StripeAccountId }); return(charge); } catch (Exception e) { throw; } }
public void ProcessNewCard() { StripeConfiguration.SetApiKey("pk_live_HTl5JEEmjEbq772AbJ3N6Ahl"); WebClient newClient = new WebClient(); var tokenOptions = new Stripe.TokenCreateOptions() { Card = new Stripe.CreditCardOptions() { Number = ccNumber.Text, ExpYear = long.Parse(years[expYear.SelectedIndex]), ExpMonth = long.Parse(months[expMonth.SelectedIndex]), Cvc = cvcLabel.Text } }; var tokenService = new Stripe.TokenService(); try { Stripe.Token stripeToken = tokenService.Create(tokenOptions); var sendingParameters = new System.Collections.Specialized.NameValueCollection(); sendingParameters.Set("newToken", stripeToken.Id); sendingParameters.Set("userID", App.currentUser.systemID); sendingParameters.Set("newLastFour", ccNumber.Text.Substring(12)); sendingParameters.Set("newExpiryDate", months[expMonth.SelectedIndex] + "/" + years[expYear.SelectedIndex]); newClient.UploadValues("http://www.cvx4u.com/web_service/updateCreditCard.php", sendingParameters); App.currentUser.ccLastFour = ccNumber.Text.Substring(12); App.currentUser.ccExpiryDate = months[expMonth.SelectedIndex] + "/" + years[expYear.SelectedIndex]; } catch (StripeException stripeExcept) { Console.WriteLine("errros is " + stripeExcept.StripeError.Message + " " + stripeExcept.StripeError.Code + " " + stripeExcept.StripeError.ErrorDescription); } }
public ActionResult Charge(StripeChargeModel model) { // 4242424242424242 string errormessage = ""; bool isvalidemail = false; bool isvalidamount = false; HttpResponseMessage responseMessage = new HttpResponseMessage(); try { var addr = new System.Net.Mail.MailAddress(model.Email); bool emailvalid = (addr.Address == model.Email); isvalidemail = true; } catch { errormessage += "invalid email\r\n"; isvalidemail = false; } if (model.Amount == 0) { isvalidamount = false; errormessage += "invalid amount\r\n"; } else { isvalidamount = true; } if (isvalidamount == true && isvalidemail == true) { try { string Name = model.CardHolderName; string CardNumber = model.CardNum; long ExpirationYear = long.Parse(model.Expyear); long ExpirationMonth = long.Parse(model.ExpMonth); string CVV2 = model.CVV; string Buyer_Email = model.Email; int amount = (int)model.Amount; Stripe.StripeConfiguration.SetApiKey("sk_test_KVelkjylnQQPOkrHSSu8gCft00dODAP1ie"); Stripe.CreditCardOptions card = new Stripe.CreditCardOptions(); card.Name = Name; card.Number = CardNumber; card.ExpYear = ExpirationYear; card.ExpMonth = ExpirationMonth; card.AddressLine1 = model.AddressLine1; card.AddressLine2 = model.AddressLine2; card.AddressState = model.AddressCity; card.AddressCountry = model.AddressCountry; card.AddressZip = model.AddressPostcode; card.Cvc = CVV2; // set card to token object and create token Stripe.TokenCreateOptions tokenCreateOption = new Stripe.TokenCreateOptions(); tokenCreateOption.Card = card; Stripe.TokenService tokenService = new Stripe.TokenService(); Stripe.Token token = tokenService.Create(tokenCreateOption); //create customer object then register customer on Stripe Stripe.CustomerCreateOptions customer = new Stripe.CustomerCreateOptions(); customer.Email = Buyer_Email; var custService = new Stripe.CustomerService(); Stripe.Customer stpCustomer = custService.Create(customer); //create credit card charge object with details of charge var options = new Stripe.ChargeCreateOptions { Amount = (int)(amount * 100), // Amount = (int)(model.Amount * 100), // Currency = "gbp", // Description = "Description for test charge", // Source = model.Token Currency = "gbp", ReceiptEmail = Buyer_Email, Source = model.Token, Description = "Description for test charge" }; //and Create Method of this object is doing the payment execution. var service = new Stripe.ChargeService(); Stripe.Charge charge = service.Create(options); // This will do the Payment } return(new HttpStatusCodeResult(HttpStatusCode.OK, "Success")); } catch { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "error : " + errormessage)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "error : " + errormessage)); } }
public ViewResult makePayment(PaymentInformation cardInfo) { try { Stripe.StripeConfiguration.SetApiKey("sk_test_51HqI05B1UsJ4lZg1agboQSE7i0fWn98619xc2FP5NhREH4igqo1AlKTQO8VWMfsQBUs1OlXNBzBkOqORRQP6ZlPf00E2l0QVhL"); Stripe.CreditCardOptions card = new Stripe.CreditCardOptions(); card.Name = cardInfo.CardOwnerFirstName + " " + cardInfo.CardOwnerLastName; card.Number = cardInfo.CardNumber; card.ExpYear = cardInfo.ExpirationYear; card.ExpMonth = cardInfo.ExpirationMonth; card.Cvc = cardInfo.CVV2; Console.WriteLine(TotalPrice.ToString()); Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions(); token.Card = card; Stripe.TokenService serviceToken = new Stripe.TokenService(); Stripe.Token newToken = serviceToken.Create(token); Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions(); myCustomer.Email = cardInfo.Buyer_Email; myCustomer.SourceToken = newToken.Id; var customerService = new Stripe.CustomerService(); Stripe.Customer stripeCustomer = customerService.Create(myCustomer); var t = TempData["totalCost"]; int t1 = (int)Math.Round(Convert.ToDouble(t)) - 1; string total; string input_decimal_number = t.ToString(); var regex = new System.Text.RegularExpressions.Regex("(?<=[\\.])[0-9]+"); if (regex.IsMatch(input_decimal_number)) { string decimal_places = regex.Match(input_decimal_number).Value; total = t1.ToString() + decimal_places; } else { total = t1 + "00"; } System.Diagnostics.Trace.WriteLine(t1.ToString()); var options = new Stripe.ChargeCreateOptions { Amount = Convert.ToInt32(total), Currency = "USD", ReceiptEmail = cardInfo.Buyer_Email, CustomerId = stripeCustomer.Id, }; var service = new Stripe.ChargeService(); Stripe.Charge charge = service.Create(options); return(View("Thanks")); } catch (StripeException e) { switch (e.StripeError.ErrorType) { case "card_error": error = (" Error Message: " + e.StripeError.Message); break; case "api_connection_error": break; case "api_error": break; case "authentication_error": break; case "invalid_request_error": break; case "rate_limit_error": break; case "validation_error": break; default: // Unknown Error Type break; } ViewBag.Greeting = error; return(View("Error")); } }
private async void Button_Clicked(object sender, EventArgs e) { try { StripeConfiguration.SetApiKey("sk_test_51H7Lu7KJ3FKVwUnlPU8EUYuDPU0UMWNajFeHpVYzqwLkpKFRk9480iV54ZvAIPy4J0xYlKoN9IQaGMoyhhcaxOgl003Kz8FIdL"); //This are the sample test data use MVVM bindings to send data to the ViewModel Stripe.CreditCardOptions stripcard = new Stripe.CreditCardOptions(); stripcard.Number = cardNumberEntry.Text; stripcard.ExpYear = Convert.ToInt32(expiryDate.Text.Split('/')[1]); stripcard.ExpMonth = Convert.ToInt32(expiryDate.Text.Split('/')[0]); stripcard.Cvc = cvvEntry.Text; //Step 1 : Assign Card to Token Object and create Token Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions(); token.Card = stripcard; Stripe.TokenService serviceToken = new Stripe.TokenService(); Stripe.Token newToken = serviceToken.Create(token); // Step 2 : Assign Token to the Source var options = new SourceCreateOptions { Type = SourceType.Card, Currency = "usd", Token = newToken.Id }; var service = new SourceService(); Source source = service.Create(options); //Step 3 : Now generate the customer who is doing the payment Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions() { Name = nameEntry.Text, Email = emailEntry.Text, Description = "Amare Payment", }; var customerService = new Stripe.CustomerService(); Stripe.Customer stripeCustomer = customerService.Create(myCustomer); mycustomer = stripeCustomer.Id; // Not needed //Step 4 : Now Create Charge Options for the customer. var chargeoptions = new Stripe.ChargeCreateOptions { Amount = 100, Currency = "USD", ReceiptEmail = emailEntry.Text, Customer = stripeCustomer.Id, Source = source.Id }; //Step 5 : Perform the payment by Charging the customer with the payment. var service1 = new Stripe.ChargeService(); Stripe.Charge charge = service1.Create(chargeoptions); // This will do the Payment getchargedID = charge.Id; // Not needed await DisplayAlert("Payment", "Payment Success", "Okay"); await Navigation.PopAsync(); } catch (Stripe.StripeException ex) { await DisplayAlert("Payment Error", ex.Message, "Okay"); } }
public void ProcessNewUser(object sender, EventArgs e) { bool moveOn = true; if (App.newUser.isSupporter == true) { if (ccNumber.Text.Length != 16) { ccNumLabel.TextColor = Color.Red; moveOn = false; } if (expiryMonth.SelectedIndex == -1) { expMonthLabel.TextColor = Color.Red; moveOn = false; } if (expiryYear.SelectedIndex == -1) { expYearLabel.TextColor = Color.Red; moveOn = false; } if (cvcEntry.Text.Length != 3) { cvcLabel.TextColor = Color.Red; moveOn = false; } } else { if (verificationURL.Text == "") { verficationLabel.TextColor = Color.Red; moveOn = false; } } if (moveOn == true) { noticeFrame.IsVisible = true; noticeButton.IsVisible = false; noticeText.Text = "Sending..."; var sendingParameters = new System.Collections.Specialized.NameValueCollection { { "firstName", App.newUser.firstName }, { "lastName", App.newUser.lastName }, { "eMail", eMailField.Text }, { "isSupporter", App.newUser.isSupporter.ToString().ToLower() }, { "contactPerson", App.newUser.contactPerson }, { "phone", App.newUser.phone }, { "website", App.newUser.website }, { "party", App.newUser.party }, { "mailingAddress", App.newUser.streetAddress }, { "city", App.newUser.city }, { "state", App.newUser.state }, { "zipCode", App.newUser.zipCode }, { "office", App.newUser.office }, { "officeDistrict", App.newUser.officeDistrict }, { "officeState", App.newUser.officeState }, { "officeCity", App.newUser.officeCity }, { "officeCounty", App.newUser.officeCounty }, { "issues", App.newUser.issues }, { "ideology", App.newUser.ideology }, { "verificationLink", verificationURL.Text }, { "jobTitle", App.newUser.jobTitle }, { "employerName", App.newUser.employerName }, { "employerCity", App.newUser.employerCity }, { "employerState", App.newUser.employerState }, { "payoutAddress", App.newUser.payoutAddress }, { "payoutEMail", App.newUser.payoutEMail }, { "payoutOther", App.newUser.payoutOther } }; if (App.newUser.isSupporter == true) { var tokenOptions = new Stripe.TokenCreateOptions() { Card = new Stripe.CreditCardOptions() { Number = ccNumber.Text, ExpYear = long.Parse(ccExpiryYears[expiryYear.SelectedIndex]), ExpMonth = long.Parse(ccExpiryMonths[expiryMonth.SelectedIndex]), Cvc = cvcEntry.Text } }; var tokenService = new Stripe.TokenService(); try { Stripe.Token stripeToken = tokenService.Create(tokenOptions); Console.WriteLine(stripeToken.StripeResponse); sendingParameters.Set("stripeToken", stripeToken.Id); sendingParameters.Set("lastFour", ccNumber.Text.Substring(12, 4)); sendingParameters.Set("ccExpiry", ccExpiryMonths[expiryMonth.SelectedIndex] + "/" + ccExpiryYears[expiryYear.SelectedIndex]); } catch (StripeException stripeExcept) { Console.WriteLine("errros is " + stripeExcept.StripeError.Message + " " + stripeExcept.StripeError.Code + " " + stripeExcept.StripeError.ErrorDescription); noticeText.Text = ccWarning; noticeButton.IsVisible = true; moveOn = false; //errorWindow.IsVisible = true; } } Console.WriteLine("district in is " + App.newUser.officeDistrict); //Console.WriteLine("send county is"+App.newUser.officeCounty); DependencyService.Get <IFirebaseAuthenticator>().CreateNewUser(eMailField.Text, passwordField.Text, sendingParameters); } }
public PaymentView(DateTime bookingDate, string centerName, string sportName, string courtName, string startingBookingTime, string endingBookingTime, double TotalPaymentAmount) { InitializeComponent(); //startingBookingTime AND endingBookingTime are TimeSpan not DateTime ...... Done var uname = Preferences.Get("UserName", String.Empty); if (String.IsNullOrEmpty(uname)) { username.Text = "Guest"; } else { username.Text = uname; } centername.Text = centerName; courtname.Text = courtName; //bookingdate.Text = bookingDate.Date.ToString(); cvm = new PaymentViewModel(bookingDate); this.BindingContext = cvm; bookingtime.Text = startingBookingTime.ToString() + " - " + endingBookingTime.ToString(); double RoundedTotalPaymentAmount = Math.Round(TotalPaymentAmount, 1, MidpointRounding.ToEven); totalpaymentamount.Text = "RM " + RoundedTotalPaymentAmount.ToString(); string totalp = totalpaymentamount.Text; DateTime s = Convert.ToDateTime(startingBookingTime); DateTime d = Convert.ToDateTime(endingBookingTime); NewEventHandler.Clicked += async(sender, args) => { // if check payment from Moustafa is true, then add booking to firebase try { //StripeConfiguration.SetApiKey("sk_test_51IpayhGP2IgUXM55te5JbGRu14MOp6AU6GORVFhqpOilEOp96ERDzKCi1VN9rDLrOmOEwNPqgOvQuIyaNg8YKfkL00Qoq8a7QX"); StripeConfiguration.SetApiKey("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"); //This are the sample test data use MVVM bindings to send data to the ViewModel Stripe.TokenCardOptions stripcard = new Stripe.TokenCardOptions(); stripcard.Number = cardnumber.Text; stripcard.ExpYear = Int64.Parse(expiryYear.Text); stripcard.ExpMonth = Int64.Parse(expirymonth.Text); stripcard.Cvc = cvv.Text; //stripcard.Cvc = Int64.Parse(cvv.Text); //Step 1 : Assign Card to Token Object and create Token Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions(); token.Card = stripcard; Stripe.TokenService serviceToken = new Stripe.TokenService(); Stripe.Token newToken = serviceToken.Create(token); // Step 2 : Assign Token to the Source var options = new SourceCreateOptions { Type = SourceType.Card, Currency = "myr", Token = newToken.Id }; var service = new SourceService(); Source source = service.Create(options); //Step 3 : Now generate the customer who is doing the payment Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions() { Name = "Moustafa", Email = "*****@*****.**", Description = "Customer for [email protected]", }; var customerService = new Stripe.CustomerService(); Stripe.Customer stripeCustomer = customerService.Create(myCustomer); mycustomer = stripeCustomer.Id; // Not needed //Step 4 : Now Create Charge Options for the customer. var chargeoptions = new Stripe.ChargeCreateOptions { //Amount = (Int64.Parse(RoundedTotalPaymentAmount)) * 100, //(int(RoundedTotalPaymentAmount)) //Amount = Convert.ToInt32(RoundedTotalPaymentAmount) * 100, //Amount = (long?)(double.Parse(RoundedTotalPaymentAmount) * 100), Amount = (long?)(double.Parse(totalp) * 100), Currency = "MYR", ReceiptEmail = "*****@*****.**", Customer = stripeCustomer.Id, Source = source.Id }; //Step 5 : Perform the payment by Charging the customer with the payment. var service1 = new Stripe.ChargeService(); Stripe.Charge charge = service1.Create(chargeoptions); // This will do the Payment getchargedID = charge.Id; // Not needed } catch (Exception ex) { UserDialogs.Instance.Alert(ex.Message, null, "ok"); Console.Write("error" + ex.Message); //await Application.Current.MainPage.DisplayAlert("error ", ex.Message, "OK"); } finally { //if (getchargedID != null) if (getchargedID != null) { var acd = new AddBookingData(sportName, courtName, username.Text, centerName, s, d, bookingDate, RoundedTotalPaymentAmount); await acd.AddBookingDataAsync(); UserDialogs.Instance.Alert("Payment Successed", "Success", "Ok"); Xamarin.Forms.Application.Current.MainPage = new MainTabbedView(); //await Application.Current.MainPage.DisplayAlert("Payment Successed ", "Success", "OK"); } else { UserDialogs.Instance.Alert("Something Wrong", "Faild", "OK"); //await Application.Current.MainPage.DisplayAlert("Payment Error ", "faild", "OK"); } } /* * var acd = new AddBookingData(sportName, courtName, username.Text, centerName, s, d, bookingDate, RoundedTotalPaymentAmount); * await acd.AddBookingDataAsync(); * /* * * * //Application.Current.MainPage = new MainTabbedView(); * * //await Navigation.PopModalAsync(); * //await Navigation.PopToRootAsync(); * /* * Navigation.InsertPageBefore(new NewPage(), Navigation.NavigationStack[0]); * await Navigation.PopToRootAsync(); */ }; /* * public void GetCustomerInformationID(object sender, EventArgs e) * { * var service = new CustomerService(); * var customer = service.Get(mycustomer); * var serializedCustomer = JsonConvert.SerializeObject(customer); * // var UserDetails = JsonConvert.DeserializeObject<CustomerRetriveModel>(serializedCustomer); * * } * * * public void GetAllCustomerInformation(object sender, EventArgs e) * { * var service = new CustomerService(); * var options = new CustomerListOptions * { * Limit = 3, * }; * var customers = service.List(options); * var serializedCustomer = JsonConvert.SerializeObject(customers); * } * * * public void GetRefundForSpecificTransaction(object sender, EventArgs e) * { * var refundService = new RefundService(); * var refundOptions = new RefundCreateOptions * { * Charge = getchargedID, * }; * Refund refund = refundService.Create(refundOptions); * refundID = refund.Id; * } * * * public void GetRefundInformation(object sender, EventArgs e) * { * var service = new RefundService(); * var refund = service.Get(refundID); * var serializedCustomer = JsonConvert.SerializeObject(refund); * * } */ /* * * async Task NewEventHandler(object sender, EventArgs e) * { * // if check payment from Moustafa is true, then * * // add booking to firebase * * var acd = new AddBookingData(sportName, courtName, username.Text, centerName, s, d, bookingDate, TotalPaymentAmount); * await acd.AddBookingDataAsync(); * } */ }
public async Task <IActionResult> ProcessingAsync() { PayModel paymodel = getPayModel(); var tokenoptions = new TokenCreateOptions { Card = new TokenCardOptions { AddressLine1 = paymodel.AddressLine1, AddressLine2 = paymodel.AddressLine2, AddressCity = paymodel.AddressCity, AddressState = paymodel.AddressState, AddressZip = paymodel.AddressZip, Name = paymodel.Name, Number = paymodel.CardNumder, ExpMonth = paymodel.ExpMonth, ExpYear = paymodel.ExpYear, Cvc = paymodel.CVC }, }; var serviceToken = new Stripe.TokenService(); Token stripeToken = await serviceToken.CreateAsync(tokenoptions); paymodel.OrderName = "OrderName"; paymodel.OrderDescription = "OrderDescription"; paymodel.StripeToken = stripeToken.Id; var Metadata = new Dictionary <string, string> { { "Name", paymodel.OrderName }, { "Price", paymodel.Amount.ToString() }, { "Description", paymodel.OrderDescription } }; var chargeOptions = new ChargeCreateOptions { Amount = paymodel.Amount, Currency = "USD", Description = $"Buying {paymodel.OrderName} {paymodel.OrderDescription}", Source = new AnyOf <string, CardCreateNestedOptions>(paymodel.StripeToken), ReceiptEmail = paymodel.Email, Metadata = Metadata }; var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeOptions); //foreach (var product in model.Products) //{ // ProductModel correctProduct = await _productsService.RetrieveAsync(product.Id); // if (correctProduct != product) // { // throw new CustomServerException("invalid order data"); // } // product.Id = default(int); // await CreateOrderAsync(product); // var transaction = new TransactionModel { Currency = charge.Currency, Amount = charge.Amount, Status = charge.Status, Created = charge.Created, Description = charge.Description, Object = charge.Object, SourceId = charge.Source.Id }; // await _transactionsService.CreateAsync(transaction); //} var response = await Task.FromResult(charge); return(Ok(response)); }
public ViewResult makePayment(PaymentInformation cardInfo) { try { Stripe.StripeConfiguration.SetApiKey("sk_test_51HqI05B1UsJ4lZg1agboQSE7i0fWn98619xc2FP5NhREH4igqo1AlKTQO8VWMfsQBUs1OlXNBzBkOqORRQP6ZlPf00E2l0QVhL"); //Create Card Object to create Token Stripe.CreditCardOptions card = new Stripe.CreditCardOptions(); card.Name = cardInfo.CardOwnerFirstName + " " + cardInfo.CardOwnerLastName; card.Number = cardInfo.CardNumber; card.ExpYear = cardInfo.ExpirationYear; card.ExpMonth = cardInfo.ExpirationMonth; card.Cvc = cardInfo.CVV2; //Assign Card to Token Object and create Token Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions(); token.Card = card; Stripe.TokenService serviceToken = new Stripe.TokenService(); Stripe.Token newToken = serviceToken.Create(token); Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions(); myCustomer.Email = cardInfo.Buyer_Email; myCustomer.SourceToken = newToken.Id; var customerService = new Stripe.CustomerService(); Stripe.Customer stripeCustomer = customerService.Create(myCustomer); //Create Charge Object with details of Charge var options = new Stripe.ChargeCreateOptions { Amount = Convert.ToInt32(cardInfo.Amount), Currency = "USD", ReceiptEmail = cardInfo.Buyer_Email, CustomerId = stripeCustomer.Id, }; //and Create Method of this object is doing the payment execution. var service = new Stripe.ChargeService(); Stripe.Charge charge = service.Create(options); // This will do the Payment return(View("Thanks")); } catch (StripeException e) { switch (e.StripeError.ErrorType) { case "card_error": //error = ("Code: " + e.StripeError.Code + "; "); error = (" Error Message: " + e.StripeError.Message); break; case "api_connection_error": break; case "api_error": break; case "authentication_error": break; case "invalid_request_error": break; case "rate_limit_error": break; case "validation_error": break; default: // Unknown Error Type break; } ViewBag.Greeting = error; return(View("Error")); } }
private async Task <string> CreateStripeClient(string email, string name, string cardNumber, int month, int year, string cvv) { var optionstoken = new TokenCreateOptions { Card = new TokenCardOptions { Number = cardNumber, ExpMonth = month, ExpYear = year, Cvc = cvv } }; var servicetoken = new Stripe.TokenService(); Token stripetoken = await servicetoken.CreateAsync(optionstoken); var customer = new CustomerCreateOptions { Email = email, Name = name, Source = stripetoken.Id, }; Console.WriteLine(" stripetoken attributes :" + stripetoken); var services = new CustomerService(); var created = services.Create(customer); var option = new PaymentMethodCreateOptions { Type = "card", Card = new PaymentMethodCardOptions { Number = cardNumber, ExpMonth = month, ExpYear = year, Cvc = cvv, }, }; var service = new PaymentMethodService(); var result = service.Create(option); Console.WriteLine(" PaymentMethodService attributes :" + result); var options = new PaymentMethodAttachOptions { Customer = created.Id, }; var method = new PaymentMethodService(); method.Attach( result.Id, options ); if (created.Id == null) { return("Failed"); } else { return(created.Id); } }