コード例 #1
0
        public async Task Execute(RefundInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            IDebit debit = account.Withdraw(_entityFactory, input.Amount);

            if (debit == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not have enough funds to withdraw {input.Amount}.");
                return;
            }

            await _accountRepository.Update(account, debit);

            // Publish the event to the enterprice service bus
            await _serviceBus.PublishEventAsync(new Shared.Events.WithdrawCompleted()
            {
                AccountId = input.AccountId, Amount = input.Amount.ToMoney().ToDecimal()
            });

            await _unitOfWork.Save();

            RefundOutput output = new RefundOutput(
                debit,
                account.GetCurrentBalance()
                );

            _outputHandler.Default(output);
        }
コード例 #2
0
        private bool LoadFile()
        {
            Common.AppendStatus("Loading file", true);

            if (!File.Exists(this.Filename))
            {
                Common.AppendStatus("File not found: " + this.Filename, true);
                return(false);
            }

            var info = new FileInfo(this.Filename);

            if (info.Extension == RefundProcessor.FileTypeCSV)
            {
                using (var helper = new CsvHelper.CsvReader(new StreamReader(this.Filename), CultureInfo.InvariantCulture))
                {
                    this.Refunds = helper.GetRecords <RefundInput>()
                                   .ToList();
                }
            }
            else
            {
                var book  = new XSSFWorkbook(this.Filename);
                var sheet = book.GetSheetAt(0);

                this.Refunds = new List <RefundInput>();

                for (var lp = 1; lp < sheet.PhysicalNumberOfRows; lp++)
                {
                    var row  = sheet.GetRow(lp);
                    var amt  = row.GetCell(1).NumericCellValue;
                    var cust = row.GetCell(0).StringCellValue;

                    if (Util.IsEmpty(cust) || Util.IsEmpty(amt))
                    {
                        continue;
                    }

                    var refRec = new RefundInput()
                    {
                        Amount     = (decimal)amt,
                        CustomerID = cust
                    };

                    this.Refunds.Add(refRec);
                }
            }

            if (this.Refunds.Any())
            {
                Common.AppendStatus("Customers loaded: " + this.Refunds.Count, true);
                return(true);
            }

            Common.AppendStatus("No Customers loaded", false);
            return(false);
        }
コード例 #3
0
        public async Task <IActionResult> Refund([FromBody][Required] RefundRequest request)
        {
            var refundInput = new RefundInput(
                request.AccountId,
                new PositiveMoney(request.Amount)
                );
            await _refundUseCase.Execute(refundInput);

            return(_presenter.ViewModel);
        }
コード例 #4
0
 /// <summary>
 /// 订单退款
 /// </summary>
 /// <param name="input">退款数据</param>
 /// <returns></returns>
 public async Task <AlipayTradeRefundResponse> Refund(RefundInput input)
 {
     return(await this.Refund(input.Data));
 }