Exemple #1
0
        public async Task <Price> GetPrice()
        {
            var priceService = new PriceService(_client);
            var price        = await priceService.GetAsync("price_1I9BDlLEKfRfXn5LnzigkJpT");

            return(price);
        }
Exemple #2
0
        public async Task <IActionResult> Create()
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var userNames = user.FirstName + ' ' + user.LastName;

            var customerService = new CustomerService();
            var customers       = await customerService.ListAsync();

            var customer = customers.FirstOrDefault(x => x.Name == userNames);

            if (customer == null)
            {
                var customerOptions = new CustomerCreateOptions
                {
                    Name     = userNames,
                    Email    = user.Email,
                    Phone    = user.PhoneNumber,
                    Metadata = new Dictionary <string, string>
                    {
                        ["HotelId"]   = user.HotelId.ToString(),
                        ["UserId"]    = user.Id,
                        ["BirthDate"] = user.BirthDate.ToShortDateString(),
                        ["Username"]  = user.UserName,
                    },
                };

                customer = await customerService.CreateAsync(customerOptions);
            }

            var priceService = new PriceService();
            var price        = await priceService.GetAsync("price_1IP1xzLxakYJAQmTh3ple3eB");

            var service = new PaymentIntentService();
            var options = new PaymentIntentCreateOptions
            {
                Amount           = price.UnitAmount,
                Currency         = "bgn",
                SetupFutureUsage = "on_session",
                Customer         = customer.Id,
            };
            var paymentIntent = await service.CreateAsync(options);

            var model = new PaymentInputModel
            {
                Token                = paymentIntent.ClientSecret,
                PaymentId            = paymentIntent.Id,
                StripePublishableKey = this.configuration["Stripe:PublishableKey"],
            };

            return(this.View(model));
        }
        public async Task <ConfigResponse> GetConfig()
        {
            // Fetch price from the API
            var service = new PriceService(this.client);
            var price   = await service.GetAsync(this.options.Value.Price);

            // return json: publicKey (env), unitAmount, currency
            return(new ConfigResponse
            {
                PublicKey = this.options.Value.PublishableKey,
                UnitAmount = price.UnitAmount,
                Currency = price.Currency,
            });
        }