Exemplo n.º 1
0
        private async Task <(Flow flow, Domain.Account)> GetFlow(string flowId)
        {
            flowId.NotNullOrEmpty();

            Flow flow = null;

            {
                var data = await _distributedCache.GetAsync($"flow-{flowId}");

                if (data == null || data.Length == 0)
                {
                    throw new Exception($"Invalid flow {flowId}");
                }

                flow = JsonSerializer.Deserialize <Flow>(data);
            }

            flow.NotNull();

            var account = await _accountsService.GetOrCreateAccount(AccountIdentification.ByGlobalUserId(User.GetUserId()));

            if (flow.AccountId != account.Id)
            {
                throw new Exception("Flow for wrong account.");
            }

            return(flow, account);
        }
Exemplo n.º 2
0
        public async Task <IViewComponentResult> InvokeAsync(string selectedTab)
        {
            var account = await _accountsService.GetAccount(AccountIdentification.ByGlobalUserId(((ClaimsPrincipal)User).GetUserId()));

            return(View(new SideBarViewModel
            {
                SelectedTab = selectedTab,
                Amount = account?.CurrentBalance ?? 0
            }));
        }
Exemplo n.º 3
0
        public async Task <CreateOrderResponse> CreateOrder([FromBody] CreateOrderRequest request)
        {
            var account = await _accountsService.GetOrCreateAccount(AccountIdentification.ByGlobalUserId(User.GetUserId()));

            var pendingOrder = await _payPalService.CreatePendingOrder(account.Id, request.Amount);

            return(new CreateOrderResponse
            {
                OrderId = pendingOrder.PayPalOrderId
            });
        }
Exemplo n.º 4
0
        public async Task <ActionResult> PayPalOrderCreate([FromBody] CreatePayPalOrderRequest request)
        {
            var(flow, _) = await GetFlow(request.FlowId);

            var account = await _accountsService.GetOrCreateAccount(AccountIdentification.ByGlobalUserId(User.GetUserId()));

            var pendingOrder = await _payPalService.CreatePendingOrder(account.Id, flow.Amount);

            return(Json(new CreatePayPalOrderResponse
            {
                OrderId = pendingOrder.PayPalOrderId
            }));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Index(SpecifyAmountInputModel model)
        {
            model.Amount = model.Amount.TrimMoney();

            if (!ModelState.IsValid)
            {
                return(View(new SpecifyAmountViewModel
                {
                    Amount = model.Amount
                }));
            }

            var flowId = Guid.NewGuid().ToString();
            await _distributedCache.SetAsync($"flow-{flowId}", JsonSerializer.SerializeToUtf8Bytes(new Flow
            {
                Amount    = model.Amount,
                AccountId = (await _accountsService.GetOrCreateAccount(AccountIdentification.ByGlobalUserId(User.GetUserId()))).Id
            }), new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
            });

            return(RedirectToAction("Fund", new { flowId = flowId }));
        }