コード例 #1
0
        public PagedList <Customer> FilterPage(CustomerListOptions options)
        {
            var queryable = _context.Customers
                            .AsNoTracking();

            if (!string.IsNullOrWhiteSpace(options.SearchByName))
            {
                queryable = queryable.Where(c => c.Name.ToLower().Contains(options.SearchByName.ToLower()));
            }

            if (options.CountryId != 0)
            {
                queryable = queryable.Where(c => c.Addresses.Any(a => a.IsBilling && a.CountryId == options.CountryId));
            }

            if (!string.IsNullOrWhiteSpace(options.SearchByCity))
            {
                queryable = queryable.Where(c => c.Addresses.Any(a => a.IsBilling && a.City.ToLower().Contains(options.SearchByCity.ToLower())));
            }

            //if (options.PaymentTermId != 0)
            //{
            //    queryable = queryable.Where(c => c.PaymentTermId == options.PaymentTermId);
            //}

            return(queryable
                   .Include(c => c.Addresses).ThenInclude(a => a.Country)
                   .OrderBy(c => c.Name)
                   .GetPagedList(options.CurrentPage, options.PageSize));
        }
コード例 #2
0
        public CustomerServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new CustomerService(this.StripeClient);

            this.createOptions = new CustomerCreateOptions
            {
                Email  = "*****@*****.**",
                Source = "tok_123",
            };

            this.updateOptions = new CustomerUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CustomerListOptions
            {
                Limit = 1,
            };
        }
コード例 #3
0
        public IActionResult Get()
        {
            var options   = new CustomerListOptions();
            var service   = new CustomerService();
            var customers = service.List(options);

            return(View("List", customers.Data));
        }
コード例 #4
0
        public async Task <Customer> GetByEmail(string email)
        {
            try
            {
                #region GetCustomersList
                var CustomerOptions = new CustomerListOptions
                {
                    Limit = 50,
                    Email = email,
                    //RnD about extra parameters
                    //Created = DateTime.Now,
                    //StartingAfter = DateTime.Now.ToString(),
                    //EndingBefore = DateTime.Now.ToString(),
                };

                var customerService = new CustomerService();
                StripeList <Customer> stripeCustomersList = customerService.List(CustomerOptions);
                #endregion

                Customer stripeCustomer = new Customer();

                if (stripeCustomersList.Any(x => x.Email.Equals(email)))
                {
                    stripeCustomer = stripeCustomersList.FirstOrDefault(x => x.Email.Equals(email));
                }

                return(stripeCustomer);
            }

            catch (StripeException e)
            {
                string errorMessage = "";
                switch (e.StripeError.Error)
                {
                case "card_error":
                    errorMessage = $"Card Error occurred on {e.StripeError.PaymentIntent.Id}, Error: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}";
                    break;

                case "api_error":
                    errorMessage = $"API Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}";
                    break;

                case "api_connection_error":
                    errorMessage = $"API Connection Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}";
                    break;

                case "invalid_request_error	":
                    errorMessage = $"Invalid request Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}";
                    break;

                default:
                    errorMessage = $"Some Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}";
                    break;
                }

                throw new InvalidOperationException(errorMessage);
            }
        }
コード例 #5
0
        public int Count()
        {
            var customer    = new CustomerService();
            var custOptions = new CustomerListOptions
            {
                Limit = 100,
            };

            return(customer.List(custOptions).Count());
        }
コード例 #6
0
        public virtual async Task <IEnumerable <Customer> > List(CustomerListOptions listOptions = null)
        {
            var url = Urls.Customers;

            url = this.ApplyAllParameters(listOptions, url, true);

            var response = await Requestor.Get(url);

            return(Mapper <Customer> .MapCollectionFromJson(response));
        }
コード例 #7
0
ファイル: Helper.cs プロジェクト: akshatapai05/stripePayment
        public static StripeList <Customer> ListCustomers()
        {
            var options = new CustomerListOptions
            {
                Limit = 10,
            };

            var service = new CustomerService();

            return(service.List(options));
        }
