public virtual async Task <StripeCustomer> CreateAsync(StripeCustomerCreateOptions createOptions, StripeRequestOptions requestOptions = null) { return(Mapper <StripeCustomer> .MapFromJson( await Requestor.PostStringAsync(this.ApplyAllParameters(createOptions, Urls.Customers, false), SetupRequestOptions(requestOptions)) )); }
//Sync public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions, StripeRequestOptions requestOptions = null) { return Mapper<StripeCustomer>.MapFromJson( Requestor.PostString(this.ApplyAllParameters(createOptions, Urls.Customers, false), SetupRequestOptions(requestOptions)) ); }
public bool SaveCustomerByToken(string email, string stripeToken) { try { var customer = new StripeCustomerCreateOptions(); customer.Email = email; //customer.Description = "Johnny Tenderloin ([email protected])"; customer.TokenId = stripeToken; //customer.PlanId = *planId*; // only if you have a plan //customer.Coupon = *couponId*; // only if you have a coupon //customer.TrialEnd = DateTime.UtcNow.AddMonths(1); // when the customers trial ends (overrides the plan if applicable) //customer.Quantity = 1; // optional, defaults to 1 var customerService = new StripeCustomerService(Cohort.Site.Stripe.SecretKey); var stripeCustomer = customerService.Create(customer); // Create linkage between signup and customer for later charging return true; } catch (Exception) { // log return false; } }
public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions, StripeRequestOptions requestOptions = null) { return(Mapper <StripeCustomer> .MapFromJson( Requestor.PostString( this.ApplyAllParameters(createOptions, Urls.Customers, false), this.SetupRequestOptions(requestOptions)))); }
/// <summary> /// Creates the customer asynchronous. /// </summary> /// <param name="user">The user.</param> /// <param name="planId">The plan identifier.</param> /// <param name="trialEnd">The trial end.</param> /// <param name="cardToken">The card token.</param> /// <returns></returns> public async Task<object> CreateCustomerAsync(SaasEcomUser user, string planId = null, DateTime? trialEnd = null, string cardToken = null) { var customer = new StripeCustomerCreateOptions { AccountBalance = 0, Email = user.Email }; if (!string.IsNullOrEmpty(cardToken)) { customer.Card = new StripeCreditCardOptions { TokenId = cardToken }; } if (!string.IsNullOrEmpty(planId)) { customer.PlanId = planId; customer.TrialEnd = trialEnd; } var stripeUser = await Task.Run(() => _customerService.Create(customer)); return stripeUser; }
private async Task<string> ProcessSubscription(StripeChargeModel model) { //TODO if (model.Amount == 0) { model.Amount = 399; } var planId = "Up100PerMo"; var secretKey = ConfigurationManager.AppSettings["StripeApiKey"]; model.Card.TokenId = model.Id; return await Task.Run(() => { var stripeCustomerCreateOptions = new StripeCustomerCreateOptions { Email = model.Email, PlanId = planId, Card = model.Card, Description = "Charged £3.99 for monthly up to 100", }; var customerService = new StripeCustomerService(secretKey); var stripeCustomer = customerService.Create(stripeCustomerCreateOptions); return stripeCustomer.Id; }); }
public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions) { var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Customers); var response = Requestor.PostString(url, ApiKey); return Mapper<StripeCustomer>.MapFromJson(response); }
public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions) { var url = this.ApplyAllParameters(createOptions, Urls.Customers, false); var response = Requestor.PostString(url, ApiKey); return(Mapper <StripeCustomer> .MapFromJson(response)); }
public StripeCustomer Create(StripeCustomerCreateOptions createOptions) { var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Customers); var response = Requestor.PostString(url); return(PopulateStripeCustomer(response)); }
public StripeCustomer Create(StripeCustomerCreateOptions createOptions) { var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Customers); var response = Requestor.PostString(url); return PopulateStripeCustomer(response); }
public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions) { var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Customers + "?expand[]=default_card"); var response = Requestor.PostString(url, ApiKey); return(Mapper <StripeCustomer> .MapFromJson(response)); }
public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions) { var url = ParameterBuilder.ApplyAllParameters(createOptions, Urls.Customers); var response = Requestor.PostString(url); return(Mapper <StripeCustomer> .MapFromJson(response)); }
public virtual async Task <StripeCustomer> CreateAsync(StripeCustomerCreateOptions createOptions, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return(Mapper <StripeCustomer> .MapFromJson( await Requestor.PostStringAsync( this.ApplyAllParameters(createOptions, Urls.Customers, false), this.SetupRequestOptions(requestOptions), cancellationToken).ConfigureAwait(false))); }
//Async public virtual async Task<StripeCustomer> CreateAsync(StripeCustomerCreateOptions createOptions, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { return Mapper<StripeCustomer>.MapFromJson( await Requestor.PostStringAsync(this.ApplyAllParameters(createOptions, Urls.Customers, false), SetupRequestOptions(requestOptions), cancellationToken) ); }
public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions, StripeRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var url = this.ApplyAllParameters(createOptions, Urls.Customers, false); var response = Requestor.PostString(url, requestOptions); return(Mapper <StripeCustomer> .MapFromJson(response)); }
public virtual StripeCustomer Create(StripeCustomerCreateOptions createOptions, StripeRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var url = this.ApplyAllParameters(createOptions, Urls.Customers, false); var response = Requestor.Instance.PostString(url, requestOptions); return Mapper<StripeCustomer>.MapFromJson(response); }
public ActionResult About() { StripeConfiguration.SetApiKey("sk_test_JRb9hXgh80838IRQQTUHwJPP"); var myCustomer = new StripeCustomerCreateOptions(); // set these properties if it makes you happy myCustomer.Email = "*****@*****.**"; myCustomer.Description = "teste stripe.net"; // setting up the card myCustomer.Source = new StripeSourceOptions() { // set this property if using a token // TokenId = *tokenId *, Object = "card", // set these properties if passing full card details (do not // set these properties if you set TokenId) Number = "4242424242424242", ExpirationYear = "2022", ExpirationMonth = "10", AddressCountry = "IE", // optional AddressLine1 = "24 Beef Flank St", // optional AddressLine2 = "Apt 24", // optional AddressCity = "Biggie Smalls", // optional AddressState = "NC", // optional AddressZip = "27617", // optional Name = "Mateus Meatballs", // optional Cvc = "1223", }; myCustomer.PlanId = "2"; // only if you have a plan // myCustomer.TaxPercent = 20; // only if you are passing a plan, this tax percent will be added to the price. //myCustomer.Coupon = *couponId *; // only if you have a coupon //myCustomer.TrialEnd = DateTime.UtcNow.AddMonths(1); // when the customers trial ends (overrides the plan if applicable) myCustomer.Quantity = 1; // optional, defaults to 1 var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(myCustomer); return View(); }
public CreateCustomerResponse CreateCustomer(CreateCustomerRequest req) { var response = new CreateCustomerResponse(); try { var myCustomer = new StripeCustomerCreateOptions(); myCustomer.Email = req.Email; myCustomer.Description = req.Name; // set these properties if using a card myCustomer.CardNumber = req.CreditCard.CardNumber; myCustomer.CardExpirationYear = req.CreditCard.ExpirationYear.ToString(); myCustomer.CardExpirationMonth = req.CreditCard.ExpirationMonth.ToString(); myCustomer.CardAddressCountry = "US"; // optional //myCustomer.CardAddressLine1 = "24 Beef Flank St"; // optional //myCustomer.CardAddressLine2 = "Apt 24"; // optional //myCustomer.CardAddressState = "NC"; // optional myCustomer.CardAddressZip = req.PostalCode; // // optional myCustomer.CardName = req.CreditCard.CardHolderName; // optional if (req.CreditCard.SecurityCode.Length > 0) { myCustomer.CardCvc = req.CreditCard.SecurityCode; } myCustomer.PlanId = req.PlanId; var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(myCustomer); if (stripeCustomer.Id.Length > 0) { response.NewCustomerId = stripeCustomer.Id; response.Success = true; } else { response.Success = false; response.Message = "Unable to get new customer Id"; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }
private void CreateStripeCustomer(string stripeToken, string coupon) { var customer = new Stripe.StripeCustomerCreateOptions(); using (var db = InitializeSettings.DbFactory) { var data = db.Get <Majorsilence.Vpn.Poco.Users>(_userId); // If it is the first time the customer has paid we have not created an account yet // so do it now. customer.Email = data.Email; customer.Description = string.Format("{0} {1} ({2})", data.FirstName, data.LastName, data.Email); customer.TokenId = stripeToken; customer.PlanId = Helpers.SiteInfo.StripePlanId; //customer.TrialEnd = DateTime.Now.AddDays(30); if (coupon.Trim() != "") { customer.CouponId = coupon; } var customerService = new StripeCustomerService(Helpers.SiteInfo.StripeAPISecretKey); var cust = customerService.Create(customer); var subscriptionInfo = new StripeSubscriptionService(Helpers.SiteInfo.StripeAPISecretKey); var subscriptionList = subscriptionInfo.List(cust.Id).ToList(); if (subscriptionList.Count() > 1) { throw new Exceptions.StripeSubscriptionException( string.Format("More then one subscription detected for vpn customer: {0}, stripe customer: {1}", _userId, cust.Id) ); } data.StripeCustomerAccount = cust.Id; data.StripeSubscriptionId = subscriptionList.First().Id; db.Update(data); } }
private void createCustomer() { string token = "" + Request.Form["stripeToken"]; var myCustomer = new StripeCustomerCreateOptions(); myCustomer.Email = ""; myCustomer.Description = ""; //Setting up card myCustomer.Source = new StripeSourceOptions() { TokenId = token }; var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(myCustomer); //Add to DB DbConn.dBWrite("EXEC CreateStripeID '" + stripeCustomer.Id + "', " + Session["ID"]); }
public ActionResult Charge(string stripeToken, int quantities,string couponID) { decimal additionalPrice = 0; // get selected plan User userObj = (User)Session["user"]; var planID = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID).PlanID; // get selected plan details var selectedPlanName = planRepository.Plans.FirstOrDefault(pid => pid.ID == planID); // create subscription and get subscription id var customerService = new StripeCustomerService(); customerService.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp"; var currentAccountDetails = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID); var customer = new StripeCustomerCreateOptions(); customer.PlanId = selectedPlanName.Name; customer.Quantity = quantities; customer.TokenId = stripeToken; customer.Email = userObj.Email; if (couponID != "") { customer.CouponId = couponID; } // Create subscription try { var subscriptionDetails = customerService.Create(customer); var stripeCustomerID = subscriptionDetails.Id; // save StripeCustomerID currentAccountDetails.StripeCustomerID = stripeCustomerID; accountRepo.SaveAccount(currentAccountDetails); Session["account"] = currentAccountDetails; return Json(1, JsonRequestBehavior.AllowGet); } catch (Exception ex) { Session["paymentFailureNotifications"] = "card_declined"; return RedirectToAction("BillingOptions", "Admin", new { id = 1 }); } //return RedirectToAction("BillingOptions", "Admin", new { id = 1 }); }
private StripeCustomer PerformStripeSubscriptionCheckout(CreateInvoiceReturn invoiceReturn) { try { var myCustomer = new StripeCustomerCreateOptions(); if (invoice.InvoiceBilling != null) { myCustomer.CardAddressCity = invoice.InvoiceBilling.City; myCustomer.CardAddressCountry = invoice.InvoiceBilling.Country; myCustomer.CardAddressLine1 = invoice.InvoiceBilling.Street; myCustomer.CardAddressState = invoice.InvoiceBilling.State; myCustomer.CardAddressZip = invoice.InvoiceBilling.Zip; myCustomer.Email = invoice.InvoiceBilling.Email; } if (invoice.Subscription != null) { myCustomer.TokenId = invoice.Subscription.ArticleNumber; if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Monthly) { myCustomer.PlanId = StripePlanNames.Monthly_Plan.ToString(); } else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Six_Months) { myCustomer.PlanId = StripePlanNames.Six_Month_League_Subscription.ToString(); } else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Three_Months) { myCustomer.PlanId = StripePlanNames.Three_Month_League_Subscription.ToString(); } else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Yearly) { myCustomer.PlanId = StripePlanNames.Yearly_League_Subscription.ToString(); } else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Monthly_RN_Sponsor) { myCustomer.PlanId = StripePlanNames.Monthly_RN_Sponsor.ToString(); } } //creates the customer //adds the subscription //charges the customer. var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(myCustomer); invoice.PaymentProviderCustomerId = stripeCustomer.Id; return stripeCustomer; } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); if (exception.Message.Contains("Your card was declined")) invoiceReturn.Status = InvoiceStatus.Card_Was_Declined; } return null; }
private StripeCustomer GetCustomer() { var mycust = new StripeCustomerCreateOptions(); mycust.Email = "*****@*****.**"; mycust.Description = "Rahul Pandey([email protected])"; mycust.CardNumber = "4242424242424242"; mycust.CardExpirationMonth = "11"; mycust.CardExpirationYear = "2018"; // mycust.PlanId = "100"; mycust.CardCvc = "123"; mycust.CardName = "Rahul Pandey"; mycust.CardAddressCity = "ABC"; mycust.CardAddressCountry = "USA"; mycust.CardAddressLine1 = "asbcd"; //mycust.TrialEnd = getrialend(); var customerservice = new StripeCustomerService("sk_test_fSK5PInUME0uPQnz7LatVoN0"); return customerservice.Create(mycust); }
public void Create(string userName, Plan plan, string stripeToken) { var user = UserManager.FindByName(userName); if (String.IsNullOrEmpty(user.StripeCustomerId)) //first time customer { //create customer which will create subscription if plan is set and cc info via token is provided var customer = new StripeCustomerCreateOptions() { Email = user.Email, Source = new StripeSourceOptions() { TokenId = stripeToken }, PlanId = plan.ExternalId //externalid is stripe plan.id }; StripeCustomer stripeCustomer = StripeCustomerService.Create(customer); user.StripeCustomerId = stripeCustomer.Id; user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); //Invoice Created var invoiceService = new StripeInvoiceService(); // IEnumerable<StripeInvoice> response = invoiceService.List().Where(x=>x.CustomerId == stripeCustomer.Id && x.Paid == true && ; // SendPaymentReceivedFromChargeEmail() } else { var stripeSubscription = StripeSubscriptionService.Create(user.StripeCustomerId, plan.ExternalId); user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); } }
private async Task CreateCustomer(StripeModel model) { await Task.Run(() => { // create customer based on validated token from stripe.js var myCustomer = new StripeCustomerCreateOptions(); // assign token to a credit card option for a user myCustomer.Card = new StripeCreditCardOptions() { TokenId = model.Token }; myCustomer.Email = User.Identity.Name; myCustomer.Description = User.Identity.Name; myCustomer.PlanId = model.SubscriptionType.ToString(); myCustomer.Quantity = 1; // create customer in stripe service var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(myCustomer); // get subscription Id from created user var subscriptionID = stripeCustomer.StripeSubscriptionList.StripeSubscriptions.FirstOrDefault().Id; // save credit card optional details StripeCustomerService customerServic = new StripeCustomerService(); stripeCustomer = customerService.Get(stripeCustomer.Id); var cardId = stripeCustomer.StripeDefaultCardId; // get card id var myCard = new StripeCardUpdateOptions(); myCard.Name = model.CardHolderName; myCard.AddressLine1 = model.AddressLine1; myCard.AddressLine2 = model.AddressLine2; myCard.AddressCity = model.AddressCity; myCard.AddressZip = model.AddressPostcode; myCard.AddressCountry = model.AddressCountry; var cardService = new StripeCardService(); StripeCard stripeCard = cardService.Update(stripeCustomer.Id, cardId, myCard); //........................ // record customer in database var cust = getCustomer(); if(cust == null) // new users { // get values to create a new record in StripeCustomer table StripeCustomers customer = new StripeCustomers(); customer.CustomerName = User.Identity.Name; customer.StripeCustomerID = stripeCustomer.Id; customer.StripeSubscriptionID = subscriptionID; customer.SubscriptionType = model.SubscriptionType.ToString(); customer.HasSubscription = true; customer.Interval = "Monthly"; customer.StartDate = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time"); if (model.SubscriptionType.ToString() == "standard") { customer.TrialValidUntil = currentTime.AddDays(30); } db.StripeCustomers.Add(customer); } else // user with db records { StripeCustomers newRecord = new StripeCustomers(); // take the data from current user newRecord.StripeCustomerID = stripeCustomer.Id; newRecord.CustomerName = User.Identity.Name; newRecord.StripeSubscriptionID = subscriptionID; newRecord.SubscriptionType = model.SubscriptionType.ToString(); newRecord.HasSubscription = true; newRecord.Interval = "Monthly"; newRecord.StartDate = currentTime; if (model.SubscriptionType.ToString() == "standard") { newRecord.TrialValidUntil = currentTime.AddDays(30); } db.StripeCustomers.Add(newRecord); // delete customer's old record in database db.StripeCustomers.Remove(cust); } db.SaveChanges(); }); }
private static StripeCustomerCreateOptions InitializeCreateSubscriptionOptions(ApplicationModel.Billing.CustomerPayment payment) { var myCustomer = new StripeCustomerCreateOptions(); // set these properties if it makes you happy myCustomer.Email = payment.Email; myCustomer.Description = payment.Description; // set these properties if using a card myCustomer.CardNumber = payment.CardNumber; //how is this coming in? myCustomer.CardExpirationYear = payment.CardExpirationYear; myCustomer.CardExpirationMonth = payment.CardExpirationMonth; myCustomer.CardAddressCountry = payment.CardAddressCountry; // optional myCustomer.CardAddressLine1 = payment.CardAddressLine1; // optional myCustomer.CardAddressLine2 = payment.CardAddressLine2; // optional myCustomer.CardAddressCity = payment.CardAddressCity; // optional myCustomer.CardAddressState = payment.CardAddressState; // optional myCustomer.CardAddressZip = payment.CardAddressZip; // optional myCustomer.CardName = payment.CardName; // optional myCustomer.CardCvc = payment.CardCvc; // optional // set this property if using a token myCustomer.PlanId = payment.PlanId; // only if you have a plan myCustomer.CouponId = (payment.CouponId != null && payment.CouponId != String.Empty) ? payment.CouponId : null; return myCustomer; }
private StripeCustomer CreateStripeCustomer(string apiKey, tbl_Orders order, StripeCheckoutModel model) { var myCustomer = new StripeCustomerCreateOptions { Email = order.CustomerEMail, Description = order.BillingFullName, CardNumber = model.CreditCardNumber, CardExpirationYear = model.ExpiryYear.ToString(), CardExpirationMonth = model.ExpiryMonth.ToString() }; var customerService = new StripeCustomerService(apiKey); var stripeCustomer = customerService.Create(myCustomer); return stripeCustomer; }
private StripeCustomer GetCustomer(NewDonationModel model, StripePlan plan) { var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); var currentUser = manager.FindById(User.Identity.GetUserId()); string userEmail = currentUser.Email; var myCustomer = new StripeCustomerCreateOptions { Email = userEmail, Description = currentUser.FirstName + currentUser.LastName, Source = new StripeSourceOptions() { TokenId = model.Token } }; myCustomer.PlanId = plan.Id; var customerService = new StripeCustomerService("sk_test_yPi2XADkAP3wiS1i6tkjErxZ"); return customerService.Create(myCustomer); }
private CreateInvoiceReturn ChargeStripeCheckoutPayment() { // Create the Stripe Request and get the data back. CreateInvoiceReturn output = new CreateInvoiceReturn(); var myCustomer = new StripeCustomerCreateOptions(); if (invoice.InvoiceBilling != null) { myCustomer.CardAddressCity = invoice.InvoiceBilling.City; myCustomer.CardAddressCountry = invoice.InvoiceBilling.Country; myCustomer.CardAddressLine1 = invoice.InvoiceBilling.Street; myCustomer.CardAddressState = invoice.InvoiceBilling.State; myCustomer.CardAddressZip = invoice.InvoiceBilling.Zip; myCustomer.Email = invoice.InvoiceBilling.Email; } myCustomer.TokenId = invoice.StripeToken; var myCharge = new StripeChargeCreateOptions(); var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(myCustomer); // always set these properties //need to convert to cents because thats what stripe uses. myCharge.AmountInCents = (int)(invoice.FinancialData.TotalIncludingTax * 100); myCharge.Currency = invoice.Currency.ToString(); // set this if you want to myCharge.Description = invoice.Note; // set this property if using a token myCharge.CustomerId = stripeCustomer.Id; myCharge.Capture = true; var chargeService = new StripeChargeService(); StripeCharge stripeCharge = chargeService.Create(myCharge); output.InvoiceId = invoice.InvoiceId; output.Status = InvoiceStatus.Stripe_Customer_Created_And_Charged; invoice.InvoiceStatus = InvoiceStatus.Stripe_Customer_Created_And_Charged; return output; }
public ActionResult AddNewCard(string stripeToken) { bool tokenUsed = false; User userObj = (User)Session["user"]; if (userObj.PrimaryUser == false) return RedirectToAction("Index", "Admin"); var stripeCustomerID = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID).StripeCustomerID; if (stripeCustomerID == null) { // create subscription and get subscription id var customerService = new StripeCustomerService(); customerService.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp"; var currentAccountDetails = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID); var customer = new StripeCustomerCreateOptions(); customer.PlanId = "Empty Plan"; customer.Quantity = 1; customer.TokenId = stripeToken; customer.Email = userObj.Email; // Create subscription var subscriptionDetails = customerService.Create(customer); stripeCustomerID = subscriptionDetails.Id; // save StripeCustomerID currentAccountDetails.StripeCustomerID = stripeCustomerID; accountRepo.SaveAccount(currentAccountDetails); tokenUsed = true; } else { var card = new StripeCardService(); card.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp"; var cardOpt = new StripeCardCreateOptions(); cardOpt.TokenId = stripeToken; var res = card.Create(stripeCustomerID, cardOpt); } return RedirectToAction("BillingOptions", "Admin", new { id = 1 }); }
public StripeObject CreateCustomer(string email, string firstName, string lastName) { string description = firstName + " " + lastName + " (" + email + ")"; try { var customerOptions = new StripeCustomerCreateOptions(); customerOptions.Email = email; customerOptions.Description = description; StripeCustomer customer = cusService.Create(customerOptions); return customer; } catch (Exception ex) { if (ex is StripeException) { StripeException exception = (StripeException) ex; StripeError err = exception.StripeError; StripeAccessError error = new CreateCustomerError(); error.Error_Type = err.ErrorType; return error; } return null; } }
// Methods for doing Stripe payment static private StripeCustomerCreateOptions SetNewCustomer(CreditCardInformation creditCardInfo, string productName) { var newCustomer = new StripeCustomerCreateOptions { Email = creditCardInfo.Email, CardNumber = creditCardInfo.CardNumber, CardExpirationMonth = creditCardInfo.ExpMonth, CardExpirationYear = creditCardInfo.ExpYear, CardName = creditCardInfo.FirstName + " " + creditCardInfo.LastName }; newCustomer.Description = string.Format("{0} ({1}) has purchased {2}", newCustomer.CardName, newCustomer.Email, productName); return newCustomer; }
/// <summary> /// Creates a new customer record in Stripe for the given user /// NOTE: Save changes on the underlying context for the model after calling this method /// </summary> /// <param name="user"></param> public static void CreateCustomer(IStripeUser user, string paymentToken = null) { // Do not overwrite the user, ever if (user.HasPaymentInfo()) return; var newCustomer = new StripeCustomerCreateOptions(); newCustomer.Email = user.Email; if (paymentToken != null) newCustomer.Card = new StripeCreditCardOptions() { TokenId = paymentToken }; var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(newCustomer); // Set the accounting info user.PaymentSystemId = stripeCustomer.Id; System.Diagnostics.Trace.TraceInformation("Created customer in stripe: '{0}' with id '{1}", user.Email, user.PaymentSystemId); }
/// <summary> /// Implements <see cref="IStripeService.CreateCustomer"/> /// </summary> public string CreateCustomer(User user) { var myCustomer = new StripeCustomerCreateOptions { Email = user.Email, Description = $"{user.FirstName} {user.LastName} ({user.Email})" }; var customerService = new StripeCustomerService(); try { StripeCustomer customer = customerService.Create(myCustomer); return customer.Id; } catch (StripeException ex) { string exceptionMessage; StripeExceptionType type; if (ex.HttpStatusCode >= HttpStatusCode.InternalServerError || (int)ex.HttpStatusCode == 429 /* Too Many Requests */ || (int)ex.HttpStatusCode == 402 /* Request Failed */) { type = StripeExceptionType.ServiceError; exceptionMessage = "An error occured while creating a customer account for you. Please try again later."; } else if (ex.HttpStatusCode == HttpStatusCode.Unauthorized) { // Note: We want to log this as it means we don't have a valid API key Debug.WriteLine("Stripe API Key is Invalid"); Debug.WriteLine(ex.Message); type = StripeExceptionType.ApiKeyError; exceptionMessage = "An error occured while talking to one of our backends. Sorry!"; } else { // Note: Log unknown errors Debug.WriteLine(ex.HttpStatusCode); Debug.WriteLine($"Stripe Type: {ex.StripeError.ErrorType}"); Debug.WriteLine($"Stripe Message: {ex.StripeError.Message}"); Debug.WriteLine($"Stripe Code: {ex.StripeError.Code}"); Debug.WriteLine($"Stripe Param: {ex.StripeError.Parameter}"); type = StripeExceptionType.UnknownError; exceptionMessage = "An unknown error occured while creating a customer account for you. Please try again later."; } throw new StripeServiceException(exceptionMessage, type, ex); } }