Exemplo n.º 1
0
        public async Task <IActionResult> KontingentSuccessAsync(string session)
        {
            var kontingentProduct = await _stripeService.GetProductByNameAsync("kontingent");

            var stripeSession = await _stripeService.GetSessionAsync(session);

            var hasPayed       = _stripeService.IsPaymentComplete(stripeSession);
            var correctProduct = stripeSession?.Metadata?["Product"] == kontingentProduct.Id;
            var user           = await _userManager.FindByIdAsync(stripeSession?.ClientReferenceId);

            var sessionCreated = stripeSession != null?DateTime.Parse(stripeSession.Metadata["SessionCreated"]) : DateTime.MinValue;

            if (DateTime.UtcNow < sessionCreated.AddHours(1) && hasPayed && correctProduct)
            {
                user?.MarkAsPayed();
                await _userManager.UpdateAsync(user);

                return(View(user));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }