Beispiel #1
0
        public virtual StripeCard Update(string customerOrRecipientId, string cardId, StripeCardUpdateOptions updateOptions, bool isRecipient = false, StripeRequestOptions requestOptions = null)
        {
            var url = SetupUrl(customerOrRecipientId, isRecipient, cardId);

            return Mapper<StripeCard>.MapFromJson(
                Requestor.PostString(this.ApplyAllParameters(updateOptions, url, false),
                SetupRequestOptions(requestOptions))
            );
        }
        public virtual StripeCard Update(string customerOrRecipientId, string cardId, StripeCardUpdateOptions updateOptions, bool isRecipient = false)
        {
            var url = SetupUrl(customerOrRecipientId, isRecipient, cardId);
            url = this.ApplyAllParameters(updateOptions, url, false);

            var response = Requestor.PostString(url, ApiKey);

            return Mapper<StripeCard>.MapFromJson(response);
        }
		public virtual StripeCard Update(string customerId, string cardId, StripeCardUpdateOptions updateOptions)
		{
			var customerUrl = string.Format(Urls.Cards, customerId);
			var url = string.Format("{0}/{1}", customerUrl, cardId);
			url = ParameterBuilder.ApplyAllParameters(updateOptions, url);

			var response = Requestor.PostString(url, ApiKey);

			return Mapper<StripeCard>.MapFromJson(response);
		}
Beispiel #4
0
        public virtual StripeCard Update(string customerId, string cardId, StripeCardUpdateOptions updateOptions)
        {
            var customerUrl = string.Format(Urls.Cards, customerId);
            var url         = string.Format("{0}/{1}", customerUrl, cardId);

            url = this.ApplyAllParameters(updateOptions, url, false);

            var response = Requestor.PostString(url, ApiKey);

            return(Mapper <StripeCard> .MapFromJson(response));
        }
Beispiel #5
0
        public virtual StripeCard Update(string customerOrRecipientId, string cardId, StripeCardUpdateOptions updateOptions, bool isRecipient = false, StripeRequestOptions requestOptions = null)
        {
            var url = SetupUrl(customerOrRecipientId, isRecipient, cardId);

            return(Mapper <StripeCard> .MapFromJson(
                       Requestor.PostString(this.ApplyAllParameters(updateOptions, url, false),
                                            SetupRequestOptions(requestOptions))
                       ));
        }
Beispiel #6
0
        public virtual async Task <StripeCard> UpdateAsync(string customerOrRecipientId, string cardId, StripeCardUpdateOptions updateOptions, bool isRecipient = false, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = SetupUrl(customerOrRecipientId, isRecipient, cardId);

            return(Mapper <StripeCard> .MapFromJson(
                       await Requestor.PostStringAsync(this.ApplyAllParameters(updateOptions, url, false),
                                                       SetupRequestOptions(requestOptions),
                                                       cancellationToken)
                       ));
        }
        private async Task CreateCustomer(StripeModel model)
        {
            await Task.Run(() =>
            {
                // create customer based on validated token from stripe.js 
                var myCustomer = new StripeCustomerCreateOptions();

                // assign token to a credit card option for a user
                myCustomer.Card = new StripeCreditCardOptions()
                {
                    TokenId = model.Token
                };

                myCustomer.Email = User.Identity.Name;
                myCustomer.Description = User.Identity.Name;
                myCustomer.PlanId = model.SubscriptionType.ToString();
                myCustomer.Quantity = 1;
                
                // create customer in stripe service
                var customerService = new StripeCustomerService();
                StripeCustomer stripeCustomer = customerService.Create(myCustomer);

                // get subscription Id from created user
                var subscriptionID = stripeCustomer.StripeSubscriptionList.StripeSubscriptions.FirstOrDefault().Id;              
                       
             // save credit card optional details 
                StripeCustomerService customerServic = new StripeCustomerService();
                stripeCustomer = customerService.Get(stripeCustomer.Id);
                var cardId = stripeCustomer.StripeDefaultCardId; // get card id
                var myCard = new StripeCardUpdateOptions();

                myCard.Name = model.CardHolderName;
                myCard.AddressLine1 = model.AddressLine1;
                myCard.AddressLine2 = model.AddressLine2;
                myCard.AddressCity = model.AddressCity;
                myCard.AddressZip = model.AddressPostcode;
                myCard.AddressCountry = model.AddressCountry;

                var cardService = new StripeCardService();
                StripeCard stripeCard = cardService.Update(stripeCustomer.Id, cardId, myCard);
            //........................
                
                // record customer in database
                var cust = getCustomer();
                if(cust == null) // new users
                {
                    // get values to create a new record in StripeCustomer table
                    StripeCustomers customer = new StripeCustomers();
                
                    customer.CustomerName = User.Identity.Name;
                    customer.StripeCustomerID = stripeCustomer.Id;
                    customer.StripeSubscriptionID = subscriptionID;
                    customer.SubscriptionType = model.SubscriptionType.ToString();
                    customer.HasSubscription = true;
                    customer.Interval = "Monthly";
                    customer.StartDate = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");
                    if (model.SubscriptionType.ToString() == "standard")
                    {
                        customer.TrialValidUntil = currentTime.AddDays(30);
                    }
                    db.StripeCustomers.Add(customer);
                    }
                    else // user with db records
                    {
                        StripeCustomers newRecord = new StripeCustomers();

                        // take the data from current user
                        newRecord.StripeCustomerID = stripeCustomer.Id;
                        newRecord.CustomerName = User.Identity.Name;
                        newRecord.StripeSubscriptionID = subscriptionID;
                        newRecord.SubscriptionType = model.SubscriptionType.ToString();
                        newRecord.HasSubscription = true;
                        newRecord.Interval = "Monthly";
                        newRecord.StartDate = currentTime;
                        if (model.SubscriptionType.ToString() == "standard")
                        {
                            newRecord.TrialValidUntil = currentTime.AddDays(30);
                        }
                        db.StripeCustomers.Add(newRecord);

                        // delete customer's old record in database
                        db.StripeCustomers.Remove(cust);
                    }
                db.SaveChanges();
            });
        }
Beispiel #8
0
        public virtual StripeCard Update(string customerOrRecipientId, string cardId, StripeCardUpdateOptions updateOptions, bool isRecipient = false)
        {
            var url = SetupUrl(customerOrRecipientId, isRecipient, cardId);

            url = this.ApplyAllParameters(updateOptions, url, false);

            var response = Requestor.PostString(url, ApiKey);

            return(Mapper <StripeCard> .MapFromJson(response));
        }