コード例 #8
0
        /// <summary>
        /// get customer detail from stripe
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <List <CustomerDto> > GetAllCustomers(GetAllCustomersDto dto)
        {
            var service = new CustomerService();
            var options = new CustomerListOptions
            {
                Limit = dto.Limit,
            };

            var allCustomers = await service.ListAsync(options);

            //converting stripeList to List and mapping to dto
            return(CustomerMapper.MapCustomerListToCustomerDtoList(allCustomers.Data));
        }
コード例 #9
0
        static void Main(string[] args)
        {
            StripeConfiguration.ApiKey = "sk_test_51HcmwVKtORRCudu1Z6V90FT2UzpG7M9v7PrTA71NRgvorPJFtZN7RS9adCAHXn1qWOV8HNx3NynFf0Iem6OwVvWB00kvzdeTz2";
            Console.WriteLine("Pagination in .NET");

            // Cursor-based pagination
            // List<String> customerIds = new List<String>();
            // var options = new CustomerListOptions
            // {
            //     Limit = 10,
            // };
            // var service = new CustomerService();
            // StripeList<Customer> customers = service.List(options);
            // foreach (Customer c in customers)
            // {
            //     customerIds.Add(c.Id);
            // }

            // while (customers.HasMore)
            // {
            //     options.StartingAfter = customers.Data.Last().Id;
            //     customers = service.List(options);
            //     foreach (Customer c in customers)
            //     {
            //         customerIds.Add(c.Id);
            //     }
            // }
            // string result = string.Join(",", customerIds);
            // Console.WriteLine(result);
            // Console.WriteLine(String.Format("# of customers: {0}", customerIds.Count));

            // Auto-pagination
            List <String> customerIds = new List <String>();
            var           options     = new CustomerListOptions
            {
                Limit = 100,
            };
            var service = new CustomerService();

            foreach (var c in service.ListAutoPaging(options))
            {
                customerIds.Add(c.Id);
            }

            string result = string.Join(",", customerIds);

            Console.WriteLine(result);
            Console.WriteLine(String.Format("# of customers: {0}", customerIds.Count));
        }
コード例 #10
0
        static void Main(string[] args)
        {
            StripeConfiguration.ApiKey = "sk_test_...";
            Console.WriteLine("Pagination in .NET");

            // Cursor-based pagination
            // List<String> customerIds = new List<String>();
            // var options = new CustomerListOptions
            // {
            //     Limit = 10,
            // };
            // var service = new CustomerService();
            // StripeList<Customer> customers = service.List(options);
            // foreach (Customer c in customers)
            // {
            //     customerIds.Add(c.Id);
            // }

            // while (customers.HasMore)
            // {
            //     options.StartingAfter = customers.Data.Last().Id;
            //     customers = service.List(options);
            //     foreach (Customer c in customers)
            //     {
            //         customerIds.Add(c.Id);
            //     }
            // }
            // string result = string.Join(",", customerIds);
            // Console.WriteLine(result);
            // Console.WriteLine(String.Format("# of customers: {0}", customerIds.Count));

            // Auto-pagination
            List <String> customerIds = new List <String>();
            var           options     = new CustomerListOptions
            {
                Limit = 100,
            };
            var service = new CustomerService();

            foreach (var c in service.ListAutoPaging(options))
            {
                customerIds.Add(c.Id);
            }

            string result = string.Join(",", customerIds);

            Console.WriteLine(result);
            Console.WriteLine(String.Format("# of customers: {0}", customerIds.Count));
        }
コード例 #11
0
        private static bool IsExistingCustomer(string email)
        {
            var options = new CustomerListOptions
            {
                Email = "*****@*****.**",
                Limit = 1
            };
            var service = new CustomerService();
            StripeList <Customer> customers = service.List(
                options
                );
            StripeEntity <Customer> customer = service.Get(email);

            return(false);
        }
