Пример #1
0
        public async Task <IActionResult> ProductAsync(string id)
        {
            var product = await _stripeService.GetProductAsync(id);

            var price = await _stripeService.GetPriceAsync(id);

            if (product != null && price != null)
            {
                var apiKey = _configuration["StripeConfig:PublicApiKey"];
                return(View(new ProductInfo(product, price, apiKey)));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Пример #2
0
        public async Task <ActionResult> ProductAsync(string product, string user)
        {
            var prod = await _stripeService.GetProductAsync(product);

            var price = await _stripeService.GetPriceAsync(product);

            var sessionparameter = "?session={CHECKOUT_SESSION_ID}";
            var successPage      = prod.Metadata.Keys.Contains("Success") ? prod.Metadata["Success"] : "Success";
            var successUrl       = $"{Url.Action(successPage, "Pay", new { }, Request.Scheme)}{sessionparameter}";
            var cancelUrl        = Url.Action("Cancel", "Pay", new { }, Request.Scheme);

            var stripeSessionId = _stripeService.StartPayment(
                prod,
                price,
                user,
                successUrl,
                cancelUrl
                );

            var result = new JsonResult(new { id = stripeSessionId });

            return(result);
        }