コード例 #1
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));
        }
コード例 #2
0
        private async Task <Customer> getOrCreateCustomer(string email)
        {
            var service     = new Stripe.CustomerService();
            var listOptions = new Stripe.CustomerListOptions
            {
                Limit = 1
            };

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

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

            var customerCreateOptions = new Stripe.CustomerCreateOptions
            {
                Email = email
            };

            return(await service.CreateAsync(customerCreateOptions));
        }