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 string CreateCustomer(string email, string name, string ccToken) { var myCustomer = new StripeCustomerCreateOptions(); // set these properties if it makes you happy myCustomer.Email = email; myCustomer.Description = name; myCustomer.SourceToken = ccToken; var customerService = new StripeCustomerService(Constants.StripeSecretKey); Stripe.StripeCustomer stripeCustomer = customerService.Create(myCustomer); return(stripeCustomer.Id); }
public IHttpActionResult Index() { StripeConfiguration.SetApiKey(WebConfigurationManager.AppSettings["StripeSecretKey"]); var json = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd(); var stripeEvent = StripeEventUtility.ParseEvent(json); var customerService = new StripeCustomerService(); string stripeCustomerID = stripeEvent.Data.Object.customer;//as string; var stripeCustomer = new Stripe.StripeCustomer(); //Test var eventObjectInfo = JObject.Parse(json); var evtDataObject = eventObjectInfo.SelectToken("data.object"); switch (stripeEvent.Type) { case StripeEvents.PayoutPaid: //var customer = Mapper<Stripe.StripeCustomer>.MapFromJson(eventObjectInfo.ToString()); return(Json(new { success = true, message = "Hello world number" })); case StripeEvents.InvoicePaymentFailed: return(Json(new { id = stripeEvent.Id, message = "User Subcription Paused" })); case StripeEvents.ChargeSucceeded: string dytoString = Convert.ToString(stripeCustomerID); var obj = _context.StripeCustomers.FirstOrDefault(c => c.StripeCustomerID == dytoString); if (obj != null) { } return(Json(new { type = stripeEvent.Type, stripeEvent.Type })); case StripeEvents.InvoiceCreated: //string custID = stripeEvent.Data.Object.customer; //var getCustomer = customerService.Get(custID); var evt = Mapper <StripeEvent> .MapFromJson(eventObjectInfo.ToString()); return(Json(new { evt.Id, evt.Data.Object.customer })); case StripeEvents.InvoicePaymentSucceeded: return(Json(new { message = "Invoice Payment Successful" })); default: return(Json(new { id = stripeEvent.Id })); } }
public string UpdateCustomer(string stripeId, string ccToken) { //remove old card var customerService = new StripeCustomerService(Constants.StripeSecretKey); Stripe.StripeCustomer stripeCustomer = customerService.Get(stripeId); if (!String.IsNullOrEmpty(stripeCustomer.DefaultSourceId)) { var cardService = new StripeCardService(Constants.StripeSecretKey); cardService.Delete(stripeId, stripeCustomer.DefaultSourceId); } var myCustomer = new StripeCustomerUpdateOptions(); myCustomer.SourceToken = ccToken; // this will set the default card to use for this customer var finalCustomer = customerService.Update(stripeId, myCustomer); return(finalCustomer.Id); }
static private StripeCustomerUpdateOptions SetUpdateCustomer(StripeCustomer oldCustomer, CreditCardInformation creditCardInfo, string productName) { var customerUpdateOptions = new StripeCustomerUpdateOptions { Email = creditCardInfo.Email, CardNumber = creditCardInfo.CardNumber, CardExpirationMonth = creditCardInfo.ExpMonth, CardExpirationYear = creditCardInfo.ExpYear, CardCvc = creditCardInfo.CVV2, CardName = creditCardInfo.FirstName + " " + creditCardInfo.LastName }; //if (oldCustomer.Description != oldCustomer.StripeCard.Name + " (" + oldCustomer.Email + ")" + " has purchased tubeCore") // customerUpdateOptions.Description = oldCustomer.Description + " and tubeCore"; //else // customerUpdateOptions.Description = customerUpdateOptions.CardName + " (" + customerUpdateOptions.Email + ")" + " has purchased tubeCore"; if (!Utility.IsStringEmpty(oldCustomer.Description) && oldCustomer.Description.Contains("has purchased")) customerUpdateOptions.Description += string.Format("{0} and {1}", oldCustomer.Description, productName); else customerUpdateOptions.Description = string.Format("{0} ({1}) has purchased {2}", customerUpdateOptions.CardName, customerUpdateOptions.Email, productName); return customerUpdateOptions; }
private void MapStripeCustomerTo(StripeCustomer stripeCustomer, GetCustomerResponse response) { if (response == null) return; response.Email = CleanUpStripeEmail(stripeCustomer.Email); response.Id = stripeCustomer.Id; response.Description = stripeCustomer.Description; if (stripeCustomer.StripeSubscription != null) { response.PlanId = stripeCustomer.StripeSubscription.StripePlan.Id; response.PlanName = stripeCustomer.StripeSubscription.StripePlan.Name; decimal planAmount = (decimal)stripeCustomer.StripeSubscription.StripePlan.AmountInCents; planAmount = planAmount / 100; response.PlanAmount = planAmount; response.PlanStatus = stripeCustomer.StripeSubscription.Status; } if (stripeCustomer.StripeNextRecurringCharge != null) { decimal nextCharge = (decimal)stripeCustomer.StripeNextRecurringCharge.AmountInCents; nextCharge = nextCharge / 100; string nextStatus = "Next charge " + nextCharge.ToString("C") + " on " + stripeCustomer.StripeNextRecurringCharge.Date; response.NextCharge = nextStatus; } if (stripeCustomer.StripeCard == null) { response.HasCard = false; } else { response.HasCard = true; } }
private async Task<string> SubscriptionDonation(NewDonationModel model, StripeCustomer customer) { return await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { Amount = (int)(model.Amount * 100), Currency = "usd", ReceiptEmail = customer.Email, CustomerId = customer.Id }; var chargeService = new StripeChargeService("sk_test_yPi2XADkAP3wiS1i6tkjErxZ"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; }); }
private string GetStripeSubscriptionIdForNewCustomer(StripeCustomer stripeUser) { return stripeUser.StripeSubscriptionList.TotalCount > 0 ? stripeUser.StripeSubscriptionList.Data.First().Id : null; }
void IEmailHelper.SendSubscriptionCancelled(StripeCustomer customer, string customerEmail, string customerName) { Guard.ArgumentNotNullOrEmptyString(customerName, "customerName"); Guard.ArgumentNotNullOrEmptyString(customerEmail, "customerEmail"); Guard.ArgumentNotNull(() => customer); Dictionary<string, string> values = new Dictionary<string, string>(); values.Add("FirstName", customerName); values.Add("Date", customer.StripeSubscription.TrialEnd.ToString()); var send = this as IEmailHelper; string fileName = String.Empty; if (root.Contains("~")) { fileName = System.Web.HttpContext.Current.Server.MapPath(root + "SubscriptionCancelled.txt"); } else { fileName = root + "SubscriptionCancelled.txt"; } send.SetupEmail(values, customerEmail, fileName, "We Need You Have. Subscription Cancelled Notice."); }
public void UpdateCustomer_ValidParameters_Successful() { //Arrange StripeCustomer customer = new StripeCustomer(); customer.Id = customerId; Mock<StripeCustomerService> custCustService = new Mock<StripeCustomerService>(null); custCustService.Setup(cust => cust.Update(It.IsAny<string>(), It.IsAny<StripeCustomerUpdateOptions>(), null)) .Returns(customer); stripeAccessor = new StripeAccessorService(subService.Object, charService.Object, custCustService.Object); //Act string returnedId = stripeAccessor.UpdateCustomer(customerId, "email", "Hal", "Wilkerson"); //Assert Assert.That(returnedId, Is.EqualTo(customerId)); }
public void GetCustomer_ValidParameters_Successful() { //Arrange StripeCustomer customer = new StripeCustomer(); customer.Id = customerId; Mock<StripeCustomerService> custCustService = new Mock<StripeCustomerService>(null); custCustService.Setup(cust => cust.Get(It.IsAny<String>(), null)) .Returns(customer); stripeAccessor = new StripeAccessorService(subService.Object, charService.Object, custCustService.Object); //Act StripeObject returnedCustomer = stripeAccessor.GetCustomer(customerId); //Assert Assert.That(returnedCustomer.Id, Is.EqualTo(customerId)); Assert.That(returnedCustomer, Is.InstanceOf<StripeCustomer>()); }