/// <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); }
/// <summary> /// Creates or update a customer /// </summary> /// <param name="customer"></param> /// <param name="paymentToken"></param> public static void CreateOrUpdateCustomer(ICustomerEntity customer, string paymentToken = null) { if (customer.HasPaymentInfo()) { UpdateCustomer(customer, paymentToken); } else { CreateCustomer(customer, paymentToken); } }