public async Task <SuccessModel> CheckOut(StripePaymentDTO model)
        {
            try
            {
                var content     = JsonConvert.SerializeObject(model);
                var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
                var response    = await _client.PostAsync("api/StripePayment/Create", bodyContent);

                if (response.IsSuccessStatusCode)
                {
                    var contentTemp = await response.Content.ReadAsStringAsync();

                    // Enitity to DTO convert is alrdy done in repository
                    var result = JsonConvert.DeserializeObject <SuccessModel>(contentTemp);
                    return(result);
                }
                else
                {
                    var contentTemp = await response.Content.ReadAsStringAsync();

                    // Enitity to DTO convert is alrdy done in repository
                    var errorModel = JsonConvert.DeserializeObject <ErrorModel>(contentTemp);
                    throw new Exception(errorModel.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public async Task <IActionResult> Create(StripePaymentDTO payment)
        {
            try
            {
                var domain = _config.GetValue <string>("HiddenVilla_Client_URL");

                var options = new SessionCreateOptions
                {
                    PaymentMethodTypes = new List <string>
                    {
                        "card"
                    },
                    LineItems = new List <SessionLineItemOptions>
                    {
                        new SessionLineItemOptions
                        {
                            PriceData = new SessionLineItemPriceDataOptions
                            {
                                UnitAmount  = payment.Amount, // convert to cent
                                Currency    = "usd",
                                ProductData = new SessionLineItemPriceDataProductDataOptions
                                {
                                    Name = payment.ProductName
                                }
                            },
                            Quantity = 1
                        }
                    },
                    Mode       = "payment",
                    SuccessUrl = domain + "/success-payment?session_id={{CHECKOUT_SESSION_ID}}",
                    CancelUrl  = domain + payment.ReturnUrl
                };

                var     service = new SessionService();
                Session session = await service.CreateAsync(options);

                return(Ok(new SuccessModel()
                {
                    Data = session.Id
                }));
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorModel()
                {
                    ErrorMessage = e.Message
                }));
            }


            return(View());
        }
        public async Task <IActionResult> Create(StripePaymentDTO payment)
        {
            try
            {
                var domain = _configuration.GetValue <string>("HiddenVilla_Client_URL");
                if (HotelAssignment2_API.Startup._Env.ToLower() == "Development".ToLower())
                {
                    domain = _configuration.GetValue <string>("HiddenVilla_Client_URL_Local");
                }
                var option = new SessionCreateOptions
                {
                    PaymentMethodTypes = new List <string>
                    {
                        "card"
                    }
                    , LineItems = new List <SessionLineItemOptions>
                    {
                        new SessionLineItemOptions
                        {
                            PriceData = new SessionLineItemPriceDataOptions
                            {
                                UnitAmount    = payment.Amount
                                , Currency    = "USD"
                                , ProductData = new SessionLineItemPriceDataProductDataOptions
                                {
                                    Name = payment.ProductName
                                }
                            }
                            , Quantity = 1
                        }
                    }
                    , Mode       = "payment"
                    , SuccessUrl = domain + "/success-payment?session_id={{CHECKOUT_SESSION_ID}}" //stripe return session id. automacally populates {{}} field
                    , CancelUrl  = domain + payment.ReturnUrl
                };

                var     service = new SessionService();
                Session session = await service.CreateAsync(option);

                return(Ok(new SuccessModel()
                {
                    Data = session.Id
                }));
            }catch (Exception e)
            {
                return(BadRequest(new ErrorModel()
                {
                    ErrorMessage = e.Message
                }));
            }
        }
        public async Task <SuccessModel> CheckOut(StripePaymentDTO model)
        {
            var content     = JsonConvert.SerializeObject(model);
            var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
            var response    = await _client.PostAsync("/api/stripepayment/create", bodyContent);

            if (response.IsSuccessStatusCode)
            {
                var contentTemp = await response.Content.ReadAsStringAsync();

                var result = JsonConvert.DeserializeObject <SuccessModel>(contentTemp);

                return(result);
            }
            else
            {
                var contentTemp = await response.Content.ReadAsStringAsync();

                var error = JsonConvert.DeserializeObject <Error>(contentTemp);

                throw new Exception(error.ErrorMessage);
            }
        }