Ejemplo n.º 1
0
        public async Task <ActionResult> AddTransaction(WalletViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonErrorResult(ModelState));
            }

            var dto = BuildUserTransactionDto(model.AddTransactionViewModel);
            await _transactionsService.AddTransaction(dto);

            return(new JsonNetResult(new { dto.Id }));
        }
Ejemplo n.º 2
0
        public void Should_throw_if_user_does_not_exist()
        {
            var dto = new UserTransactionDto {
                UserId = 4
            };
            Func <System.Threading.Tasks.Task> act = async() => await _service.AddTransaction(dto);

            act.ShouldThrow <BusinessException>().Where(e => e.Status == ErrorStatus.DataNotFound);
        }
Ejemplo n.º 3
0
        public async Task CapturePendingOrder(string orderId, string payerId)
        {
            Order order;

            {
                var client  = _payPalClientProvider.BuildHttpClient();
                var request = new OrdersCaptureRequest(orderId);
                request.RequestBody(new OrderActionRequest());
                var response = await client.Execute(request);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    _logger.LogError("Invalid status code from PayPal order capture: status: {Status} response: {Response}", response.StatusCode, SerializePayPalType(response.Result <object>()));
                    throw new Exception("Invalid PayPal response");
                }

                order = response.Result <Order>();

                if (order.Status != "COMPLETED")
                {
                    _logger.LogError("The order from PayPal wasn't marked as COMPELTED: {Response}", SerializePayPalType(response.Result <object>()));
                    throw new Exception("The order from PayPal wasn't marked as COMPELTED");
                }
            }

            using (var con = new ConScope(_dataService))
                using (var trans = await con.BeginTransaction())
                {
                    var pendingOrder = con.Connection.Single <PayPalOrder>(x => x.PayPalOrderId == orderId);

                    if (pendingOrder.OrderStatus == PayPalOrderStatus.Completed)
                    {
                        throw new Exception($"Attempted to update order {orderId} as completed, but it is already marked as completed.");
                    }

                    pendingOrder.OrderStatus     = PayPalOrderStatus.Completed;
                    pendingOrder.PayPalPayerId   = payerId;
                    pendingOrder.PayPalOrderJson = SerializePayPalType(order);

                    await con.Connection.SaveAsync(pendingOrder);

                    await _transactionsService.AddTransaction(pendingOrder.AccountId, pendingOrder.Amount, "PayPal reload", pendingOrder.PayPalOrderJson, pendingOrder.Id);

                    trans.Commit();
                }
        }