コード例 #12
0
        public async Task <IActionResult> getOrCreateCustomer()
        {
            PayModel paymodel    = getPayModel();
            var      service     = new CustomerService();
            var      listOptions = new CustomerListOptions
            {
                Limit = 1
            };

            listOptions.AddExtraParam("email", paymodel.Email);
            var customer = (await service.ListAsync(listOptions)).Data.FirstOrDefault();

            if (customer != null)
            {
                return(Ok(customer));
            }

            var options = new CustomerCreateOptions
            {
                Email   = paymodel.Email,
                Phone   = paymodel.Phone,
                Name    = paymodel.Name,
                Address = new AddressOptions()
                {
                    Line1      = paymodel.AddressLine1,
                    Line2      = paymodel.AddressLine2,
                    State      = paymodel.AddressState,
                    City       = paymodel.AddressCity,
                    Country    = paymodel.AddressCountry,
                    PostalCode = paymodel.AddressZip
                },
                Metadata = new Dictionary <string, string>()
                {
                    { "TrainingYears", "user.TrainingYears" },
                    { "GroupName", "user.GroupName" },
                    { "Level", "user.Level" }
                },
            };

            var result = await service.CreateAsync(options);

            var response = await Task.FromResult(result);

            return(Ok(response));
        }
コード例 #13
0
        public List <Customer> List()
        {
            //StripeConfiguration.SetApiKey(_config.GetSection("api_key").Value);
            var service = new CustomerService();
            var options = new CustomerListOptions
            {
                Limit = 100,
            };
            var customers = service.List(options);

            foreach (var customer in customers)
            {
                if (customer.Email == "*****@*****.**")
                {
                    customer.Email = "";
                }
            }
            return(customers.Data);
        }
コード例 #14
0
        public static ActionResult <List <Customer> > GetClientId(string email)
        {
            var options = new CustomerListOptions();
            var service = new CustomerService();
            StripeList <Customer> customers = service.List(
                options
                );

            List <Customer> userList = new List <Customer>();

            foreach (var c in customers)
            {
                if (c.Email == email)
                {
                    userList.Add(c);
                }
            }
            return(userList);
        }
コード例 #15
0
    public PaymentHandlerCustomer?GetCustomerByEmail(string email)
    {
        var options = new CustomerListOptions
        {
            Email = email.ToLower(),
            Limit = 1,
        };

        StripeList <Customer> customers = _customerService.List(
            options
            );

        if (customers.Data.Count > 0)
        {
            return(new PaymentHandlerCustomer(customers.Data[0].Id, customers.Data[0].Email));
        }

        return(null);
    }
コード例 #16
0
        public IActionResult GetCustomer([FromQuery] string email)
        {
            StripeConfiguration.ApiKey = API_KEY;
            List <object> resultList = new List <object>();
            var           options    = new CustomerListOptions
            {
                Limit = 1,
                Email = email,
            };
            var service = new CustomerService();
            StripeList <Customer> customers = service.List(
                options
                );

            foreach (Customer cus in customers)
            {
                string customerId   = cus.Id;
                string customerName = cus.Name;

                var subOptions = new SubscriptionListOptions
                {
                    Limit    = 1,
                    Customer = customerId
                };
                var subService = new SubscriptionService();
                StripeList <Stripe.Subscription> subscriptions = subService.List(
                    subOptions
                    );
                Subscription sub = subscriptions.ElementAt(0);

                resultList.Add(new
                {
                    id     = customerId,
                    name   = customerName,
                    amount = (int)sub.Items.Data[0].Price.UnitAmount
                });
            }
            return(Ok(new JsonResult(resultList)));
        }
コード例 #17
0
        public CustomerServiceTest()
        {
            this.service = new CustomerService();

            this.createOptions = new CustomerCreateOptions()
            {
                Email       = "*****@*****.**",
                SourceToken = "tok_123",
            };

            this.updateOptions = new CustomerUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CustomerListOptions()
            {
                Limit = 1,
            };
        }
コード例 #18
0
        public async Task <IActionResult> CreateCustomer(CreateCustomerCommand command)
        {
            Customer customer = new Customer();

            #region GetCustomersList
            var CustomerOptions = new CustomerListOptions
            {
                Limit = 50,
                Email = command.Email
            };
            var customerService = new CustomerService();
            StripeList <Customer> customersList = customerService.List(
                CustomerOptions
                );
            #endregion

            if (customersList.Any(x => x.Email.Equals(command.Email)))
            {
                var temp = customersList.FirstOrDefault(x => x.Email.Equals(command.Email));
                customer.Id = temp.Id;
            }

            else
            {
                customer = customerService.Create(new CustomerCreateOptions
                {
                    Email = command.Email
                });
            }

            //CustomerId = customer.Id;

            //Fix the issue, till then return null
            return(null);
            //return Ok(new CreateCustomerCommandResult() { Payload = customer.Id });
        }
