public Token CreateCardToken(Payment paymentInfo) { Stripe.CreditCardOptions card = new Stripe.CreditCardOptions(); card.Name = paymentInfo.CardOwnerFirstName + " " + paymentInfo.CardOwnerLastName; card.Number = paymentInfo.CardNumber; card.ExpYear = paymentInfo.ExpirationYear; card.ExpMonth = paymentInfo.ExpirationMonth; card.Cvc = paymentInfo.CVV2; CreateToken(card); return(CreateToken(card)); }
public static stripe.CreditCardOptions CreateCreditCardOptions(this ProcessPaymentRequest processPaymentRequest, ICustomerService customerService, IStateProvinceService stateProvinceService, ICountryService countryService, StripeCurrency stripeCurrency) { var creditCardOptions = new stripe.CreditCardOptions() { Cvc = processPaymentRequest.CreditCardCvv2, Currency = stripeCurrency.ToString(), ExpMonth = processPaymentRequest.CreditCardExpireMonth, ExpYear = processPaymentRequest.CreditCardExpireYear, Name = processPaymentRequest.CreditCardName, Number = processPaymentRequest.CreditCardNumber, }; var customer = customerService.GetCustomerById(processPaymentRequest.CustomerId); var customerBillingAddress = customerService.GetCustomerBillingAddress(customer); var billingStateProvince = customerBillingAddress.StateProvinceId.HasValue ? stateProvinceService.GetStateProvinceById(customerBillingAddress.StateProvinceId.Value) : null; var billingCountry = customerBillingAddress != null && customerBillingAddress.CountryId.HasValue ? countryService.GetCountryById(customerBillingAddress.CountryId.Value) : null; if (customer != null && customerBillingAddress != null) { creditCardOptions.AddressCity = customerBillingAddress.City; creditCardOptions.AddressCountry = billingCountry?.Name; creditCardOptions.AddressLine1 = customerBillingAddress.Address1; creditCardOptions.AddressLine2 = customerBillingAddress.Address2; creditCardOptions.AddressState = billingStateProvince?.Name; creditCardOptions.AddressZip = customerBillingAddress.ZipPostalCode; } return(creditCardOptions); }
public static stripe.CreditCardOptions CreateCreditCardOptions(this ProcessPaymentRequest processPaymentRequest, Core.Domain.Customers.Customer customer, StripeCurrency stripeCurrency) { var creditCardOptions = new stripe.CreditCardOptions() { Cvc = processPaymentRequest.CreditCardCvv2, Currency = stripeCurrency.ToString(), ExpMonth = processPaymentRequest.CreditCardExpireMonth, ExpYear = processPaymentRequest.CreditCardExpireYear, Name = processPaymentRequest.CreditCardName, Number = processPaymentRequest.CreditCardNumber, }; if (customer.BillingAddress != null) { creditCardOptions.AddressCity = customer.BillingAddress.City; creditCardOptions.AddressCountry = customer.BillingAddress.Country?.Name; creditCardOptions.AddressLine1 = customer.BillingAddress.Address1; creditCardOptions.AddressLine2 = customer.BillingAddress.Address2; creditCardOptions.AddressState = customer.BillingAddress.StateProvince?.Name; creditCardOptions.AddressZip = customer.BillingAddress.ZipPostalCode; } return(creditCardOptions); }
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")); } }
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"); } }