Пример #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
        /// <summary>
        ///     退款申请接口
        /// </summary>
        /// <param name="model">The model<see cref="RefundRequest" /></param>
        /// <returns></returns>
        public RefundOutput Refund(RefundRequest model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (model.TotalFee < 0)
            {
                throw new WeChatPayException("订单额不能小于0!");
            }
            if (model.RefundFee < 0)
            {
                throw new WeChatPayException("退款金额不能小于0!");
            }
            if (string.IsNullOrEmpty(model.OutTradeNo) && string.IsNullOrEmpty(model.TransactionId))
            {
                throw new WeChatPayException("商户订单号与微信订单号必须传入其中一个!");
            }
            if (model.TotalFee < model.RefundFee)
            {
                throw new WeChatPayException("退款金额不能大于订单金额!");
            }
            var url = "https://api.mch.weixin.qq.com/secapi/pay/refund";

            RefundOutput result = null;

            try
            {
                var config = GetConfig();
                ;
                model.AppId    = config.PayAppId;
                model.MchId    = config.MchId;
                model.NonceStr = _weChatPayHelper.GetNoncestr();
                model.OpUserId = config.MchId;

                //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中)
                var cert = config.PayCertPath;

                //商户证书调用或安装都需要使用到密码,该密码的值为微信商户号(mch_id)
                var password = config.MchId;

                //调用证书
                var cer = new X509Certificate2(cert, password,
                                               X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);

                var dictionary = _weChatPayHelper.GetDictionaryByType(model);

                model.Sign = _weChatPayHelper.CreateMd5Sign(dictionary, config.TenPayKey); //生成Sign
                result     = _weChatPayHelper.PostXML <RefundOutput>(url, model, cer);
            }
            catch (Exception ex)
            {
                WeChatPayHelper.LoggerAction?.Invoke(nameof(WeChatPayApi), ex.ToString());
            }

            return(result);
        }
Пример #3
0
        public void Default(RefundOutput withdrawOutput)
        {
            var withdrawResponse = new RefundResponse(
                withdrawOutput.Transaction.Amount,
                withdrawOutput.Transaction.Description,
                withdrawOutput.Transaction.TransactionDate,
                withdrawOutput.UpdatedBalance
                );

            ViewModel = new ObjectResult(withdrawResponse);
        }
Пример #4
0
 public void Default(RefundOutput output)
 {
     Refunds.Add(output);
 }