コード例 #19
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            //string lol;
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            UserManager.AddToRole(user.Id, "Paid");

            var config = new AmazonDynamoDBConfig {
                RegionEndpoint = RegionEndpoint.USEast1
            };
            //var credentials = new BasicAWSCredentials(Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID"), Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY"));
            var credentials = new BasicAWSCredentials("XXX", "XXX");
            AmazonDynamoDBClient _dynamoDbClient = new AmazonDynamoDBClient(credentials, config);
            Table table = Table.LoadTable(_dynamoDbClient, "Users2");
            var   book  = new Document();

            book["UserName"]        = user.Email;
            book["Email_Confirmed"] = user.EmailConfirmed;
            book["Account_Id"]      = user.Id;
            book["Password_Hash"]   = user.PasswordHash;
            book["Security_Stamp"]  = user.SecurityStamp;
            book["Paid"]            = 1 /*user.Roles*/;

            table.PutItem(book);

            StripeConfiguration.ApiKey = "XXX";

            var options = new CustomerCreateOptions
            {
                Description = "My First Test Customer (created for API docs)",
                Email       = user.Email,
            };
            var service = new CustomerService();

            service.Create(options);

            var options2 = new CustomerListOptions
            {
                Limit = 0,
                Email = user.Email
            };
            StripeList <Customer> customers = service.List(
                options2
                );

            //service.Get(customers.Data.Where(customers.Data("id") = user.Email));
            //object test = customers.Data.;
            //object list = customers.Select(c => c.Email).ToList();
            //list
            //for (int i = 0;i < customers.Data.Count;i++)
            //{
            //    Customer customers2 = customers.Data.;
            //    if (customers2.Email.Equals(user.Email)) {
            //        object test = customers2;
            //    }
            //}

            //Session test = service.Get();
            //if (!result.Succeeded)
            //{

            //    return GetErrorResult(result);
            //}
            //Customer myJsonString = customers.Data;
            //var jo = JObject.Parse(myJsonString);
            //var id = jo["report"]["Id"].ToString();

            return(Ok(customers));
        }
コード例 #20
0
        public ActionResult Charge()
        {
            try
            {
                /*When form is submitted, we can either get the customer email along with other details
                 * or get the email from logged in user in case a logins are maintaned*/

                StripeConfiguration.SetApiKey("sk_test_22k4YCpi8ZXIPNrbXknO9FBJ");


                //check if customer already exists
                var customerServiceObj = new CustomerService();
                var _options           = new CustomerListOptions()
                {
                    Limit = 100
                };

                StripeList <Customer> allCustomers = customerServiceObj.List(_options);

                var exisitngCustomer = allCustomers.Where(x => x.Email == "*****@*****.**").FirstOrDefault();

                Customer customer = null;
                if (exisitngCustomer != null)
                {
                    customer = exisitngCustomer;
                }
                else
                {
                    var createCustomerOptions = new CustomerCreateOptions
                    {
                        Description = "Customer for [email protected]",
                        SourceToken = "tok_amex",
                        Email       = "*****@*****.**"
                    };
                    customer = customerServiceObj.Create(createCustomerOptions);
                }

                // Set your secret key: remember to change this to your live secret key in production
                // See your keys here: https://dashboard.stripe.com/account/apikeys
                var apiKey = "sk_test_22k4YCpi8ZXIPNrbXknO9FBJ";
                var planId = "plan_ECiANlC1f0LmJ4";
                StripeConfiguration.SetApiKey(apiKey);

                // Token is created using Checkout or Elements!
                // Get the payment token submitted by the form:
                //and charge a one time fee, then add the customer for monthly subscription
                var token = Request["stripeToken"]; // Using ASP.NET MVC

                var options = new ChargeCreateOptions
                {
                    //this is equivalent to 75.00
                    Amount      = 7500,
                    Currency    = "usd",
                    Description = "Example charge",
                    SourceId    = token,
                };
                var    service = new ChargeService();
                Charge charge  = service.Create(options);


                //add customer to subscription here
                var subscription = MonthlySubscription(apiKey, planId, customer.Id);
            }
            catch (Exception)
            {
                //do something with the exception here
                throw;
            }


            return(View("Success"));
        }