CustomerPayment ISubscriptionService.SaveCustomer(string id, ApplicationModel.Billing.CustomerPayment payment) { //Save Subscription Need to check first active vs new here var organization = this.organizationRepository.Find(payment.OrganizationId, null, null); var customerService = new StripeCustomerService(); if (id != null && id != "null") { var myCustomer = InitializeUpdateCustomerOptions(payment); StripeCustomer stripeCustomer = customerService.Update(id, myCustomer); } else { var myCustomer = InitializeCreateSubscriptionOptions(payment); StripeCustomer stripeCustomer = customerService.Create(myCustomer); id = stripeCustomer.StripeSubscription.CustomerId; payment.CustomerId = id; } organization.Subscription.Status = SubscriptionStatus.ACTIVE; organization.Subscription.CustomerBillingId = id; if (!String.IsNullOrEmpty(payment.CardNumber)) { organization.Subscription.ExpirationDate = payment.CardExpirationMonth + "/" + payment.CardExpirationYear; organization.Subscription.Last4Digits = payment.CardNumber.Substring(payment.CardNumber.Length - 4, 4); } organization.Subscription.HasTrialed = true; var svc = (ISubscriptionService)this; svc.SaveSubscription(organization); return(payment); }
private static StripeCustomerUpdateOptions InitializeUpdateCustomerOptions(ApplicationModel.Billing.CustomerPayment payment) { var myCustomer = new StripeCustomerUpdateOptions(); // 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 return(myCustomer); }
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 static StripeCustomerUpdateSubscriptionOptions InitializeUpdateSubscriptionOptions(ApplicationModel.Billing.CustomerPayment payment, Organization organization) { var myCustomer = new StripeCustomerUpdateSubscriptionOptions(); // 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; myCustomer.Prorate = true; if (organization.Subscription.HasTrialed) { // when the customers trial ends (overrides the plan if applicable) // Calculate what day of the week is 36 days from this instant. //System.DateTime today = DateTime.Now.ToUniversalTime(); //Add 3 hours to let Stripe update / account for timezone //System.TimeSpan duration = new System.TimeSpan(0, 2, 0, 0); //Set time in future //System.DateTime threeMinutesFromNow = today.Add(duration); //myCustomer.TrialEnd = threeMinutesFromNow; myCustomer.TrialEnd = null; } return(myCustomer); }