public async Task <StripeCustomer> CreateCustomerAsync(StripeCustomerCreateOptions options, string apiKey) { var customerService = new StripeCustomerService(apiKey); var customer = customerService.Create(options); return(customer); }
public static StripeCustomerCreateOptions ValidToken(string tokenId, string _planId = null, string _couponId = null, DateTime?_trialEnd = null) { var stripeCustomerCreateOptions = new StripeCustomerCreateOptions() { // obsolete: Source = new StripeSourceOptions() { TokenId = tokenId } SourceToken = tokenId }; if (_planId != null) { stripeCustomerCreateOptions.PlanId = _planId; } if (_couponId != null) { stripeCustomerCreateOptions.CouponId = _couponId; } if (_trialEnd != null) { stripeCustomerCreateOptions.TrialEnd = _trialEnd; } return(stripeCustomerCreateOptions); }
public void createSuscription(int userId, TipoSuscripcion suscripcion, string token, string stripePrivateKey) { StripeConfiguration.SetApiKey(stripePrivateKey); var suscriptor = entities.Suscriptor.Find(userId); if (string.IsNullOrEmpty(suscriptor.stripeCustomerId)) { var customer = new StripeCustomerCreateOptions() { Email = suscriptor.correoElectronico, SourceToken = token, PlanId = suscripcion.externalId }; var stripeCustomer = _customerServices.Create(customer); suscriptor.stripeCustomerId = stripeCustomer.Id; suscriptor.TipoSuscripcionSuscriptor.Add(new TipoSuscripcionSuscriptor() { suscriptorId = suscriptor.suscriptorId, tipoSuscripcionId = suscripcion.tipoSuscripcionId, fechaExperacion = (DateTime.Now.AddDays(30)), fechaCompra = DateTime.Now }); entities.SaveChanges(); } else { var subscriptionService = subscriptionServices.Create(suscriptor.stripeCustomerId, suscripcion.externalId); ///// update suscription } }
public ActionResult Subscribe(StripeTokenResponse data) { var myCustomer = new StripeCustomerCreateOptions(); myCustomer.Email = User.Identity.Name; myCustomer.SourceToken = data.StripeToken; myCustomer.PlanId = ConfigurationManager.AppSettings["stripe:plan"]; // only if you have a plan myCustomer.TaxPercent = 0; // only if you are passing a plan, this tax percent will be added to the price. Metrics.Info($"Creating subscription for {myCustomer.Email} {myCustomer.SourceToken} {myCustomer.PlanId}"); var customerService = new StripeCustomerService(ConfigurationManager.AppSettings["stripe:token_secret"]); StripeCustomer stripeCustomer = customerService.Create(myCustomer); using (var db = new Email2SmsContext()) { var userId = GetUserId(); var row = db.Subscriptions.FirstOrDefault(f => f.User == userId); if (row == null) { row = new Subscription { User = userId }; db.Subscriptions.Add(row); } row.StripeCustomer = stripeCustomer.Id; row.LastInvoiceUtc = DateTime.UtcNow; db.SaveChanges(); } return(Redirect("~/home/setup")); }
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 StripeCustomer CreateStripeCustomer(string sEmail, string sToken, string sInputDiscountCode) { try { StripeConfiguration.SetApiKey(ConfigurationManager.AppSettings["stripeApi_LiveKey"]); var customerService = new StripeCustomerService(); string sDiscountCode = ConfigurationManager.AppSettings["discount_code"]; var CustomerOptions = new StripeCustomerCreateOptions() { Email = sEmail, Description = "EmediCodes Basic Plan for " + sEmail, AccountBalance = 0, PlanId = "1", SourceToken = sToken, TrialEnd = DateTime.Now + TimeSpan.FromDays(14) }; if (sInputDiscountCode.Equals(sDiscountCode)) { CustomerOptions.CouponId = sDiscountCode; } StripeCustomer customer = customerService.Create(CustomerOptions); return(customer); } catch (Exception ex) { oLogger.LogData("METHOD: CreateStripeCustomer; ERROR: TRUE; EXCEPTION: " + ex.Message + "; INNER EXCEPTION: " + ex.InnerException + "; STACKTRACE: " + ex.StackTrace); throw; } }
public static StripeCustomerCreateOptions ValidCard(string _planId = null, string _couponId = null, DateTime?_trialEnd = null) { var stripeCustomerCreateOptions = new StripeCustomerCreateOptions() { CardAddressCountry = "US", CardAddressLine1 = "234 Bacon St", CardAddressLine2 = "Apt 1", CardAddressState = "NC", CardAddressZip = "27617", Email = "*****@*****.**", CardCvc = "1661", CardExpirationMonth = "10", CardExpirationYear = "2021", CardName = "Johnny Tenderloin", CardNumber = "4242424242424242", Description = "Johnny Tenderloin ([email protected])", }; if (_planId != null) { stripeCustomerCreateOptions.PlanId = _planId; } if (_couponId != null) { stripeCustomerCreateOptions.CouponId = _couponId; } if (_trialEnd != null) { stripeCustomerCreateOptions.TrialEnd = _trialEnd; } return(stripeCustomerCreateOptions); }
public void Create(string userName, Plan plan, string stripeToken) { //get User 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 //external id is Stripe plan id }; StripeCustomer stripeCustomer = StripeCustomerService.Create(customer); //update user user.StripeCustomerId = stripeCustomer.Id; user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); } else { //customer already exists, add subscription to customer var stripeSubscription = StripeSubscriptionService.Create(user.StripeCustomerId, plan.ExternalId); user.ActiveUntil = DateTime.Now.AddDays((double)plan.TrialPeriodDays); UserManager.Update(user); } }
public string CreateCustomerObject(CustomerObjectRequest cardTokenRequest) { var customerCreateOptions = new StripeCustomerCreateOptions(); customerCreateOptions.TokenId = cardTokenRequest.CardToken; //these are all optional customerCreateOptions.Email = "*****@*****.**"; customerCreateOptions.Description = "I am a tasty customer"; var metaData = new Dictionary <string, string>(); metaData.Add("opentableId", "123456"); customerCreateOptions.Metadata = metaData; var customerService = new StripeCustomerService(ConfigurationManager.AppSettings["masterMerchantSecretkey"]); try { StripeCustomer createdCustomer = customerService.Create(customerCreateOptions); return(createdCustomer.Id); } catch (StripeException sx) { //do some logging } return(""); }
public attaching_and_detaching_sources() { var SourceCardCreateOptions = new StripeSourceCreateOptions { Type = StripeSourceType.Card, Token = "tok_visa" }; var CustomerCreateOptions = new StripeCustomerCreateOptions { Email = "*****@*****.**", }; var sourceService = new StripeSourceService(Cache.ApiKey); var customerService = new StripeCustomerService(Cache.ApiKey); var SourceCard = sourceService.Create(SourceCardCreateOptions); Customer = customerService.Create(CustomerCreateOptions); var SourceAttachOptions = new StripeSourceAttachOptions { Source = SourceCard.Id }; SourceAttached = sourceService.Attach(Customer.Id, SourceAttachOptions); SourceDetached = sourceService.Detach(Customer.Id, SourceAttached.Id); }
public ActionResult SubmitStripeSubscriptionForm(StripeSubscriptionCheckout model) { if (ModelState.IsValid) { var loggedOnMember = Members.GetCurrentMember(); var memberService = Services.MemberService; var member = memberService.GetById(loggedOnMember.Id); var customer = new StripeCustomerCreateOptions(); customer.Email = member.Email; customer.Description = member.Name; customer.SourceToken = model.StripeToken; customer.PlanId = model.PlanId; try { var customerService = new StripeCustomerService(SensativeInformation.StripeKeys.SecretKey); StripeCustomer stripeCustomer = customerService.Create(customer); //Log customer id on member member.SetValue("stripeUserId", stripeCustomer.Id); memberService.Save(member); return(RedirectToCurrentUmbracoPage()); } catch (StripeException e) { _log.Error(e.StripeError.Message); ModelState.AddModelError("", "There was an error setting up your subscription. Please try again. If the issue persists please contact us"); } } return(CurrentUmbracoPage()); }
public creating_and_updating_subscriptions_with_manual_invoicing() { var customerService = new StripeCustomerService(Cache.ApiKey); var subscriptionService = new StripeSubscriptionService(Cache.ApiKey); var CustomerCreateOptions = new StripeCustomerCreateOptions { Email = "*****@*****.**", }; var Customer = customerService.Create(CustomerCreateOptions); var SubscriptionCreateOptions = new StripeSubscriptionCreateOptions { Billing = StripeBilling.SendInvoice, DaysUntilDue = 7, PlanId = Cache.GetPlan("silver").Id }; SubscriptionCreated = subscriptionService.Create(Customer.Id, SubscriptionCreateOptions); var SubscriptionUpdateOptions = new StripeSubscriptionUpdateOptions { DaysUntilDue = 2, }; SubscriptionUpdated = subscriptionService.Update(SubscriptionCreated.Id, SubscriptionUpdateOptions); }
/// <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); }
/// <summary> /// Creates a new customer record in Stripe for the given user /// This will set the "PaymentSystemId" property on the given IStripeUser instance if the user was successfully created /// NOTE: Save changes on the underlying context for the model after calling this method /// </summary> /// <param name="customer"></param> /// <param name="paymentToken"></param> public static StripeCustomer CreateCustomer(ICustomerEntity customer, string paymentToken = null) { // Do not overwrite the user, ever if (customer.HasPaymentInfo()) { return(null); } var newCustomer = new StripeCustomerCreateOptions(); newCustomer.Email = customer.Email; if (paymentToken != null) { newCustomer.Source = new StripeSourceOptions() { TokenId = paymentToken } } ; var customerService = new StripeCustomerService(); StripeCustomer stripeCustomer = customerService.Create(newCustomer); // Set the accounting info customer.PaymentSystemId = stripeCustomer.Id; Logger.Log <StripeManager>("Created customer in stripe: '{0}' with id '{1}", LogLevel.Information, customer.Email, customer.PaymentSystemId); return(stripeCustomer); }
public creating_and_updating_invoices_with_manual_invoicing() { var customerService = new StripeCustomerService(Cache.ApiKey); var invoiceItemService = new StripeInvoiceItemService(Cache.ApiKey); var invoiceService = new StripeInvoiceService(Cache.ApiKey); var CustomerCreateOptions = new StripeCustomerCreateOptions { Email = "*****@*****.**", }; var Customer = customerService.Create(CustomerCreateOptions); var InvoiceItemCreateOptions = new StripeInvoiceItemCreateOptions { Amount = 1000, Currency = "usd", CustomerId = Customer.Id }; var InvoiceItem = invoiceItemService.Create(InvoiceItemCreateOptions); var InvoiceCreateOptions = new StripeInvoiceCreateOptions { Billing = StripeBilling.SendInvoice, DaysUntilDue = 7, }; InvoiceCreated = invoiceService.Create(Customer.Id, InvoiceCreateOptions); var InvoiceUpdateOptions = new StripeInvoiceUpdateOptions { Paid = true, }; InvoiceUpdated = invoiceService.Update(InvoiceCreated.Id, InvoiceUpdateOptions); }
public StripeCharge CreateCharge(string customerEmail, string customerDescription, string customerToken, string accessToken, string chargeDescription, decimal chargeAmount, Int32 applicationFee) { // create charge var customerOptions = new StripeCustomerCreateOptions { Email = customerEmail, //Email, Description = customerDescription, TokenId = customerToken, }; var stripeCustomerService = new StripeCustomerService(accessToken); //owner.AccessToken var customer = stripeCustomerService.Create(customerOptions); var stripeChargeService = new StripeChargeService(accessToken); //The token returned from the above method var stripeChargeOption = new StripeChargeCreateOptions() { Amount = Convert.ToInt32(chargeAmount * 100), Currency = "usd", CustomerId = customer.Id, Description = chargeDescription, ApplicationFee = applicationFee }; return(stripeChargeService.Create(stripeChargeOption)); }
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 listing_cards_on_customer() { var customerService = new StripeCustomerService(Cache.ApiKey); var bankAccountService = new BankAccountService(Cache.ApiKey); var cardService = new StripeCardService(Cache.ApiKey); var CustomerCreateOptions = new StripeCustomerCreateOptions { Email = "*****@*****.**", SourceToken = "tok_visa", }; var Customer = customerService.Create(CustomerCreateOptions); var BankAccountCreateOptions = new BankAccountCreateOptions { SourceBankAccount = new SourceBankAccount() { RoutingNumber = "110000000", AccountNumber = "000123456789", Country = "US", Currency = "usd", AccountHolderName = "Jenny Rosen", AccountHolderType = BankAccountHolderType.Individual, } }; var BankAccount = bankAccountService.Create(Customer.Id, BankAccountCreateOptions); ListCards = cardService.List(Customer.Id); }
public customers_fixture() { CustomerCreateOptionsWithShipping = new StripeCustomerCreateOptions { Email = "*****@*****.**", SourceToken = "tok_visa", Shipping = new StripeShippingOptions { Name = "Namey Namerson", Line1 = "123 Main St", Line2 = "Apt B", Country = "USA", State = "NC", } }; var service = new StripeCustomerService(Cache.ApiKey); CustomerWithShipping = service.Create(CustomerCreateOptionsWithShipping); CustomerUpdateOptionsWithShipping = new StripeCustomerUpdateOptions { Email = "*****@*****.**", Shipping = CustomerCreateOptionsWithShipping.Shipping }; CustomerUpdateOptionsWithShipping.Shipping.Phone = "8675309"; UpdatedCustomerWithShipping = service.Update(CustomerWithShipping.Id, CustomerUpdateOptionsWithShipping); }
private StripeCustomer GetCustomer() { var mycust = new StripeCustomerCreateOptions(); SourceCard card = new SourceCard(); card.Number = "4242424242424242"; card.Name = "Yathiraj U"; card.ExpirationMonth = "10"; card.ExpirationYear = "2016"; card.AddressCountry = "USA"; card.ReceiptEmail = "*****@*****.**"; card.AddressCity = "abc"; mycust.Email = "uryathi834 @gmail.com"; card.Cvc = "123"; mycust.PlanId = "123456"; // mycust.TrialEnd = mycust.Description = "Rahul Pandey([email protected])"; mycust.SourceCard = card; // mycust.SourceCard = "USA"; // mycust.CardExpirationMonth = "10"; // mycust.CardExpirationYear = "2016"; // mycust.PlanId = "100"; //mycust.TrialEnd = getrialend(); var customerservice = new StripeCustomerService("sk_test_CQT723mQ9B3Qhzs7pxUtINLv"); return(customerservice.Create(mycust)); }
private StripeCustomer createTCGStripeCustomer(StorePaymentMethod_Details details, string sourceToken) { StripeConfiguration.SetApiKey(secretKey); StripeCustomer customer = new StripeCustomer(); try { StripeSource source = new StripeSource(); if (sourceToken == null) { source = createStripeSource(details.CardNumber, details.CardExpiryYear, details.CardExpiryMonth, details.CardCVV, details.CardHolderFullName, true); } else { source.Id = sourceToken; } //ATTACH THE SOURCE TO CUSTOMER var customerOptions = new StripeCustomerCreateOptions() { SourceToken = source.Id }; var customerService = new StripeCustomerService(); customer = customerService.Create(customerOptions); } catch (StripeException e) { throw new StripeException(e.HttpStatusCode, e.StripeError, e.Message); } return(customer); }
public static StripeCustomerCreateOptions ValidCard(string _planId = null, string _couponId = null, DateTime? _trialEnd = null) { var stripeCustomerCreateOptions = new StripeCustomerCreateOptions() { CardAddressCountry = "US", CardAddressLine1 = "234 Bacon St", CardAddressLine2 = "Apt 1", CardAddressState = "NC", CardAddressZip = "27617", Email = "*****@*****.**", CardCvc = "1661", CardExpirationMonth = "10", CardExpirationYear = "2021", CardName = "Johnny Tenderloin", CardNumber = "4242424242424242", Description = "Johnny Tenderloin ([email protected])", }; if (_planId != null) stripeCustomerCreateOptions.PlanId = _planId; if (_couponId != null) stripeCustomerCreateOptions.CouponId = _couponId; if (_trialEnd != null) stripeCustomerCreateOptions.TrialEnd = _trialEnd; return stripeCustomerCreateOptions; }
private static string CreateStripeCustomer(string userId, string stripeToken) { var customerService = new StripeCustomerService(); var getStripeCustomer = _context.StripeCustomers.FirstOrDefault(c => c.UserId == userId); if (getStripeCustomer != null) { return(getStripeCustomer.StripeCustomerID); } var getUser = _context.Users.FirstOrDefault(c => c.Id == userId); var customerOptions = new StripeCustomerCreateOptions() { Description = "Veme Customer", SourceToken = stripeToken, Email = getUser.Email }; Stripe.StripeCustomer customer = customerService.Create(customerOptions); _context.StripeCustomers.Add(new POCO.StripeCustomer { CreationDate = DateTime.Now.Date, StripeCustomerID = customer.Id, UserId = userId }); _context.SaveChanges(); return(customer.Id); }
public async Task test_payments() { StripeConfiguration.SetApiKey(ConfigurationManager.AppSettings["Stripe.SecretKey"]); var stripeTokenreateOptions = new StripeTokenCreateOptions(); stripeTokenreateOptions.Card = new StripeCreditCardOptions() { Number = "4242424242424242", ExpirationYear = "2022", ExpirationMonth = "10", }; var tokenService = new StripeTokenService(); StripeToken stripeToken = tokenService.Create(stripeTokenreateOptions); StripeCustomerCreateOptions customerCreateOptions = new StripeCustomerCreateOptions { SourceToken = stripeToken.Id, Email = $"{Guid.NewGuid()}@test.com" }; var customerService = new StripeCustomerService(); var customer = customerService.Create(customerCreateOptions); var dbConnection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); var stripeService = new StripeService(dbConnection); await stripeService.TryCharge(customer.Id, 300, "AUD"); }
public void TestCreateCustomer() { StripeSDKMain stripe = new StripeSDKMain(); StripeCustomerCreateOptions stripeCustomerCreateOptions = new StripeCustomerCreateOptions() { Description = "Maro", Email = "*****@*****.**", SourceToken = "tok_visa", }; Serializer serializer = new Serializer(); var stripeCustomerCreateOptionsJSON = serializer.Serialize <StripeCustomerCreateOptions>(stripeCustomerCreateOptions); string Response = ""; string Errors = ""; int ErrorCode = 0; var Api_Key = GetApiKey(); stripe.CreateCustomer(Api_Key, stripeCustomerCreateOptionsJSON, ref Response, ref Errors, ref ErrorCode); if (ErrorCode == 0) { Console.WriteLine(Response); } else { Console.WriteLine(Errors); } }
public async Task WhenStripeModeIsLive_ItShouldCreateACustomer() { this.apiKeyRepository.Setup(v => v.GetApiKey(UserType.StandardUser)).Returns(LiveKey); var expectedOptions = new StripeCustomerCreateOptions { Description = UserId.ToString(), Source = new StripeSourceOptions { TokenId = TokenId, } }; var customer = new StripeCustomer { Id = CustomerId }; this.stripeService.Setup(v => v.CreateCustomerAsync( It.Is <StripeCustomerCreateOptions>( x => JsonConvert.SerializeObject(x, Formatting.None) == JsonConvert.SerializeObject(expectedOptions, Formatting.None)), LiveKey)) .ReturnsAsync(customer); var result = await this.target.ExecuteAsync(UserId, TokenId, UserType.StandardUser); Assert.AreEqual(CustomerId, result); }
public static StripeCustomerCreateOptions ValidToken(string tokenId, string _planId = null, string _couponId = null, DateTime?_trialEnd = null) { var stripeCustomerCreateOptions = new StripeCustomerCreateOptions() { Card = new StripeCreditCardOptions() { TokenId = tokenId } }; if (_planId != null) { stripeCustomerCreateOptions.PlanId = _planId; } if (_couponId != null) { stripeCustomerCreateOptions.CouponId = _couponId; } if (_trialEnd != null) { stripeCustomerCreateOptions.TrialEnd = _trialEnd; } return(stripeCustomerCreateOptions); }
public IHttpActionResult PostPaymentAccount(StripeBindingModel stripeBindingModel) { int accountId = this.GetAccountId(); Account account = db.Accounts.Find(accountId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Use stripe to get the customer token string stripeCustomerToken = ""; var myCustomer = new StripeCustomerCreateOptions(); myCustomer.SourceToken = stripeBindingModel.CardToken; var customerService = new StripeCustomerService(); var stripeCustomer = customerService.Create(myCustomer); PaymentAccount paymentAccount = new PaymentAccount(PaymentMethod.Stripe, stripeCustomerToken); paymentAccount.AccountId = accountId; // updae the default payment account as the new account account.DefaultPaymentAccount = paymentAccount; db.SetModified(account); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = paymentAccount.Id }, paymentAccount)); }
public bool Post([FromBody] JObject report) { Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("Username", report.Property("username").Value.ToString()); List <Subscription> sub = new Subscription().SearchDocument(parameters); if (sub.Count <= 0) { StripeConfiguration.SetApiKey("sk_test_p9FWyo0hC9g8y39CkRR1pnYH"); var options = new StripeCustomerCreateOptions { Email = report.Property("email").Value.ToString(), SourceToken = report.Property("id").Value.ToString() }; var service = new StripeCustomerService(); StripeCustomer customer = service.Create(options); DoSub(customer, report); } else { updateSubscription(report); } return(true); }
public ActionResult Index(string jsonCardInformation) { JObject jObject = JObject.Parse(jsonCardInformation); string key = ConfigurationManager.AppSettings["StripeSecretKey"]; var myCustomer = new StripeCustomerCreateOptions(); myCustomer.Email = System.Web.HttpContext.Current.User.Identity.Name; myCustomer.Description = "Testing a Card"; myCustomer.SourceToken = jObject["tokenId"].ToString(); var customerService = new StripeCustomerService(); StripeRequestOptions requestOption = new StripeRequestOptions() { ApiKey = key }; StripeCustomer stripeCustomer = new StripeCustomer(); stripeCustomer = customerService.Create(myCustomer, requestOption); CardInfo newCustomer = new CardInfo() { CustomerId = stripeCustomer.Id, Email = System.Web.HttpContext.Current.User.Identity.Name, Name = jObject["name"].ToString(), CardType = jObject["cardBrand"].ToString(), LastFour = jObject["lastFour"].ToString() }; ctx.Cards.Add(newCustomer); ctx.SaveChanges(); var x = ctx.Cards.Where(y => y.Email == System.Web.HttpContext.Current.User.Identity.Name); return(View(x)); }
/// <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); }
public static StripeCustomerCreateOptions ValidCard(string _planId = null, string _couponId = null, DateTime? _trialEnd = null, bool _trialEndNow = false) { // obsolete: var cardOptions = new StripeSourceOptions() var cardOptions = new SourceCard() { AddressCountry = "US", AddressLine1 = "234 Bacon St", AddressLine2 = "Apt 1", AddressState = "NC", AddressZip = "27617", Cvc = "1661", ExpirationMonth = "10", ExpirationYear = "2021", Name = "Johnny Tenderloin", Number = "4242424242424242", }; var stripeCustomerCreateOptions = new StripeCustomerCreateOptions() { // obsolete: Source = cardOptions, SourceCard = cardOptions, Email = "*****@*****.**", Description = "Johnny Tenderloin ([email protected])", AccountBalance = 100, Metadata = new Dictionary<string, string> { { "A", "Value-A" }, { "B", "Value-B" } } }; if (_planId != null) stripeCustomerCreateOptions.PlanId = _planId; if (_couponId != null) stripeCustomerCreateOptions.CouponId = _couponId; if (_trialEnd != null) stripeCustomerCreateOptions.TrialEnd = _trialEnd; if (_trialEndNow) stripeCustomerCreateOptions.EndTrialNow = true; return stripeCustomerCreateOptions; }
public static StripeCustomerCreateOptions ValidToken(string tokenId, string _planId = null, string _couponId = null, DateTime? _trialEnd = null) { var stripeCustomerCreateOptions = new StripeCustomerCreateOptions() { TokenId = tokenId }; if (_planId != null) stripeCustomerCreateOptions.PlanId = _planId; if (_couponId != null) stripeCustomerCreateOptions.CouponId = _couponId; if (_trialEnd != null) stripeCustomerCreateOptions.TrialEnd = _trialEnd; return stripeCustomerCreateOptions; }