Update() public method

public Update ( string customerId, StripeCustomerUpdateOptions updateOptions, Stripe.StripeRequestOptions requestOptions = null ) : Stripe.StripeCustomer
customerId string
updateOptions StripeCustomerUpdateOptions
requestOptions Stripe.StripeRequestOptions
return Stripe.StripeCustomer
        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;
        }
Example #2
0
        public UpdateCustomerResponse UpdateCustomer(UpdateCustomerRequest req)
        {
            var response = new UpdateCustomerResponse();

            try
            {
                if (req.PlanId.Length > 0)
                {
                    return UpdateSubscription(req);
                }
                else
                {
                    // Update Customer
                    var myCustomer = new StripeCustomerUpdateOptions();
                    
                    if (req.CreditCard.CardNumber.Trim().Length > 0)
                    {
                        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;
                        }
                    }
                                                       
                    var customerService = new StripeCustomerService();
                    StripeCustomer stripeCustomer = customerService.Update(req.CustomerId, myCustomer);

                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
Example #3
0
        /// <summary>
        /// Updates a customer record, using the given payment token
        /// NOTE: Save changes on the underlying context for the model after calling this method
        /// </summary>
        /// <param name="user"></param>
        /// <param name="paymentToken"></param>
        public static void UpdateCustomer(IStripeUser user, string paymentToken = null)
        {
            var customerUpdate = new StripeCustomerUpdateOptions() { Email = user.Email };

            // Create a token for this payment token
            customerUpdate.Card = new StripeCreditCardOptions() { TokenId = paymentToken };

            var customerService = new StripeCustomerService();
            StripeCustomer stripeCustomer = customerService.Update(user.PaymentSystemId, customerUpdate);

            System.Diagnostics.Trace.TraceInformation("Updated customer in stripe: '{0}' with id '{1}", user.Email, user.PaymentSystemId);
        }
        public ActionResult ChangeDefault(string id)
        {
            User userObj = (User)Session["user"];
            var stripeCustomerID = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID).StripeCustomerID;

            var customer = new StripeCustomerService();
            customer.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp";

            var customerUpdate = new StripeCustomerUpdateOptions();
            customerUpdate.DefaultCard = id;
            customer.Update(stripeCustomerID, customerUpdate);

            return RedirectToAction("Subscription", "Admin", new { id = 1 });
        }